Skip to content

Instantly share code, notes, and snippets.

@kernel1983
Created October 26, 2010 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kernel1983/646532 to your computer and use it in GitHub Desktop.
Save kernel1983/646532 to your computer and use it in GitHub Desktop.
create looping background in cocos2D
-(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