2012-09-14 59 views
1

我想在另一個精靈上有一個精靈,並且想給頂部的精靈提供動畫。任何人都可以給我一種方法嗎?我試過這個如何將sprite添加到cocos 2d中的另一個sprite中?

CCLayer *foreground = [CCLayer node]; 
    CCSprite* background = [CCSprite spriteWithFile:@"background.png" ]; 
    background.position = ccp(150, -120); 

    seeker1 = [CCSprite spriteWithFile: @"wave.png"]; 
    seeker1.position = ccp(180, 420); 
    [seeker1 addChild:background z:-1]; 

    [foreground addChild:seeker1]; 

    [self addChild:foreground z:1]; 


    id waves = [CCWaves actionWithWaves:5 amplitude:15 horizontal:YES vertical:YES grid:ccg(15,10) duration:5]; 
    id a1 = [CCMoveBy actionWithDuration:3 position:ccp(0,-200)]; 

    id action2 = 
    [CCSequence actions: [[a1 copy] autorelease], [a1 reverse], nil]; 

    id action = [CCSpawn actions: 
       action2, 
       waves, 
       nil]; 
    [seeker1 runAction:action]; 

但是,當我運行程序時,它給出了整個圖層的動畫。任何人只能爲seeker1提供動畫嗎?

回答

1

那是因爲你已經添加了背景精靈作爲seeker1精靈的子元素。

我假設你打算將背景添加爲前景層的子元素。類似這樣的:

[foreground addChild:background z:-1]; 
相關問題