【发布时间】:2014-04-07 17:49:44
【问题描述】:
我已经开始使用 Sprite Kit。我正在开发一款具有移动背景的游戏。现在我想知道如果我触摸屏幕如何使背景移动得更快,以及当我松开手指时如何正常移动背景。
我现在正在像这样移动我的背景。
代码开头是这样的:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
[self addBackground]
};
return self;
}
-(void)addBackground{
SKTexture* background = [SKTexture textureWithImageNamed:@"backgroundImage"];
SKAction* moveBackground = [SKAction moveByX:-1704*2 y:0 duration:0.004 * background.size.width*2];
SKAction* putOnStart = [SKAction moveByX:1704*2 y:0 duration:0];
SKAction* moveForever = [SKAction repeatActionForever:[SKAction sequence:@[moveBackground, putOnStart]]];
for( int i = 0; i < 2 + self.frame.size.width / ( background.size.width * 2 ); ++i ) {
SKSpriteNode* sprite = [SKSpriteNode spriteNodeWithTexture:background size:CGSizeMake(1704 ,320)];
sprite.position = CGPointMake(i * sprite.size.width, sprite.size.height / 2);
[background runAction:moveForever];
[self addChild:sprite];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touching = YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touching = NO;
}
我在视图出现时初始化它。现在问题是我想更新SKAction moveBackround 的持续时间。
【问题讨论】: