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

  • 相关阅读:
    eclipse安装Genymotion插件
    [Eclipse插件] 安装和使用JD-Eclipse插件
    [Eclipse插件] Eclipse中如何安装和使用GrepCode插件
    [Android Studio] Android Studio如何删除module(转载)
    前端html基本标签
    python实现简单FTP
    文件的md5计算
    suprocess模块
    几个小例子
    configparser模块
  • 原文地址:https://www.cnblogs.com/rollrock/p/3587065.html
Copyright © 2011-2022 走看看