CCTimer Help


I am trying to start a timer, that I have as a public member variable

 cocos2d::CCTimer _growingTimer;

_growingTimer = cocos2d::CCTimer::timerWithTarget(this, schedule_selector(Broccoli::plantStoppedGrowing), 1);

But I am getting:

Unknown type name 'SEL_SCHEDULE'; did you mean 'cocos2d::SEL_SCHEDULE'?


No matching function for call to 'timerWithTarget'

But even adding a


to the


doesn’t help

Does anyone have a working example? I just need to run the timer once and check it periodically to see how far in it is.

  1. Make sure the “this” is a CCObject.
  2. Try adding USING_NS_CC before the definitions.


Make sure to schedule the same class function.


Hi Lance,

Good Ideas, that made things compile.

Do you start a timer with >update?
I did:
<pre>*growingTimer = cocos2d::CCTimer::timerWithTarget, 10);

void Broccoli::plantStoppedGrowing()
std::cout << “Broccoli Stopped Growing” << std::endl;

Hoping that in 10 seconds I would see my


Touch Coder,

What do you mean?


I haven’t used CCTimer but it seems that the 3rd parameter would be time needed to wait until the selector is called.
No need to call update().

You could also do this without using CCTimer.

this -> scheduleOnce( schedule_selector( Brocolli::plantStoppedGrowing ) /* method to invoke */, 10 /* delay */ );


Hi Lance,

I am still experiencing some issues.

I tried:

this -> scheduleOnce( schedule_selector( Brocolli::plantStoppedGrowing ) /* method to invoke */, 10 /* delay */ );

But realized that I am not sure I can use scheduleOnce as this class subclasses CCObject (no real reason, it doesn’t beed to, but thought it might be handy later on)

I also saw you replied to another post about delaying/scheduling here:

Can you provide some pointers on what I can so?

Basically the user clicks on a CCMenu item (in this case Broccoli) and after then click it I want to run Brocolli::plantStoppedGrowing after a set amount of time.


Try changing it to CCNode.


I did that, but the nothing fires after 10 seconds. I even have a std::cout in the function being called to verify.

Here is the code:

 this->scheduleOnce(schedule_selector(Broccoli::plantStoppedGrowing ) /* method to invoke */, 10 /* delay */ );
    std::cout << "Past scheduleOnce" << std::endl;

When it hits that I see on the console:

planting broccoli
Past scheduleOnce

In the plantStoppedGrowing() I have:

void Broccoli::plantStoppedGrowing()
    std::cout << "Broccoli Stopped Growing" << std::endl;

but if I tap the menu item again I do see on the console:

Cocos2d: CCScheduler#scheduleSelector. Selector already scheduled. Updating interval from: 0.0000 to 0.0000


I’m still not figuring this out. Does anyone have any advice?


after some work today, using some C++11 threading works well for this.