Im in the middle of creating my first iPhone game - I have a background in OOP and in particular C++ so I had some questions with regards to how best to logically setup layers while maintaining functionality.
Currently I WANT for my game to have three main layers:
Notice I used the word WANT here - because for the life of me im constantly having to move logical objects around just to work within what appears to be Cocos2d's and spacemanagers structure.
Below are just some of the issues that I'm facing
Am I missing something very obvious here? is there a core understanding of layers that Im just not getting? More and more I feel like im being pushed by the framework to build the whole game inside of a single class and just to use layers as scenes.
Is anyone else having these problems? Am I approaching the architecture of the game wrong? Any help would really be appreciated.
Thanks in advance guys!
Well, each game is different. There are many good discussions on the cocos2d forums about architecture, some people prefer to use an MVC approach, some like using an Actor
metaphor to contain physics objects, etc.
Here's my approach:
CCLayer
objects (GameLayer and HUDLayer) as child nodes of one CCScene
(GameScene). These are the "view" objects.GameController
singleton that can make changes to the game state (also stored in GameController, or in a separate file.) You could also subclass CCScene and call that your controller.GameLayer
is in charge of rendering the graphics of the game level and all actors in it; it also handles getting game input via touch events.HUDLayer
is placed at a higher z-index than the GameLayer and obviously has all of the CCSprite objects for the HUD and buttons.HUDLayer
and the GameLayer
is managed via the GameController.GameController
does all of the state changing and game actions.That's just my approach because it worked for my current game, and it by no means is the definitive answer.
I'd suggest that you look into using an Actor
paradigm for your physics objects -- SpaceManager does a decent job, but you don't necessarily always want physics objects to extend CCSprite.