Test5::Test5()
{
CCSprite* sp1 = CCSprite::create(s_pPathSister1);
CCSprite* sp2 = CCSprite::create(s_pPathSister2); sp1->setPosition(ccp(,));
sp2->setPosition(ccp(,)); CCRotateBy* rot = CCRotateBy::create(, );
CCActionInterval* rot_back = rot->reverse();
CCAction* forever = CCRepeatForever::create(
(CCActionInterval*)(CCSequence::create(rot, rot_back, NULL))
);
CCAction* forever2 = (CCAction*)(forever->copy()->autorelease());
forever->setTag();
forever2->setTag(); addChild(sp1, , kTagSprite1);
addChild(sp2, , kTagSprite2); sp1->runAction(forever);
sp2->runAction(forever2); schedule( schedule_selector(Test5::addAndRemove), 2.0f);
} void Test5::addAndRemove(float dt)
{
CCNode* sp1 = getChildByTag(kTagSprite1);
CCNode* sp2 = getChildByTag(kTagSprite2);
//这里需要对计数加一,否则removeChild的时候会被释放掉
sp1->retain();
sp2->retain();
//false是表示不删除该节点的动作,true表示删除
removeChild(sp1, false);
removeChild(sp2, true);
//重新加载到层中
addChild(sp1, , kTagSprite1);
addChild(sp2, , kTagSprite2); sp1->release();
sp2->release();
}
05-11 18:25