cocos2d - CCParallaxNode 例子

      CGSize winSize = [[CCDirector sharedDirector] winSize];

        

        CCParallaxNode * node = [CCParallaxNodenode];

        

        CCSprite * sp1 = [CCSprite spriteWithFile:@"bear1.png"];

        sp1.position = ccp( winSize.width/2,winSize.height/2);

        

        

        CCSprite * sp2 = [CCSprite spriteWithFile:@"bear2.png"];

        sp2.position = ccp( winSize.width/2,winSize.height/2 );

        

        

        CGPoint p1 = CGPointMake(1.0, 1.0);

        CGPoint p2 = CGPointMake(0.5, 0.5);

        

        [node addChild:sp1 z:0 parallaxRatio:p1 positionOffset:CGPointMake(winSize.width/2, winSize.height/2)];

        [node addChild:sp2 z:1 parallaxRatio:p2 positionOffset:CGPointMake(winSize.width/2, winSize.height/2)];

        

        [self addChild:node];

        

        id act1 = [CCMoveTo actionWithDuration:5 position:CGPointMake(winSize.width/2, 0)];

        id act2 = [CCMoveTo actionWithDuration:5 position:CGPointMake(0-winSize.width/2, 0)];

        

        CCSequence * seq = [CCSequence actions:act1,act2, nil];

        CCRepeatForever * rep = [CCRepeatForeveractionWithAction:seq];

        

        [node runAction:rep];

 

[node addChild:sp1 z:0 parallaxRatio:p1 positionOffset:CGPointMake(winSize.width/2, winSize.height/2)];  中的  positionOffset  是 sp1 相对于node的偏移

[CCMoveToactionWithDuration:position:CGPointMake(winSize.width/2, 0)];中的 position 是node的位移

posted on 2014-03-07 19:22  景树园  阅读(181)  评论(0编辑  收藏  举报

导航