Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何制作滚动背景。目标-C_Ios_Objective C_Background - Fatal编程技术网

Ios 如何制作滚动背景。目标-C

Ios 如何制作滚动背景。目标-C,ios,objective-c,background,Ios,Objective C,Background,我试图建立一个游戏,在其中的球员移动到右边。我还希望背景与玩家的运动方向相反。如何做到这一点??我需要它看起来像flappy鸟的背景。我没有使用spriteKit或swift。一个错误不断显示为“整数常量上的后缀xscreenwidth无效” 我希望它看起来像这个背景,但我能找到的唯一东西是在spriteKit 我需要它在UIKit中我现在有这个: 上面说 UIView没有可见的@interface声明selector initWithImage,UIView没有可见的@interface声明s

我试图建立一个游戏,在其中的球员移动到右边。我还希望背景与玩家的运动方向相反。如何做到这一点??我需要它看起来像flappy鸟的背景。我没有使用spriteKit或swift。一个错误不断显示为“整数常量上的后缀xscreenwidth无效”

我希望它看起来像这个背景,但我能找到的唯一东西是在spriteKit

我需要它在UIKit中我现在有这个:

上面说 UIView没有可见的@interface声明selector initWithImage,UIView没有可见的@interface声明selector addSubView,UIView没有可见的@interface声明selector BegineAnimation

#import "Game.h"    
#import <AVFoundation/AVFoundation.h>

@interface Game ()

{

    AVAudioPlayer *_soundEffect;

}

@property (nonatomic) int screenHeight;    
@property (nonatomic) int screenWidth;

@end

@implementation Game

-(int)screenHeight{
    return self.view.frame.size.height;
}

-(int)screenWidth{
    return self.view.frame.size.width;
}


//Preparation
-(void)prepareToAnimate{

    CGRect startingPosition = CGRectMake(0,0,2xscreenWidth,screenHeight);
    //You will need to define a variable for your screenWidth and screenHeight

    UIImage *image = [UIImage imageNamed:@"bgtest2.png"];
    //Add your image name here. It should be a double image (i.e. the whole image that fits on an iphone screen next to a duplicate of itself so that it is twice the width)

    UIImageView *imageView = [[UIView alloc] initWithImage:image];

    [self addSubView:imageView];
    [self beginTheAnimation];

}
#导入“Game.h”
#进口
@界面游戏()
{
AVAudioPlayer*\u音效;
}
@属性(非原子)int屏幕高度;
@属性(非原子)int屏幕宽度;
@结束
@实施游戏
-(int)屏幕高度{
返回self.view.frame.size.height;
}
-(int)屏幕宽度{
返回self.view.frame.size.width;
}
//准备工作
-(作废)准备制作动画{
CGRect startingPosition=CGRectMake(0,0,2xscreenWidth,screenHeight);
//您需要为屏幕宽度和屏幕高度定义一个变量
UIImage*image=[UIImage ImageName:@“bgtest2.png”];
//在此处添加您的图像名称。它应该是一个双图像(即,整个图像放在iphone屏幕上,旁边是其自身的副本,因此它是宽度的两倍)
UIImageView*imageView=[[UIView alloc]initWithImage:image];
[自添加子视图:图像视图];
[自生动画];
}

乘法运算符是
*
,而不是
x
。显示错误是因为此行中有
2xscreenWidth

CGRect startingPosition = CGRectMake(0,0,2xscreenWidth,screenHeight);
将其更改为:

CGRect startingPosition = CGRectMake(0,0,2*screenWidth,screenHeight);

有没有其他方法可以做到这一点,我试着将x改为*但现在出现了更多的错误。我能找到的只有spriteKit。我觉得你的理论不错,只是看起来你有错误需要解决。您需要先修复代码中的错误,然后才能继续,或者在任何人能够适当地帮助您之前。我是stackoverflow的新手,评论部分不允许我发布错误所说的内容,因此我编辑了主要问题。
addSubView
应该是
addSubView
UIView alloc
应该是
UIImageView alloc
。看起来您还没有定义
BeginAnimation
函数;你应该这样做。看起来你可以从编程的一些基本教程中受益匪浅。尝试在internet上搜索Objective-C编程教程,这样您就可以学习如何调试上面提到的简单错误。在你能创造出一个Flappy Bird克隆之前,你有很多的学习要做。