Problem with CCTimer callback

Problem with CCTimer callback
0.0 0


Hi all!
I have a class which inherits from CCNode. What I need is function callback which is called every second to process some logic. I decided to use CCTimer, but when I do this:

CCTimer::timerWithTarget(this, schedule_selector(MyClass::MyCallBack),1);

void MyClass::MyCallBack(ccTime t)
//some logic
Nothing happens. It doesn’t work. What is my problem?
Thanks in advance


CCTimer is used by CCScheduler, you can not use it like this way.
I think you can invoke


Where this is an instance of MyClass.


Thanks for reply. I tried this, it doesn’t work again. Callback is not called. Note that I have manual class which inherits from CCNode. By the way I have another class which inherits from CCLayer, I initialized it and everything works. I don’t understand what is different betwween this two classes.


The classes that can use schedule_selector should inherit from SelectorProtocol.
CCLayer inherits from SelectorProtocol, but CCNode doesn’t.


Something wrong… I inherit my class from CCLayer but callback is not called again. :frowning: Maybe I need something like run this Layer or initialize or redefine some virtual function…I am confused. For example I have class House which inherits from CCLayer. I create a lot of House objects and call schedule with callback in each constructor. but it is not work. Help please :frowning:


Did you call schedule()?
Or you can paste some codes.
You may find this usage in tests many times. Just research “schedule_selector”.