2012-08-10 61 views
2

嗨,我正在创建一个iphone游戏在objective-c iphone游戏中一个接一个地放两个背景?

在我的游戏层,我有两个相同的背景图像,但我希望他们一个接一个走。

一旦游戏动物(例如企鹅)穿过第一个背景,我希望第一个背景在第二个背景之后 - 在游戏结束之前成为连续背景。

我已经试过各种--- for循环,while循环等,但似乎没有任何工作

没有人有我怎么会去这样做的想法?

非常感谢您给我提供的任何帮助。

,这是所有我有很多不同的尝试后至今

- (id) init 
{ 
    if((self = [super init])) 
    { 
     for (int x = 0; x < 10000000; ++x) 
     { 
      CCSprite *bg = [CCSprite spriteWithFile:@"level1.png"]; 
      [bg setPosition:ccp(160,240)]; 
      ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; 
      [bg.texture setTexParameters:&params]; 
      [self addChild:bg z:0]; 

      CCSprite *bg2 = [CCSprite spriteWithFile:@"level1.png"]; 
      [bg2 setPosition:ccp(320,480)]; 
      ccTexParams param = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT}; 
      [bg2.texture setTexParameters:&param]; 
      [self addChild:bg z:0]; 
     } 

回答

0

如果背景是,你实际上并不需要2个图像相同,你可以设置一个,它的质地RECT位置将不断移动。如果您在定时器或更新方法上调用moveBackground,它将不断滚动。

-(void)init 
{ 
    if((self=[super init])) 
    { 
     background = [CCSprite spriteWithFile:@"background.png"]; 
     ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT}; 
     [background.texture setTexParameters:&params]; 
     [self addChild:background z:0]; 
    } 
} 

-(void)moveBackground 
{ 
    // Scroll background 5 pixels to the left 
    int speed = 5; 
    background.textureRect = CGRectMake(background.textureRect.origin.x-speed, 
             background.textureRect.origin.y, 
             background.textureRect.size.width, 
             background.textureRect.size.height); 
} 
+0

非常感谢! :) – Surz 2012-08-10 22:10:14

+0

没问题。如果这解决了你的问题,你可以好好地标记我的答案是正确的; D – ezekielDFM 2012-08-11 02:04:58

+0

显然要求“15声望”的投票? 我是新来的。 – Surz 2012-08-12 03:06:16