Posts Tagged 'Cocos2d'

Errors when creating Large TileMaps with Cocos2D

Image

Lately I’ve been building a lot of tilemap based games in Cocos2D and I’ve got to say, it’s pretty freaking sweet. There’s a lot of great tutorials on how to get started, plenty of help in the Cocos2D forums, and even a few videos people have put together. I did run into an issue today that I felt others may run into, so I wanted to post the solution.

I have a few levels in my game which require more than one TileMap. I ended up using two tile maps in 1 layer and I got the following compiler error:

 

*** Assertion failure in -[CCTMXLayer setupTiles]

This error is actually masking an error, and it took about 10 minutes for me to track down the actual problem. You can not use more than 1 TileMap per Layer. If you’re using TileD you just need to create a new layer and use your 2nd TileMap on it. All will be well. If you’re not using TileD then you are missing out because it’s a seriously awesome tool.

 

Cocos2d retina support

Cocos2d is probably the most used and least documented framework out there. I’m used to docs being out-dated (doc is the most important and least maintained part of a framework) but Cocos2d gets to be my biggest loser on this scale. All that criticism aside, once you finally figure out how things are supposed to work it’s actually really nice.

If you’re familiar with the xCode you’re probably familiar with Apple using the @2x suffix on the end of their files when they need something larger than the original iPhone display resolution.  To date this is what Apple’s doing:

default.png – iPhone 3GS and older resolution
default.png@2x -Retina 3.5 inch
default-568h@2x.png – Retina 4 inch (iPhone 5 nonsense… seriously Apple?)

Cocos2d takes a similar approach:

default.png – iPhone 3GS
default-ipad.png – iPad 1 and 2 resolution
default-ipadhd.png – Retina resolutions (I don’t think they’ve got a Retina 4 inch file type as of yet.. but then again, how could I possibly know?)

This short story is you should only specify default.png as the file you’re trying to load as a Sprite. Cocos2d will automatically look to see if you have that file with the -ipad or -ipadhd extension, and load that if appropriate. (That’s all determined if you’ve got retina display enabled. Here’s some pseudo code for that:


if( ! [director_ enableRetinaDisplay:YES] )
CCLOG(@"Retina Display Not Supported");

Hope that helps!