Reputation: 141
ok so im trying to find some tutorials on how to create a moving background for a box2d game. it my first time doing it, and i dont know what they are called? can anyone tell me what they are called so i can search for some tutorials on it..
heres what im trying to do.. firstly my game is in portrait mode, and i have created an image which is 960x320 and i want it to continually run as the background of the game.... like a road which goes on forever..
can someone tell me what i can search on google to find a good tutorial for accomplish this? thankyou
Upvotes: 0
Views: 647
Reputation: 1097
You can get the tutorial of the CCParallaxScrollNode by which you can do the endless scrolling of the Background. I dont know the exact link but you need to download the 4 files they are
Now in your test demo implement the below code
in your .h file code is
CCParallaxScrollNode *parlax;
CCParallaxNode* paraNode;
in .mm file you need to declare before @implementation set
float myVelocity = -4;
the below code in init method
CCSprite *clouds1 = [CCSprite spriteWithFile:@"Default.png"];
CCSprite *clouds2 = [CCSprite spriteWithFile:@"Default.png"];
parlax= [CCParallaxScrollNode node];
[parlax addInfiniteScrollYWithZ:0 Ratio:ccp(0.5,0.5) Pos:ccp(0,0) Objects:clouds1,clouds2,nil];
[self addChild:parlax z:-1];
[self scheduleUpdate];
-(void) update : (ccTime) dt
{
[parlax updateWithVelocity:ccp(0,myVelocity) AndDelta:dt];
}
The sprites can be replaced with your own sprites also you can do some modification for the Landscape also. The code is for the portrait mode
Upvotes: 3
Reputation: 2635
One of my favourite sites for cocos2D tutorials is Ray Wenderlich. You'll find loads of cocos2d material there.
Upvotes: 1