ios - Sprite Kit 在失去生命时暂停游戏
<p><p>我想不通。我有一个游戏,玩家必须在浆果从天上掉下来时接住它们。当玩家错过一个时,我希望屏幕闪烁红色,浆果停止掉落,让游戏暂停 3 秒然后继续。</p>
<pre><code>@interface SpriteMyScene : SKScene{
SKAction *sceneUnPaused;
SKAction *scenePaused;
}
</code></pre>
<p>2种暂停游戏的方法。</p>
<pre><code>-(SKAction*)unpaused {
sceneUnPaused = [SKAction runBlock:^{
self.scene.view.paused = NO;
}];
return sceneUnPaused;}
-(SKAction*)paused{
scenePaused = [SKAction runBlock:^{
self.scene.view.paused = YES;
}];
return scenePaused;
}
</code></pre>
<p>创建浆果的方法及其 Action 。</p>
<pre><code>- (void)addBerry {
...
...
// Create the actions
//For each individual berry
SKAction * actionMove = ...
SKAction * gameWon = ...
SKAction * actionMoveDone = ...
SKAction *wait3Seconds = ;
SKAction * loseAction = [SKAction runBlock:^{
;
NSLog(@"Lost a life");
;
;
;
;
;
if (_playerLives == 0){
[ stopMusic];
SKTransition *reveal = ;
SKScene * gameOverScene = [ initWithSize:self.size andScore:_berriesKilled];
;}}];
SKAction *berrie = [SKAction runBlock:^{
;}];
]];
</code></pre>
<p>}</p>
<p>我不知道你们是否有必要帮助我弄清楚为什么它不起作用,但这里是决定我何时生成浆果的更新方法。</p>
<pre><code>- (void)updateWithTimeSinceLastUpdate:(CFTimeInterval)timeSinceLast {
self.lastSpawnTimeInterval += timeSinceLast;
if (self.lastSpawnTimeInterval > ) {
self.lastSpawnTimeInterval = 0;
;
}
</code></pre>
<p>}</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>当玩家错过一个浆果时,只需这样做:</p>
<pre><code>;
</code></pre>
<p>启动一个 NSTimer,在 3 秒后执行以下操作:</p>
<pre><code>;
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - Sprite Kit 在失去生命时暂停游戏,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21865658/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21865658/
</a>
</p>
页:
[1]