cocos2d-x 2.X demo学习笔记 7 ----RotateWorldTest CCScene全部旋转

#include "RotateWorldTest.h"
#include "../testResource.h"


//------------------------------------------------------------------
//
// TestLayer
//
//------------------------------------------------------------------
void TestLayer::onEnter()
{//布景1,有cocos2d-x字样
    CCLayer::onEnter();


    float x,y;
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    x = size.width;
    y = size.height;


    //CCMutableArray *array = [UIFont familyNames];
    //for( CCString *s in array )
    //    NSLog( s );
    CCLabelTTF* label = CCLabelTTF::create("cocos2d", "Tahoma", 64);


    label->setPosition( CCPointMake(x/2,y/2) );
    
    addChild(label);
}


//------------------------------------------------------------------
//
// SpriteLayer
//
//------------------------------------------------------------------
void SpriteLayer::onEnter()
{//角色布景
    CCLayer::onEnter();


    float x,y;
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    x = size.width;
    y = size.height;
    //创建3个角色
    CCSprite* sprite = CCSprite::create(s_pPathGrossini);
    CCSprite* spriteSister1 = CCSprite::create(s_pPathSister1);
    CCSprite* spriteSister2 = CCSprite::create(s_pPathSister2);
    //三个角色都放大
    sprite->setScale(1.5f);
    spriteSister1->setScale(1.5f);
    spriteSister2->setScale(1.5f);
    //设置三个角色的起始点
    sprite->setPosition(CCPointMake(x/2,y/2));
    spriteSister1->setPosition(CCPointMake(40,y/2));
    spriteSister2->setPosition(CCPointMake(x-40,y/2));

//旋转
    CCAction *rot = CCRotateBy::create(16, -3600);
//添加角色
    addChild(sprite);
    addChild(spriteSister1);
    addChild(spriteSister2);
    
    sprite->runAction(rot);

//跳跃到
    CCActionInterval *jump1 = CCJumpBy::create(4, CCPointMake(-400,0), 100, 4);
    CCActionInterval *jump2 = jump1->reverse();
    
    CCActionInterval *rot1 = CCRotateBy::create(4, 360*2);
    CCActionInterval *rot2 = rot1->reverse();
//执行连个动作
    spriteSister1->runAction(CCRepeat::create( CCSequence::create(jump2, jump1, NULL), 5 ));
    spriteSister2->runAction(CCRepeat::create( CCSequence::create((CCFiniteTimeAction *)(jump1->copy()->autorelease()), (CCFiniteTimeAction *)(jump2->copy()->autorelease()), NULL), 5 ));
    
    spriteSister1->runAction(CCRepeat::create( CCSequence::create(rot1, rot2, NULL), 5 ));
    spriteSister2->runAction(CCRepeat::create( CCSequence::create((CCFiniteTimeAction *)(rot2->copy()->autorelease()), (CCFiniteTimeAction *)(rot1->copy()->autorelease()), NULL), 5 ));
}


//------------------------------------------------------------------
//
// RotateWorldMainLayer
//
//------------------------------------------------------------------


void RotateWorldMainLayer::onEnter()
{
    CCLayer::onEnter();


    float x,y;
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    x = size.width;
    y = size.height;
    //创建4个块
    CCNode* blue =  CCLayerColor::create(ccc4(0,0,255,255));
    CCNode* red =   CCLayerColor::create(ccc4(255,0,0,255));
    CCNode* green = CCLayerColor::create(ccc4(0,255,0,255));
    CCNode* white = CCLayerColor::create(ccc4(255,255,255,255));


    blue->setScale(0.5f);

    blue->setPosition(CCPointMake(-x/4,-y/4));

//添加布局1

    blue->addChild( SpriteLayer::create() );
    
    red->setScale(0.5f);
    red->setPosition(CCPointMake(x/4,-y/4));


    green->setScale(0.5f);
    green->setPosition(CCPointMake(-x/4,y/4));
//添加布局2
    green->addChild(TestLayer::create());


    white->setScale(0.5f);
    white->setPosition(ccp(x/4,y/4));
    white->ignoreAnchorPointForPosition(false);
    white->setPosition(ccp(x/4*3,y/4*3));


    addChild(blue, -1);
    addChild(white);
    addChild(green);
    addChild(red);


    CCAction* rot = CCRotateBy::create(8, 720);
    //四个快资深旋转
    blue->runAction(rot);
    red->runAction((CCAction *)(rot->copy()->autorelease()));
    green->runAction((CCAction *)(rot->copy()->autorelease()) );
    white->runAction((CCAction *)(rot->copy()->autorelease()) );
}


void RotateWorldTestScene::runThisTest()
{
    CCLayer* pLayer = RotateWorldMainLayer::create();


    addChild(pLayer);

//整个CCScene旋转

    runAction( CCRotateBy::create(4, -360) );

//替换入场
    CCDirector::sharedDirector()->replaceScene(this);


}

你可能感兴趣的:(cocos2d-x 2.X demo学习笔记 7 ----RotateWorldTest CCScene全部旋转)