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.
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 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
- Remember when using box2d, you have to new and delete the object since box2d is written by c++.
- 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.
- 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.