Writing a Book About Writing an iPhone Game, Day One

Guess this book ain’t just gonna write itself, so I took one heavy first step and got a tiled background to load on the iPhone simulator using cocos2d’s TMXTiledMap class and a sweet map editor program called Tiled.

Screenshot, Day 1

Here’s a bit of the code to load the tilemap file and move the map to the center of the screen:

ColorLayer *color = [ColorLayer layerWithColor:ccc4(64,64,64,255)];
[self addChild:color z:-1];

TMXTiledMap *map = [TMXTiledMap tiledMapWithTMXFile:@"myfirsttile.tmx"];
[self addChild:map z:0 tag:kTagTileMap];

// move map to the center of the screen
CGSize ms = [map mapSize];
CGSize ts = [map tileSize];
[map runAction:[MoveTo actionWithDuration:1.0f position:ccp( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ]];

Leave a Reply

Spam protection by WP Captcha-Free

Storyteller   .:.   Musician   .:.   Vagabond   .:.   Wizard