RSS

Several Cocos2d Technical Tips

19 Mar

Recently I am using cocos2d engine to develop two game prototypes. Here are several tiny technical tips that I find useful.

To judge whether app is run on iPad or iPhone.

 1: if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

 2:     /* Then this is run on iPad */

 3: }

 4: else{

 5:     /* on iPhone or iPod */

 6: }

PS: This method can only be used on or after iOS 3.2.

OpenGL ES view’s origin is left-bottom, while the UIKit in iOS is the top-left.

That is to say, cocos2d’s coordinate system’s origin point is on the left bottom. Every time we get the touch point in the screen, we need to transform it into cocos2d coordinate.

CCArray

CCArray will add the retain count of each object in it. So the method addChild will increment the retain count because that the children array is of CCArray type.

Touch or Accelerometer Events

Receiving touch or accelerometer events are costly task, so avoiding designing too many layers to receiving the events.

Tips on using Box2D

  1. Remember when using box2d, you have to new and delete the object since box2d is written by c++.
  2. Box2d is tuned for metric system and is working best from 0.1 meter to 10 meters. So make sure you map your distance into this specific range.
  3. Tips for box2d step configuration (timeStep, velocityIteration, positionIteration)
  • Time step is the elapsed time from last step, usually passing the delta time is not a good idea. Since the frame rate may vary because of the programs running in the background(sending and receiving email), the calculation of physical engine will not be persistent and will trembling strangely. Giving a constant value is more suitable. And generally physics engines for games like a time step at least as fast as 60Hz or 1/60 seconds.
  • Usually, setting velocity iteration to 8 is a good starting point and beyond 10 is hard to detect by human eyes.
  • For position iteration, 1 is enough in many case since we care less about the precise location and care more about the velocity in many reality cases.

Those tips originated from my practice or come from other people’s suggestion. If you have something useful, please free feel to share with us! Sharing is a virtue. Smile

Advertisements
 
6 Comments

Posted by on March 19, 2012 in Technical notes

 

Tags: , , , , ,

6 responses to “Several Cocos2d Technical Tips

  1. Wesley Bao

    March 19, 2012 at 6:33 pm

    Why you start to use cocos2d? Why not Game Maker or Unity?
    And thanks for adding Coconut Island’s home page link on your blog.

     
    • Nofootbird

      March 19, 2012 at 7:48 pm

      Cocos2d has the ability of quick prototyping, and to further develop it into real product. Game maker is only suitable for prototype and has many limits. Besides, Unity and game maker cannot export game into devices without cost. 🙂
      I really enjoy the time working in coconut island.
      HAHA!

       
  2. Wesley Bao

    March 20, 2012 at 11:55 am

    I agree with you and I think learning native code on iOS is good for you to understand the whole system.
    (But in these two weeks you can get Unity iOS and Android license for free on their official website.)

     
    • Nofootbird

      March 20, 2012 at 12:30 pm

      Yes, learned much. A great benefit is that you can control more. And I have downloaded the unity recently, yet in essence, unity is a 3D engine. I still wonder the convenience of building 2D games. How are your games?

       
      • Wesley Bao

        March 20, 2012 at 3:16 pm

        We use ex2d plug-in by Abit games to help us make 2d games. It’s pretty convenience.

         
      • Nofootbird

        March 21, 2012 at 12:06 am

        WOW! I will check this plugin later.

         

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: