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?