Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a simple tower defense game, and I have to take a decision between two(or more, feel free to suggest other ways) to do the game cycle.

Option 1: Monolithic game cycle:

I could have a global scheduled selector that calls update for every sprite/object/logic thing that I need to calculate.

I could achieve this by having a singelton Game class that has a mutable array of objects and then on the Scene(or that singelton) I could have a setup with:

[self schedule: @selector(gameCycle:) interval:0.1];

And then on that gameCycle do something like:

-(void) gameCicle: (ccTime)dt {
    for(Entity* e in [[Game sharedGame] entities]){
        [e gameCicle];

Second option: Each object could create its own selector @ init. This is almost the same, but instead of a singleton, every time that i create a object I could create a new scheduled selector as such:

-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect {
    if( (self=[super initWithTexture:texture rect:rect])) {
        [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
            [self schedule: @selector(gameCycle:) interval:0.1];
    return self;

Now I don't know what is better(or if there is a very big difference in performance). What is the usual/best approach for cocos2d?

share|improve this question

Use the first one. You certainly don't want your timers be called in random order.

Although I'd suggest to actually use none of them, but use the standard update method of cocos2d. This will give you the best available performance and consistent behavior.

share|improve this answer
I don't see any documentation on that in the best practices ( could you share me some links/or an example. BTW I am NOT drawing from this scheduled selectors. – DFectuoso Aug 20 '10 at 17:07
Actually according to "Each node, by default, has no updates. If you want to update the state of your node you should schedule a callback". – DFectuoso Aug 20 '10 at 17:59

There is a third option: have a small number of scheduled updates for tasks that can be independent.

Scheduling one update method for each layer could be useful, especially if they are logically separate. One useful example of this is using one scheduled method for the main game logic and another to update the score display.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.