void MotionStreakTest1::onEnter(){ MotionStreakTest::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); // the root object just rotates around m_root = CCSprite::create(s_pPathR1); addChild(m_root, 1); m_root->setPosition(ccp(s.width/2, s.height/2)); // the target object is offset from root, and the streak is moved to follow it m_target = CCSprite::create(s_pPathR1); m_root->addChild(m_target); m_target->setPosition(ccp(s.width/4, 0)); // create the streak object and add it to the scene streak = CCMotionStreak::create(2, 3, 32, ccGREEN, s_streak); addChild(streak); // schedule an update on each frame so we can syncronize the streak with the target schedule(schedule_selector(MotionStreakTest1::onUpdate)); CCActionInterval* a1 = CCRotateBy::create(2, 360); CCAction* action1 = CCRepeatForever::create(a1); CCActionInterval* motion = CCMoveBy::create(2, ccp(100,0) ); m_root->runAction( CCRepeatForever::create((CCActionInterval*)(CCSequence::create(motion, motion->reverse(), NULL)) ) ); m_root->runAction( action1 );//最后的颜色会跟背景色一致,这样就达到逐渐消失的效果 CCActionInterval *colorAction = CCRepeatForever::create((CCActionInterval *)CCSequence::create( CCTintTo::create(0.2f, 255, 0, 0), CCTintTo::create(0.2f, 0, 255, 0), CCTintTo::create(0.2f, 0, 0, 255), CCTintTo::create(0.2f, 0, 255, 255), CCTintTo::create(0.2f, 255, 255, 0), CCTintTo::create(0.2f, 255, 0, 255), CCTintTo::create(0.2f, 255, 255, 255), NULL)); streak->runAction(colorAction);}void MotionStreakTest1::onUpdate(float delta){//先获取精灵m_target左上角的坐标,然后赋值给streak,m_target的坐标一直在变化 streak->setPosition( m_target->convertToWorldSpace(CCPointZero) );}