我正在尝试构建一个玩家向右移动的游戏。我也希望背景在玩家运动的相反方向移动。怎么实现这个?我需要它看起来像飞扬的鸟背景。我没有使用spriteKit或swift。错误一直显示"整数常量"上的无效后缀xscreenwidth。
我希望它看起来像这样的背景http://www.youtube.com/watch?v=RkGUk40LkrQ但我唯一能找到的就是spriteKit。
我在UIKit中需要它到目前为止我有这个:
它说 没有可见的@interface for UIView声明了选择器initWithImage,没有可见的@interface用于UIView声明选择器addSubView,并且没有可见的@interface用于UIView声明选择器beginTheAnimation
#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];
}
答案 0 :(得分:0)
乘法运算符为*
,而不是x
。显示错误是因为您在此行中有2xscreenWidth
:
CGRect startingPosition = CGRectMake(0,0,2xscreenWidth,screenHeight);
将其更改为:
CGRect startingPosition = CGRectMake(0,0,2*screenWidth,screenHeight);