zoukankan      html  css  js  c++  java
  • cocos2d

          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的位移

  • 相关阅读:
    ubuntu系统安装微信小程序开发工具
    【工具】vscode-代码编辑器详解
    微信小程序开发
    webpack基本配置
    vue相关知识
    史上最强vue总结~万字长文---面试开发全靠它了
    ES6——字符串
    ES6——Proxy与Reflect
    ES6——Map与Set
    ES6——Symbol
  • 原文地址:https://www.cnblogs.com/rollrock/p/3587065.html
Copyright © 2011-2022 走看看