【问题标题】:Need help incorporating "Preform Selector: WithObject: AfterDelay:" with the SKScene being paused需要帮助将“Preform Selector:WithObject:AfterDelay:”与 SKScene 暂停
【发布时间】:2014-08-18 05:14:49
【问题描述】:
我需要帮助来整合
PreformSelector: WithObject: AfterDelay:
SKScene 暂停。
我正在制作一个游戏,其中有一个暂停按钮可以暂停场景。不过这并不影响
PreformSelector: WithObject: AfterDelay:
调用“重新加载”函数的函数。如果没有这个固定,用户可以开枪,按下暂停,等待重新加载功能被调用,取消暂停,然后射击。这使得用户可以连续射击,而无需在“游戏时间”重新加载。有没有办法解决这个问题?
【问题讨论】:
标签:
objective-c
sprite-kit
skscene
【解决方案1】:
您不应该使用performSelector:withObject:afterDelay:,因为使用该方法跟踪时间和存储选择器和对象等会非常麻烦。
改为使用 SpriteKit 的 +[SKAction waitForDuration:] 操作。
您可能想要执行以下操作(我假设此代码发生在您场景的某个方法中的某处):
// Replace 2.0 below with however long you want to wait, in seconds
SKAction *waitAction = [SKAction waitForDuration:2.0];
// I'm assuming your "Reload" method is a method declared in your scene's
// class and not some other class, so I'm using "self" as the target here.
SKAction *reloadAction = [SKAction performSelector:@selector(Reload) onTarget:self];
SKAction *sequenceAction = [SKAction sequence:@[waitAction, reloadAction]];
// Since I'm assuming this is in your scene implementation, `self` here
// refers to your scene node.
[self runAction:sequenceAction];
由于可以暂停和恢复动作,因此当您使用 self.paused = YES; 暂停场景时,您的动作也会暂停,并在您稍后取消暂停场景时从中断处恢复。