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(); }