by gnomesgames....
Hi, I faced the same problems when i started cocos2D. I can explain what i have done, i don't think there is only one solution, and i don't think mine is the best ^^"...
So, the Director in cocos2D handle everything, it play scenes, manage the screen refresh, the framerate etc...
Director can only play one scene at time, so i have one game scene, it a subclass of Scene. Then i have separated my objects in two subclasses of layer, one layerStatic that contain every static object (sprite, labels (text), etc...) that will not change during the scene, in my case it's just my background image (a Sprite). The other called layerActive contains every active object, the player (a subclass of Sprite), the ground (that can move in my game, also a subclass of Sprite), the score etc...
This layer manage the game loop, it manage everything, from updating the score to touches events ----(because only a layer can manage touches events)----. The great thing with this method, is that i can easily get all information, and made objects interacts between each others.
For example, my player object is called "monJoueur", and my ground "maPlateforme", when i test if the player isn't under the floor i can do :
if(monJoueur.position.y<maPlateforme.position.y)
{
monJoueur.position = ccp(monJoueur.position.x,maPlateforme.position.y);
}
So, the only thing left to explain, is how to make the game loop :
In the init method of layerActive i use this command : [self schedule:@selector(jeux:)];
this tell cocos2d that i want the "jeux" method of self to be called at each frame.
Here my method "jeux" :
-(void)jeux:(ccTime)dt
{
[self gereMouvement:dt]; //Handle the movement
//Handle other things ;)
[self gereGouttes:dt];
[self arreteLesVagues:dt];
[monProtecteurChute updateMe:maPlateforme.position.y];
}
is this the best practice in game design and prog....
note in Gorillas there is layer for every thing....