Game Development Reference
In-Depth Information
Cocos2d uses a resolution-independent coordinate system using points instead of
pixels. One point is exactly one pixel on the SD devices, but one point is two pixels on
Retina display devices. By writing all positions in points, the coordinates will remain
the same on both devices! On a Retina iPhone the pixel resolution is 960×640, but the
point resolution remains 480×320, which makes it a lot easier to develop apps for both
Retina and non-Retina devices.
Tip To set an object to an exact pixel location on Retina devices, express the
points in fractions. For example, the point 100.5,99.5 will set an object to the
pixel coordinate 201,200 on a Retina device. However, this also sets the pixel
position to 100.5,99.5 on a non-Retina device, which is referred to as subpixel
rendering. Because the image is not on an exact pixel location, some blending
can occur, which can cause objects to not align properly or to leave gaps.
Avoiding this kind of situation is generally recommended.
Cocos2d is smart when it comes to loading images. If your code has Retina support en-
abled, and the app is running on an iPhone or iPod touch device that has a Retina dis-
play, cocos2d tries to load a sprite with the -hd suffix first. When the app is running on
a Retina iPad, cocos2d looks for the sprite with the -ipadhd suffix instead. These suf-
fixes are not fixed and can be changed through the CCFileUtils singleton class, al-
though I recommended sticking with the defaults as they're most widely supported by
third-party tools. You can find this code with explanations in newly created cocos2d
projects in the AppDelegate.m file:
Search Nedrilad ::




Custom Search