2012-08-10 59 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