I am using Cocos2D 2.0 and my issue at the moment is scheduling a method a certain amount of times per second.
Pretty much what I am basically trying to do is:
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
So for the interval, I have tried doing 1/5 or 1/10 respectively and it hasn’t worked. Is there a certain way I should be doing this using this call?
[self schedule:@selector() interval:];
Thanks!
Yes,
schedule:interval:will do the trick. Problem here is that1/10and1/5are fractions defined with two integer literals, so by C convention the integer division is applied and result is 0.Try with
[self schedule:@selector(yourMethod) interval:1.0/10]and it should work.It’s useful to note that
schedule:method automatically updates the interval if you reschedule the same selector, you don’t need to unschedule it before.