Monday, 17 October 2011

Cocos2D Prototype results

Wow, that was a step up in complexity! The exercise has proven that GameSalad and Corona seriously wrap up the physic engine. This proved to be an uphill struggle at first as there were three key areas I / you will need to know to get this example working:
  1. A decent understanding of Xcode
  2. Using the community support for Cocos2D a lot.  Thankfully its very good
  3. Working out how on earth Box2D worked with some next to useless documentation.
I had to use a completely different technique to collision detection in Cocos2D than I had in the previous two which meant having to construct the red bars separately and then attach the physic's bodies to it.  The challenge I had for a long time was that the collision was never happening this became very frustrating until I got my head round the debug drawing.

To initialise the debug draw put the following in the init method:
// Debug Draw functions
        m_debugDraw = new GLESDebugDraw( PTM_RATIO);
        world->SetDebugDraw(m_debugDraw);
        
        uint32 flags = 0;
        flags += b2DebugDraw::e_shapeBit;
        m_debugDraw->SetFlags(flags);

Then all you need is to create your draw method:
-(void) draw
{
 [super draw];
    glDisable(GL_TEXTURE_2D);
 glDisableClientState(GL_COLOR_ARRAY);
 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    
 world->DrawDebugData();
    
 glEnable(GL_TEXTURE_2D);
 glEnableClientState(GL_COLOR_ARRAY);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
}

Using this really allowed me to resolve the collision issues very quickly and proved invaluable as I found that I was making my bodies dynamic instead of static which meant they were falling off the bottom of the screen.

So, as always, what did I think based on my test criteria. My findings were as follows:
  • The ability to add scenes by creating new classes is simple enough and easy to adopt if you are used to Xcode.
  • The integration of Box2D into Cocos2D requires a steep learning curve to achieve the same results that can be done in minutes within GameSalad or Corona. 
  • If you are used to any Apple device development then the fact its in objective-c makes picking this up very easy
  • Knowledge of C++ or its syntax would be advantageous to get under the bonnet of Box2D.
  • The templates provided by Cocos2D framework through Xcode provide a good starting point as well as leveraging the normal tools of the Xcode development environment.

As far as price points go this is going to take some beating, its free! The downside though is that there is no Android support so this will have to be a consideration before adopting this for the rest of the project.

While this was tough I felt I learnt a lot from the experience and being a developer by trade in control. Which for me is important. At this time Cocos2D is narrowly leading if I decide not to include Android development at this time.

2 comments:

Steffen Itterheim said...

May I throw in Kobold2D (http://www.kobold2d.com) for good measure?

It provides you with a Box2D template project that has debug drawing and collision detection already setup for you. The Pinball game example also shows you how to use Box2D joints. Also Kobold2D is already up to date with the latest (API breaking) Box2D version 2.2.1.

The next version of Kobold2D (coming 26-28th) will also have ARC enabled by default in all projects, which should be a blessing for someone with a Corona/GameSalad background. No more Objective-C memory management.

mygamingproject said...

Thank you for your comments Steffen I will certainly consider it.

Would you rate Kobold2D over Cocos2d?

Post a Comment

 
;