我试图创建一个能飞到场景中心的盒子,但是SKAction似乎从来没有运行过,为什么呢?
-(void)update:(CFTimeInterval)currentTime {
CFTimeInterval delta = currentTime - _previousUpdateTime;
_previousUpdateTime = currentTime;
if (playerLives == 0 && isGameOver == NO) {
[self endGame];
[self moveBallToStartingPosition];
[self displayGameResults];
}
}
....
-(void)displayGameResults {
SKLabelNode *result = [SKLabelNode labelNodeWithFontNamed:@"Helvetica"];
result.color = [UIColor redColor];
result.fontSize = 20;
result.name = @"gameResultsLabel";
result.text = [NSString stringWithFormat:@"Game over! score: %d", playerScore];
SKSpriteNode *container = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:[result calculateAccumulatedFrame].size];
container.alpha = 0.3;
container.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame));
[container addChild:result];
SKAction *moveTo = [SKAction moveTo:CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) duration:3.0];
SKAction *fadeIn = [SKAction fadeInWithDuration:3.0];
[container runAction:moveTo];
[container runAction:fadeIn];
[self addChild:container];
}如果将这些操作应用于SKLabelNode,则这些操作也不会运行。
编辑:代码中没有任何调用来删除操作。我不明白他们为什么不开枪!
发布于 2014-03-23 21:40:43
我知道是什么导致了它,它是我的endGame函数中的一行代码,它将物理世界的速度设置为0。
-(void)endGame {
isGameOver = YES;
self.speed = 0.0;
}注释掉self.speed = 0.0解决了这个问题。哇哦..。
发布于 2014-03-22 15:57:49
不要以这种方式运行操作。
如果您希望它们在一个序列中工作,那么使用序列操作。
SKAction *sequence = [SKAction sequence:@[moveTo,fadeIn]];
[container runAction:sequence];如果希望它们同时工作,则使用组操作。
SKAction *group = [SKAction group:@[moveTo,fadeIn]];
[container runAction:group];如果这不能解决你的问题让我知道..。但是,您应该以这种方式执行操作。
更新
添加update:后,请确保条件playerLives == 0 && isGameOver == NO仅为真一次。因为您的update:可以在一秒钟内被调用60次,这将导致result在一秒钟内创建60次。
https://stackoverflow.com/questions/22579815
复制相似问题