私は初心者で、ccsprite を統合して視差ノードの 1 つのレイヤーをたどろうとしています。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]]];
}