views:

266

answers:

1

I want to create a CCLayer with an animated tiled background from a larger texture atlas with Cocos2d.

I know how to drop a background in a CCLayer. I know how to create an animated CCSprite. I even know how to handle tiled world maps. But I can't find a proper way to combine all these elements in the desired form.

How would I do this?


Example case: Let's say I have a 512x512 texture atlas. On it are six frames drawn next to each other, all of them 32x32, starting from the top left (0.0).

Now I would like my CCLayer's background to display a tiled image consisting of 10 by 15 tiles. Plus, the tiles themselves should animate with the six frames from the texture atlas.

As a bonus, the animation itself should be controllable. (I want to be able to speed it up, slow it down or reverse it)

A: 

You should be able to get the sprite from the tile map

CCTMXLayer *layer = [map layerNamed:@"Layer"];
CCSprite *tile = [layer tileAt:ccp(x, y)];

and run a CCAnimation action on it.

Frank Mitchell
It helped. Thanks. :)
Kriem