0.0 0


Hi, I’m new at Cocos2D-X but I’ve made some games before. I’ve always had Update() and Render() functions (update usually had a float for time) that were called every frame for each object shown (and/or not shown).

I was wondering where are these in the files such as CCSprite and the like? Or how would I go about knowing when it should update and what it should render?

All new to this, so any information would be appreciative! Thanks!


I think you should try another approach than you describe.

Look at http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_3*-*How_to_Move_a_sprite :slight_smile:

  • Rendering sprites is not your work, just add it to CCLayer with addChild() and engine would render it for you
  • If you want render something directly, CCLayer have method draw(), overload it
  • If you examine wikipage, that i refer before, you can find answer about update too :slight_smile:
    introduce member
    void update(ccTime dt) of course
    and call somewhere in layer init func
    schedule( schedule_selector(YourLayer::update));


So I should include CCSchedule in my object with a

void update(ccTime dt);

and then in my main game area (currently it’s HelloWorld - will change), have the

this->schedule( schedule_selector(GameBoard::update), 1.0 );

there? Is that what I’m reading correctly?

Then in that GameBoard::update, I do whatever I want to be updated during it?


You don’t need to call update & render in your game logic. They are done in engine internal.
The message loop is wrapped in CCEGLView or CCApplication, depends on different platforms. You can read the source from these 2 class, and find the answer easily.


Then in that GameBoard::update, I do whatever I want to be updated during it?

My answer is yes :slight_smile:


In new version of CoCos2dx you should use update(float dt); rather than update(ccTime dt);