My favorites | Sign in
Logo
                
Search
for
Updated Jul 31, 2009 by ricardoquesada
BestPractices  
cocos2d for iPhone best practices

DEPRECATED

DEPRECATED DEPRECATED

Use this page instead:

http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:best_practices

Introduction

iPhone is a very nice device. Although it has very nice and powerful features, you must be careful when programming for it. So here are the cocos2d (and general) best-practices.

Details

Improving performance

  • Use this guide as reference: perf_test.pdf
  • Use fast director:
  •     // must be called before any other call to the director
        [Director useFastDirector];
  • When possible try to use texture atlas:
    • Use AtlasSprite instead of Sprite
    • Use BitmapFontAtlas or LabelAtlas instead of Label
    • Use TileMapAtlas to render tiles
  • When possible, try to use 4-bit or 16-bit textures
    • 16-bit textures for PNG/GIF/BMP/TIFF images (16-bit textures are the default in v0.8)
    •    [Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA4444]; // add this line at the very beginning
    • 4-bit or 2-bit textures: Try to use PVRTC textures.
    •    Sprite *sprite = [Sprite spriteWithFile: @"sprite.pvr"];
    • Use 32-bit textures as the last resort

Reducing Memory

Timers

draw vs update

Director flow control

Creating Nodes (Sprites, Labels, etc..)

Hierarchy of Layers

Actions

Buttons

how does the pause/resume works ?


Comment by lindgren.mitch, Jun 02, 2009

I'd like to add that you should make sure "thumb compilation" under build settings in your project is OFF. It's off in the Cocos2D Xcode project, but if you create your own project and add the Cocos2D files to it, it will be on by default. You will see a SIGNIFICANT performance increase by turning this off.

Comment by druva.flash, Jul 30, 2009

do u have any piece of example that explains pause/resume? we are little bit confused with it


Sign in to add a comment
Hosted by Google Code