Speaking of Simulators That Don’t Simulate.

One of my complaints about the Corona Simulator was that things don’t run at the same speed on the device and in the simulator. Generally they run faster in the Corona Simulator.

Well working with Cocos2d, I had written 2 lines of code and discovered things don’t run in the iOS simulator like the device. They run slower.

In Corona I do this:

-- display the background
background_image = display.newImage( "images/paper_bkg.png" )
group:insert( background_image )

And set the background to an image that looks like lined notebook paper – my app has a hand drawn metaphor.

In Cocos2d I did this:

CCSprite*   titleSprite = [CCSprite spriteWithFile:@"paper_bkg.png"];
float centerY = winSize.height - (titleSprite.contentSize.height/2);
float centerX = titleSprite.contentSize.width/2; // sqrt of 2
titleSprite.position = ccp( centerX, centerY);
[self addChild:titleSprite];

Run in the simulator and the FPS goes from 60 FPS to 15. Run it on the iPad and it goes back to 60 FPS.

Nothing Like Shit Not Working To Get You To Optimize

I looked around for the reason and found some posts about a background sprite being too big, and how you should break it up into smaller power of 2 parts and it will run faster. Tried that, but had problems getting the pieces to line up. And in the end you are still loading a really big image into memory to do this.

That’s when I learned my background image shouldn’t really be a PNG. Here’s why:

1. PNGs are always 32bit. Even if you take say a 16 bit image and save it as a PNG, it gets encoded 32bits per pixel.

2. You should use lower bit depth images if you can. iOS – welcome back to the good old days when memory mattered. Loading an 8bit retina resolution iPad image (2048×1536) is huge. Personally I can’t tell the difference between a scanned piece of notebook paper at 32bit color and 16bit color, but it will drop the file size in half.

3. There’s a special optimized image file format for iOS. Turns out the graphic chip in this iDevices has a format optimized for it – PVR – and it can be compressed. I’m using TexturePacker for my sprites and it will output a .pv.ccz file that should save memory and work better with the device’s graphic chips.