Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Cocos2D调用方法每秒多少次?_Ios_Methods_Cocos2d Iphone_Intervals_Schedule - Fatal编程技术网

Ios Cocos2D调用方法每秒多少次?

Ios Cocos2D调用方法每秒多少次?,ios,methods,cocos2d-iphone,intervals,schedule,Ios,Methods,Cocos2d Iphone,Intervals,Schedule,我正在使用cocos2d2.0,目前我的问题是将一种方法安排为每秒一定次数 我基本上想做的是: 1. If score is 10 or less, call the method 5 times a second 2. If score is 11 or more, call the method 10 times a second 所以在间歇期,我试着分别做1/5或1/10,但都不起作用。有没有什么方法可以让我用这个电话来做 [self schedule:@selector() inter

我正在使用cocos2d2.0,目前我的问题是将一种方法安排为每秒一定次数

我基本上想做的是:

1. If score is 10 or less, call the method 5 times a second
2. If score is 11 or more, call the method 10 times a second
所以在间歇期,我试着分别做1/5或1/10,但都不起作用。有没有什么方法可以让我用这个电话来做

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

谢谢

是的,
schedule:interval:
就可以了。这里的问题是,
1/10
1/5
是由两个整数文本定义的分数,因此按照C约定应用整数除法,结果为0

尝试使用
[self schedule:@selector(yourMethod)interval:1.0/10]
,它应该可以工作


需要注意的是,
schedule:
方法会自动更新时间间隔。如果您重新安排了同一个选择器,则无需提前取消计划。

我认为使用此方法可以实现目标

if(score <= 10){
[self schedule:@selector(yourMethod) interval:0.5f];

if(分数,谢谢,我不知道每次我想更新时间间隔时都不必取消计划。我想出现此问题的另一个原因是因为我的方法中没有使用浮点,而是使用了int。我犯了一个愚蠢的错误!:)这就是我写的:“这里的问题是,1/10和1/5是由两个整数文本定义的分数,因此根据C约定,应用整数除法,结果为0。”通过写入
1.0/10
,其中一个是浮点,因此结果计算正确(它是
0.1
)感谢您的回复,我会稍后再尝试,看看它是否解决了我的问题。