CCSprite update() help

CCSprite update() help
0.0 0


I subclassed CCSprite and I have overridden update:

void BroccoliSprite::update(float dt)
    std::cout << "plant update" << std::endl;

    if (fCounter == _growTime)
        std::cout << "plant Done growing" << std::endl;



but I dont see update getting called at all.

What else should I be looking for or doing?


CCNode::ScheduleUpdate() ??



Thanks Jacob.


Hi Jacob,

Can you think of any ideas to convert frames to seconds? Obviously it varies as the frame rate changes.


You mean the framerate?

So your formula for delay rate is duration_of_animation / #_of_frames. A typical animation is 0.1 seconds, but some are slower.

We typically run a 5 frame in 0.1 seconds. Then we tune it and apply some graphics tweening to add frames when necessary.


what I was thinking of doing was using the update() method as a timer. but that isn’t accurate enough that I can figure out.

void BroccoliSprite::update(float dt)

    if (fCounter == 

I could call scheduleOnce() but the issue I have with that is what if this hasn’t been called and the user minimizes the app or something. When the app comes back to life what happens to this scheduleOnce call?

So basically I ned to run some code after xx seconds but also be to pick up again if the app gets interrupted.

I could try some mechanics with std::chrono and see too I think


CCTimeDelay::Create(3f), /* 3 second delay */
CCCallFunc::Create(…void* to your func)

What you do in your callfunc can be your timer callback.


CCNode::Schedule(func, delay). This will call your func every delay seconds. If your app goes to sleep, just pause the director, and then when it resumes, you resume the director. If you do that, cocos2d will do the rest for you.


can you clarify a bit how to create a cocos2d::CCCallFunc?

 cocos2d::CCSequence* s = cocos2d::CCSequence::create(

I dont understand the constructor:

 static CCCallFuncN* create    (   CCObject *  pSelectorTarget,
SEL_CallFuncN   selector 

can you help me understand?


I even am trying:

cocos2d::CCDelayTime *delayAction = cocos2d::CCDelayTime::create(5.0f);

    cocos2d::CCCallFunc *callSelectorAction = cocos2d::CCCallFunc::create(this,
    // run the action

but I still get an error:

 Cannot cast from type 'void (*)()' to member pointer type 'SEL_CallFunc' (aka 'void (cocos2d::CCObject::*)()') 


Change Broccoli::test() to be Broccoli::test(CCObject *foo)

that should do it.


where is CCObject *foo coming from?


This seems to work:

    cocos2d::CCDelayTime *delayAction = cocos2d::CCDelayTime::create(5.0f);

    cocos2d::CCObject* foo;

    cocos2d::CCCallFunc *callSelectorAction = cocos2d::CCCallFunc::create(foo, callfunc_selector(Broccoli::test));
    // run the action

an I just making up a temp object (foo) that is unused, has no purpose?

LOL if I move this code to a subclass of CCSprite, called BroccoliSprite and do it there then I can pass in



“foo” there is the object that is the target of the action. You can use it to chain actions


like that.


great idea


excellent info today, BTW. Thank you so much for sharing. You have helped me set a clear path! You know your sh*t. :slight_smile:


That’s what we’re here for. We’re the maintainers of cocos2d-xna. I hope we know our shiznit.

Remember you can talk to the crew directly on #cocos2d. Someone is always on there.


speaking of cocos2d-xna, I was told that you can no longer develop an xbox console game with Cocos2d. Microsoft doesn’t allow it anymore in favor of C#.


hum, I had not heard that. I bet you can do it with Xbox One (cocos2d-x C++ that is). The world of PlayStation and Wii and Xbox is all very hush hush, so whatever you hear is likely just hear-say. Our rep at SONY is very strict about what we can say about the platforms and they are quick to deny access if you violate your agreements.

All we know is that Microsoft, SONY, and Nintendo are dedicated to providing the best access to all developers who want to bring world class entertainment experiences to their audiences, regardless of computing language or middleware.