Revision: 45550
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 4, 2011 00:16 by espinallab
Initial Code
//Create our scrolling background
- (void)setupBackgroundImage
{
//create both sprite to handle background
background1 = [CCSprite spriteWithFile:@"cloud_bg1.png"];
background2 = [CCSprite spriteWithFile:@"cloud_bg2.png"];
background1.position = ccp(0, size.height/2);
background2.position = ccp(size.width, size.height/2);
//add them to main layer
[self addChild:background1 z:0];
[self addChild:background2 z:0];
//add schedule to move backgrounds
[self schedule:@selector(scroll:)];
}
- (void)scroll:(ccTime)dt {
background1.position = ccp( background1.position.x - 2, background1.position.y );
background2.position = ccp( background2.position.x - 2, background2.position.y );
//reset position when they are off from view.
if (background1.position.x == - (size.width/2)) {
background1.position = ccp(size.width+(size.width/2), size.height/2);
}
else if (background2.position.x == - (size.width/2)) {
background2.position = ccp(size.width+(size.width/2), size.height/2);
}
}
Initial URL
Initial Description
Initial Title
Cocos2d Scrolling Background
Initial Tags
Initial Language
Objective C