markckim
markckim

Reputation: 499

Detect or track whether a selector has been scheduled in cocos2d?

I'm using the CCNode class in cocos2d and would like to use its schedule:interval: method. Is there a way to detect or track whether a method is currently being scheduled?

What I think I want to do: I want to create multiple schedulers with different intervals of time (i.e., one scheduler with 1.0 seconds, one scheduler with 2.0 seconds) and have them all enter one method (let's call it "checkSchedulers"). I want the checkSchedulers method to see if any of the schedulers are active, and change the value of a BOOL variable only if all the schedulers are inactive.

Thanks in advance.

edit: my current solution is to add a BOOL variable that keeps track of each scheduler (i.e., set it to YES every time the scheduler is scheduled, and set it to NO in the method the scheduler enters at the end of the interval)

Upvotes: 2

Views: 1165

Answers (1)

johnbakers
johnbakers

Reputation: 24771

Your technique with the BOOL is the correct one. It will give you an independent way of verifying how you've set things up, which can be quite reliable if your handling of the BOOL is solid.

Just set the BOOL at the time you schedule the method, and set it again when you unschedule it.

Upvotes: 3

Related Questions