2013-08-19 27 views
2

我的問題是:我需要不斷從右向左移動我的精靈位置(方向是風景) 我已經搜索並找到了Ray的教程(感謝他) ,但圖像似乎不會連續滾動我的代碼是如何從右到左連續移動一個Sprite(視差)?

-(id) init 
{ 
// always call "super" init 
    if((self=[super init])) { 

     CGSize screenSize = [CCDirector sharedDirector].winSize; 

     // 1) Create the CCParallaxNode 
     backgroundNode = [CCParallaxNode node]; 
     [self addChild:backgroundNode z:-1]; 

     // 2) Create the sprites we'll add to the CCParallaxNode 
     Back = [CCSprite spriteWithFile:@"bg_front_spacedust.png"]; 
     Back.rotation = -90; 
     Back1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"]; 
     Back1.rotation = -90; 

     // 3) Determine relative movement speeds for space dust and background 
     CGPoint dustSpeed = ccp(0.1, 0.1); 

     // 4) Add children to CCParallaxNode 
     [backgroundNode addChild:Back z:0 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width/2, screenSize.height/2)]; 
     [backgroundNode addChild:Back1 z:1 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width,0)]; 

     // 5) Enable updates 
     [self scheduleUpdate]; 
} 
    return self; 
} 

- (void)update:(ccTime)dt { 

    // 1) Update background position 
    CGPoint backgroundScrollVel = ccp(0,-1000); 
    backgroundNode.position = ccpAdd(backgroundNode.position, ccpMult(backgroundScrollVel, dt)); 

    // 2) Check for background elements moving offscreen 
    NSArray *spaceDusts = [NSArray arrayWithObjects:Back, Back1, nil]; 
    for (CCSprite *spaceDust in spaceDusts) { 
     if ([backgroundNode convertToWorldSpace:spaceDust.position].x < -spaceDust.contentSize.width) { 
      [backgroundNode incrementOffset:ccp(2*spaceDust.contentSize.width,0) forChild:spaceDust]; 
     } 
    } 
} 

的圖像大小爲1024×320
任何人可以指導我在這個問題上
由於事先

回答

0

讓我們嘗試吧..

CCSprite *bird = [CCSprite spriteWithFile:@"bird.png"]; 
     bird.position = ccp(100,80); 
     [map addChild:bird]; 


     id move = [CCMoveTo actionWithDuration:4.2 position:ccp(400, 80)]; 
     id move1 = [CCMoveTo actionWithDuration:4.2 position:ccp(200, 80)]; 
     [bird runAction:[CCRepeatForever actionWithAction:[CCSequence actions:move,move1, nil]]]; 
相關問題