Cocos2D Endless Background Image

I am curious how to create an endless background in cocos2d. For example, let's say I created an application with a person working from left to right, and I want it to run endlessly. In this case, I would have to have an endless background so that the person could continue to work. I was constantly looking for this question and did not find anything that really works.

Any suggestions, answers and tips are greatly appreciated.

thanks

+4
source share
4 answers

Try the following:

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define MM_BG_SPEED_DUR ( IS_IPAD ? (6.0f) : (2.0f) ) -(void)onEnter { [super onEnter]; [self initBackground]; [self schedule: @selector(tick:)]; } -(void)initBackground { NSString *tex = @"BG/Background.png";//[self getThemeBG]; mBG1 = [CCSprite spriteWithFile:tex]; mBG1.position = ccp(s.width*0.5f,s.height*0.5f); [self addChild:mBG1 z:LAYER_BACKGROUND]; mBG2 = [CCSprite spriteWithFile:tex]; mBG2.position = ccp(s.width+s.width*0.5f,s.height*0.5f); mBG2.flipX = true; [self addChild:mBG2 z:LAYER_BACKGROUND]; } -(void)scrollBackground:(ccTime)dt { CGSize s = [[CCDirector sharedDirector] winSize]; CGPoint pos1 = mBG1.position; CGPoint pos2 = mBG2.position; pos1.x -= MM_BG_SPEED_DUR; pos2.x -= MM_BG_SPEED_DUR; if(pos1.x <=-(s.width*0.5f) ) { pos1.x = pos2.x + s.width; } if(pos2.x <=-(s.width*0.5f) ) { pos2.x = pos1.x + s.width; } mBG1.position = pos1; mBG2.position = pos2; } -(void)tick:(ccTime)dt { [self scrollBackground:dt]; } 
+5
source

The easiest way is to include two background images that are easily combined. (CCSprite will do just fine with this). In your update method, as soon as the first background is completely disconnected from the screen, move it back to the other side of the screen directly next to the second background and constantly move both background images. Repeat this process for the second background.

+2
source

CCTMXTiledMap may help you, but I'm afraid that you should process the end of the map and add another manually. Check out this guide on how to use tile cards in side scrolling games, hope this will be useful to you:

http://www.raywenderlich.com/15230/how-to-make-a-platform-game-like-super-mario-brothers-part-1

+1
source

Try this . It is very easy to implement and works well. Just follow the reading instructions.

0
source

All Articles