1

別のスプライトの上にスプライトを置きたいのですが、その上にあるスプライトにアニメーションを付けたいと思います。誰でも私に方法を提案できますか?私はこれを試しました

    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 だけにアニメーションを与えることはできますか?

4

1 に答える 1

1

これは、背景スプライトを seeker1 スプライトの子として追加したためです。

背景を前景レイヤーの子として追加するつもりだと思います。このようなもの:

[foreground addChild:background z:-1];
于 2012-09-14T12:45:55.087 に答える