Sprite Kit 中的计时器 [英] Timers in Sprite Kit

查看:25
本文介绍了Sprite Kit 中的计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有使用 Sprite Kit 的经验.我想知道 Sprite Kit 中是否有类似于 Cocos2D scheduler 的东西?如果没有,应该用什么 NSTimer 是唯一的选择?我想如果唯一的选择是使用 NSTimer 我们需要手动处理应用程序在后台时的情况.谢谢.

I don't have experience with Sprite Kit. I was wondering is there something similar to Cocos2D schedulers in Sprite Kit ? If no, what should be used NSTimer is the only option? I guess if the only option is using NSTimer we manually need to handle case when application is in background. Thank you.

推荐答案

要实现类似cocos scheduler的功能可以使用SKAction.

To achieve functionality similar to cocos scheduler you can use SKAction.

例如为了实现这样的事情

For example for the to achieve something like this

[self schedule:@selector(fireMethod:) interval:0.5];

使用 SKAction 你会写这个

using SKAction You would write this

SKAction *wait = [SKAction waitForDuration:0.5];
SKAction *performSelector = [SKAction performSelector:@selector(fireMethod:) onTarget:self];
SKAction *sequence = [SKAction sequence:@[performSelector, wait]];
SKAction *repeat   = [SKAction repeatActionForever:sequence];
[self runAction:repeat]; 

它不是最好看的,并且缺乏 CCScheduler 的一些灵活性,但它会在后台暂停、暂停场景/视图等时暂停.这就像在玩 LEGO :)

It isn't best looking, and lacks some flexibility of CCScheduler, but it will pause upon backgrounding, pausing scene/view etc. + it is like playing with LEGOs :)

这篇关于Sprite Kit 中的计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆