1

我是新手,试图集成一个 CCsprite 来跟随一层视差节点。它假设遵循 bg04 精灵。事实证明......,是的,它遵循,但在相反的方向。

这是代码,请帮忙,谢谢!

-(void) addParaBG
{


CCSprite* bg01 = [CCSprite spriteWithFile:@"Page001bg01.png"];
CCSprite* bg02 = [CCSprite spriteWithFile:@"Page001bg02.png"];
CCSprite* bg03 = [CCSprite spriteWithFile:@"Page001bg03.png"];
CCSprite* bg04 = [CCSprite spriteWithFile:@"Page001bg04.png"];

bg01.anchorPoint = CGPointMake(0, 0);
bg02.anchorPoint = CGPointMake(0, 0);
bg03.anchorPoint = CGPointMake(0, 0);
bg04.anchorPoint = CGPointMake(0, 0);

bg01.tag = 01;
bg02.tag = 02;
bg03.tag = 03;
bg04.tag = 04;

CCParallaxNode* paraBG = [CCParallaxNode node];
[paraBG addChild:bg01 z:1 parallaxRatio:CGPointMake(1, 0) positionOffset:CGPointMake(0, 0)];
[paraBG addChild:bg02 z:2 parallaxRatio:CGPointMake(2, 0) positionOffset:CGPointMake(0, 0)];
[paraBG addChild:bg03 z:3 parallaxRatio:CGPointMake(3, 0) positionOffset:CGPointMake(0, 0)];
[paraBG addChild:bg04 z:4 parallaxRatio:CGPointMake(4, 0) positionOffset:CGPointMake(0, 0)];

[self addChild:paraBG z:0 tag:paraBGtag];
}

-(void) moveParaBG
{
CCMoveBy* move1 = [CCMoveBy actionWithDuration:15 position:CGPointMake(-160, 0)];
CCMoveBy* move2 = [CCMoveBy actionWithDuration:15 position:CGPointMake(160, 0)];
CCSequence* sequence = [CCSequence actions:move1, move2, nil];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:sequence];

[[self getChildByTag:paraBGtag] runAction:repeat];
}

-(void) addAnimationElement
{
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CCSprite* testship = [CCSprite spriteWithFile:@"ship.png"];
testship.position = CGPointMake(screenSize.width /2, screenSize.height /2);
[self addChild:testship];

CCAnimation* anim = [CCAnimation animationWithFile:@"ship-anim" frameCount:5 delay:0.08f];
CCAnimate* animate = [CCAnimate actionWithAnimation:anim];
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:animate];

[testship runAction:repeat];
[testship runAction:[CCFollow actionWithTarget:[[self getChildByTag:paraBGtag] getChildByTag:04]]];

}
4

1 回答 1

0

您正在向后使用 CCFollow。背景层在精灵上运行跟随动作,而不是相反。

所以:

[testship runAction:[CCFollow actionWithTarget:[[self getChildByTag:paraBGtag] getChildByTag:04]]];

应改为:

CCSprite *bg = (CCSprite*)[[self getChildByTag:paraBGtag] getChildByTag:04]];
[bg runAction:[CCFollow actionWithTarget:testship]];
于 2013-04-16T17:36:58.273 回答