开发者

Handlings Game Loops in cocos2d

How does one handle multiple elements of a game at once?

In a scroller which the background/tilemap moves every gameloop how is the user input handled at the same time?

The map needs to be moved in the game loop and collision needs to be checked for the player object and parts of the map which it shouldnt hit, and there also needs to be code which takes the user input, moves the player on the map and checks for collisions too?

Should these be threaded or how are these done in cocos2d?

Are 开发者_如何学JAVAthere any built in methods?


Register a step method with a specified interval.

[self schedule:@selector(step:) interval:1.0/60.0];


// Main loop of the application
-(void) step:(ccTime)delta
{
     // do your step actions here
}

Try and avoid registering multiple step methods. You can do everything you need in one step method. You don't need to use threading.


It is prefer to register the update method

[self scheduleUpdate];

Then override the update method as you like

-(void) update:(ccTime)delta
{
    //All steps happen here
}

this will be called in every frame of your game more accurately by the cocos2d than schedule a new one.

(Cocos2dx version: this->scheduleUdate(), void update(float delta);)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜