Ah~I am discorder in this.

who can give me a tutorial of operation mechanism like XNA using draw() and update() to control all.
Before cocos2d-x I learned XNA.
XNA use draw() and update() to control a game how time to draw I need and to update what I need.
So I use it more easy.
After I read some tutorial about cocos2d-x,I haven’t find any tutorial to explain cocos2d-x how to work?
Maybe U will agree my point that is Game is update game data and draw the data by animation.
We can control my game data,so we can control my animation.
We are director.
But I don’t know cocos2d-x how to control it.
Like I use a CCAnimation to draw what I want,but I just can use it one time,I need a loop,not only one.
I can’t find the way to control it do the another time.
I don’t konw where and when I can change my date,because the draw is always run in 60FPS.
I am disorder in this.
If U readed something like I descrbied or U know my problem.
Can U give me some tutorial of operation mechanism.
Maybe it just need describe it how to work

Thanks a lot!

There is a class called CCScheduler which can handle an “update” function as in XNA.
http://www.cocos2d-x.org/reference/native-cpp/de/dee/classcocos2d_1_1_c_c_scheduler.html

In your main scene, at the end of your init function, if you put:

this->schedule(schedule_selector(MainScene::update), 0);

This will schedule the function MainScene::update to be called every frame (0 is the default for calling every frame)

The prototype for MainScene::update is as follows:

void MainScene::update(float dt)

You can see this method been used in this example:
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5*-*How_to_Detect_the_Collisions
with the slight correction that in that example, the prototype is wrong and should be as above in the latest version

Phill Jones wrote:

There is a class called CCScheduler which can handle an “update” function as in XNA.
http://www.cocos2d-x.org/reference/native-cpp/de/dee/classcocos2d_1_1_c_c_scheduler.html
>
In your main scene, at the end of your init function, if you put:
[…]
>
This will schedule the function MainScene::update to be called every frame (0 is the default for calling every frame)
>
The prototype for MainScene::update is as follows:
[…]
>
You can see this method been used in this example:
http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Chapter_5_~~_How_to_Detect_the_Collisions
with the slight correction that in that example, the prototype is wrong and should be as above in the latest version

thanks your help
But I still have a problem.
schedule is update,then the draw is where?
I just know when I add a sprite in a layer or sence
Like this:
this~~>addchild(aSprite)

The aSprite will show me.
That is mean I put sprite in sence or layer is I draw them.

The ‘draw’ function (or drawing of sprites) is handled automatically when you add a sprite as a child to the layer (which is a child of the main scene).

I have never handled drawing in any other way with cocos2d-x. It is just easier to let it do it on its own!

I hope that helps =]

Phill Jones wrote:

The ‘draw’ function (or drawing of sprites) is handled automatically when you add a sprite as a child to the layer (which is a child of the main scene).
>
I have never handled drawing in any other way with cocos2d-x. It is just easier to let it do it on its own!
>
I hope that helps =]

Thanks so a lot
Thank you very much