我无法弄清楚这一点。我有一个游戏,当玩家从天而降时,他们必须抓住浆果。当玩家错过一个时,我希望屏幕闪烁红色,浆果停止下降,游戏暂停3秒然后恢复。
@interface SpriteMyScene : SKScene{
SKAction *sceneUnPaused;
SKAction *scenePaused;
}
暂停游戏的两种方法。
-(SKAction*)unpaused {
sceneUnPaused = [SKAction runBlock:^{
self.scene.view.paused = NO;
}];
return sceneUnPaused;}
-(SKAction*)paused{
scenePaused = [SKAction runBlock:^{
self.scene.view.paused = YES;
}];
return scenePaused;
}
创造浆果及其行为的方法。
- (void)addBerry {
...
...
// Create the actions
//For each individual berry
SKAction * actionMove = ...
SKAction * gameWon = ...
SKAction * actionMoveDone = ...
SKAction *wait3Seconds = [SKAction waitForDuration:3];
SKAction * loseAction = [SKAction runBlock:^{
[self subtractLives];
NSLog(@"Lost a life");
[self vibrate];
[self runAction:scenePaused];
[self runAction:wait3Seconds];
[berry removeFromParent];
[self runAction:sceneUnPaused];
if (_playerLives == 0){
[[SoundManager sharedManager] stopMusic];
SKTransition *reveal = [SKTransition fadeWithDuration:1.0];
SKScene * gameOverScene = [[GameOverScene alloc] initWithSize:self.size andScore:_berriesKilled];
[self.view presentScene:gameOverScene transition: reveal];}}];
SKAction *berrie = [SKAction runBlock:^{
[berry runAction:actionMove];}];
[berry runAction:[SKAction sequence:@[berrie, gameWon, actionMove, loseAction, actionMoveDone]]];
}
我不知道你们是否有必要帮助我弄清楚它为什么不起作用,但这里有更新方法决定何时我会产生浆果。
- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {
self.lastSpawnTimeInterval += timeSinceLast;
if (self.lastSpawnTimeInterval > [self determineAmountOfBerries]) {
self.lastSpawnTimeInterval = 0;
[self addBerry];
}
}
答案 0 :(得分:1)
当玩家错过浆果时,只需这样做:
[self.scene.view setPaused:YES];
启动NSTimer,在3秒后执行以下操作:
[berry removeFromParent];
[self.scene.view setPaused:NO];