zoukankan      html  css  js  c++  java
  • cocos2d-x 父节点和子节点执行不同动作

    Test6::Test6()
    {
        CCSprite* sp1 = CCSprite::create(s_pPathSister1);
        CCSprite* sp11 = CCSprite::create(s_pPathSister1);
    
        CCSprite* sp2 = CCSprite::create(s_pPathSister2);
        CCSprite* sp21 = CCSprite::create(s_pPathSister2);
            
        sp1->setPosition(ccp(100,160));
        sp2->setPosition(ccp(380,160));
            
        CCActionInterval* rot = CCRotateBy::create(2, 360);
        CCActionInterval* rot_back = rot->reverse();
        CCAction* forever1 = CCRepeatForever::create(
                                                                (CCActionInterval*)(CCSequence::create(rot, rot_back, NULL)));
        CCAction* forever11 =  (CCAction*)(forever1->copy()->autorelease());
    
        CCAction* forever2 =  (CCAction*)(forever1->copy()->autorelease());
        CCAction* forever21 =  (CCAction*)(forever1->copy()->autorelease());
        
        addChild(sp1, 0, kTagSprite1);
        sp1->addChild(sp11);
        addChild(sp2, 0, kTagSprite2);
        sp2->addChild(sp21);
        //父节点和子节点都执行动作
        sp1->runAction(forever1);
        sp11->runAction(forever11);
        sp2->runAction(forever2);
        sp21->runAction(forever21);
        
        schedule( schedule_selector(Test6::addAndRemove), 2.0f);
    }
    
    void Test6::addAndRemove(float dt)
    {
        CCNode* sp1 = getChildByTag(kTagSprite1);
        CCNode* sp2 = getChildByTag(kTagSprite2);
    
        sp1->retain();
        sp2->retain();
        
        removeChild(sp1, false);
        removeChild(sp2, true);
        
        addChild(sp1, 0, kTagSprite1);
        addChild(sp2, 0, kTagSprite2);
        
        sp1->release();
        sp2->release();
    
    }
  • 相关阅读:
    计算机网络复习(二) 应用层
    JavaScript实战笔记(二) 数组去重
    计算机网络复习(一) 基本介绍
    计算机网络复习
    Git学习笔记(一) 常用命令
    Git学习笔记
    Python实战笔记(三) 多线程
    Python实战笔记(二) 网络编程
    Python学习笔记
    XBox360自制系统的更新(Update)
  • 原文地址:https://www.cnblogs.com/newlist/p/3218924.html
Copyright © 2011-2022 走看看