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've been working on a little game for the last few months, trying to approach it as a software engineer and employ best patterns and practices in my coding. I have gotten to the point where I have to distinct elements in my game.

1) The Game Logic: aka business logic. Its the meat of the game rules. It contains all information about game objects (such as Character, Weapon, and Item class definitions). It contains the game world as far as rules are required; mainly so Characters are aware of the world they are in, and who else is in it. It contains a chunk of logic use to determine how Fighting is resolved between Characters, as we as other game actions requiring rules. It contains my AI implementations. So in reality it's a combination of Class definitions and Service logic.

As it stands, the Game Logic can actually play out a game without any interface. All I need to do is create a World, add some Characters to it, assign some AI's to them, then in a loop tell their AIs to run. The result of each AIs action is reflected in the states of the Characters (eg, if damaged, health is reduced), and a summary of what happened is returned by the execution (which is intended for the UI to make sense of what happened).

2) The Game UI: which is using Cocos2d-xna for WP7. It contains definitions of all the different animations. It takes in inputs and sends the to the Game Logic, and renders its results.

As it stands, as well as all UI components for a Character (textures, sprites, animations) a UI Character also contains a Begin method which executes a Cocos2d Sequence (ccSequence) to do two things 1) Execute AI and render result for this Character 2) Re-Execute the sequence (essentially its own call back loop for executing actions).

The problem I keep running into is, the more I try to keep these two layers separate, the more they need to come together. E.g., my UI Character which is used to render what the Game Logic character is doing, so it needs a reference to the Character object from Game Logic. When this Character's AI attacks someone in the Game Logic world, the UI needs to know what happened. This works fine for rendering its own Animations based of its results, but to know what to do for other Characters affected by this action is difficult as I dont have reference to them. At the moment I do this by queuing up Pending Animations in the other character's Game Logic Character and render it when that character next executes, but this is anti SoC as it now contains something specific for the UI to focus on.

I don't want the two projects to merge into one where a Game Logic Character contains all things UI as well, such as animations and actions. Is there a nice clean way that is used for this separation? Ideally something that works nicely with Cocos2d's Action pattern?

share|improve this question

If you want decent SoC for games, without annoying wrapper code and consequent performance concerns, you should to pick a language / platform / library combination that meets that goal in the first place, or at least gives you the ability to write your own framework without undue restrictions.

You'll soon enough get the Cocos2D guys telling you to do it the Cocos2D way. And I'd agree with them. There is no inherent MVC separation there, and trying to force it will make your life harder.

(I maintain a small, cross-platform library on google code which exists for the purpose of cross-platform SoC. I wrote it in such a way as to make it repluggable between languages / platforms, but some are just too far gone to bother with. Take Unity3D for instance. The core classes / "framework" that they have in place is so obtrusive and over-engineered that while I certainly could wrap Unity3D, I'd probably not even attempt the task in the first place -- not to mention that wherever an accepted framework already exists, the associated community could probably be said to hold fairly rigid beliefs about how awesomely structured it is, and so tend not to want to adapt to a whole different structure. Hence the above comment about the Cocos2D guys. They have a point, even if the architecture they're willing to use, is not particularly well thought out.)

But this is about your coding comfort, not anyone else's. So for decent architecture, my advice is look into rolling your own in a more flexible, less assumptive language / platform like JS, Python, Java, C or C++.

Adapt, or move on.

share|improve this answer
I think for this game, I'll go with the conformist approach and do it the Cocos2D way. It has so far saved me a lot of time getting the game up and running which has been vital as working full time and being married leaves not much time for hobby coding. – Arkiliknam Dec 31 '12 at 10:42

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.