开发者

How to Repeat (Continuse) TileMap in Cocos 2d?

开发者 https://www.devze.com 2023-03-26 06:57 出处:网络
I made a game using cocos 2d. I made a Tile based map, in which I want to repeat the map when it is complete.

I made a game using cocos 2d.

I made a Tile based map, in which I want to repeat the map when it is complete.

My problem is in the game, the map moves completely for the first time but I want to continues repeat it.

I am using the following code to move the map.

-(void) moveMap
{
    // Create the actions   
    id actionMove = [CCMoveTo actionWithDuration:10.0 position:ccp(-1,(-self.tileMap.contentSize.height))];
    id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(setViewpointCenter:)];
    [self.tileMap runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
}

This works properly and the map moves do开发者_StackOverflow中文版wnward till map height, after that the map will disappear. Now I want to continue repeating the map.


Separate your tile map into two smaller tile maps and put them one next to each other.

Then in your update method check their positions and when first one goes offscreen, move it after second one. When second one goes offscreen, move it after first one.


You can use a single map that's larger that the screen, then every 32px in any given direction, shift the map back 32px. This is useful for infinite maps. It requires one a single object and texture, plus is works both for vertical and horizontal motion. It can be a pain to time correctly, but so can the multiple map scenario.

(I upvoted fichek's answer because it's the most common.)

0

精彩评论

暂无评论...
验证码 换一张
取 消