Created
October 26, 2010 08:24
-
-
Save kernel1983/646532 to your computer and use it in GitHub Desktop.
create looping background in cocos2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(id) init | |
{ | |
if( (self=[super init] )) { | |
CGSize size = [[CCDirector sharedDirector] winSize]; | |
CCTexture2D *bg = [[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"Default.png"]]; | |
CCSprite *staticBackground0 = [CCSprite spriteWithTexture:bg]; | |
staticBackground0.position = ccp(-size.width/2,size.height/2); | |
CCSprite *staticBackground1 = [CCSprite spriteWithTexture:bg]; | |
staticBackground1.position = ccp(size.width/2,size.height/2); | |
CCSprite *staticBackground = [[CCSprite alloc] init]; | |
[staticBackground addChild:staticBackground0]; | |
[staticBackground addChild:staticBackground1]; | |
[self addChild:staticBackground]; | |
id a1 = [CCMoveBy actionWithDuration:3.0f position:ccp(size.width,0)]; | |
id a2 = [CCPlace actionWithPosition:ccp(0,0)]; | |
id seq = [CCSequence actions:a1,a2, nil]; | |
[staticBackground runAction:[CCRepeatForever actionWithAction: seq]]; | |
} | |
return self; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment