首先,我们新建一个ParabolaMoveAct.h和ParabolaMoveAct.cpp。
#ifndef __ParaBOLAMOVEACT_H__ #define __ParaBOLAMOVEACT_H__ #include "cocos2d.h" USING_NS_CC; class ParabolaMoveAct : public cocos2d::CCActionInterval { public: bool initWithDuration(const CCPoint& m_Now,float m_gx,float m_gy,float m_vx,float m_vy); virtual cocos2d::CCObject* copyWithZone(cocos2d::CCZone* pZone); virtual void startWithTarget(cocos2d::CCNode *pTarget); virtual void update(float time); public: static ParabolaMoveAct* create(const CCPoint& m_Now,float m_vy); protected: cocos2d::CCPoint m_Now; float m_gx; float m_gy; float m_vx; float m_vy; }; #endif // __HELLOWORLD_SCENE_H__ 然后是.cpp的代码 #include "ParabolaMoveAct.h" USING_NS_CC; ParabolaMoveAct* ParabolaMoveAct::create(const CCPoint& m_Now,float m_vy) { ParabolaMoveAct *pRet = new ParabolaMoveAct(); pRet->initWithDuration(m_Now,m_gx,m_gy,m_vx,m_vy); pRet->autorelease(); return pRet; } bool ParabolaMoveAct::initWithDuration(const CCPoint& m_Now,float m_vy) { if (CCActionInterval::initWithDuration(100)) { this->m_Now = m_Now; this->m_gx=m_gx; this->m_gy=m_gy; this->m_vx=m_vx; this->m_vy=m_vy; return true; } return false; } CCObject* ParabolaMoveAct::copyWithZone(CCZone *pZone) { CCZone* pNewZone = NULL; ParabolaMoveAct* pcopy = NULL; if(pZone && pZone->m_pcopyObject) { pcopy = (ParabolaMoveAct*)(pZone->m_pcopyObject); } else { pcopy = new ParabolaMoveAct(); pZone = pNewZone = new CCZone(pcopy); } CCActionInterval::copyWithZone(pZone); pcopy->initWithDuration(m_Now,m_vy); CC_SAFE_DELETE(pNewZone); return pcopy; } void ParabolaMoveAct::startWithTarget(CCNode *pTarget) { CCActionInterval::startWithTarget(pTarget); m_Now = pTarget->getPosition(); } void ParabolaMoveAct::update(float time) { /* m_frameCnts++; m_currScale += m_scaleDiff; CCPoint newPos = ccpRotateByAngle(m_initPos,m_center,m_frameCnts * m_anglePreFrame); CCPoint diff = ccpsub(newPos,m_center); newPos = diff * m_currScale + m_center; m_pTarget->setPosition(newPos);*/ this->m_vx+=this->m_gx; this->m_vy+=this->m_gy; m_Now.x+=this->m_vx; m_Now.y+=this->m_vy; m_pTarget->setPosition(m_Now); } 调用方式和cocos2dx里面的其他action相同