纪录下自己写的东西!
头文件:
/*圆弧动作类*/class CCArcBy : public cocos2d::CCActionInterval{public: //初始化圆弧动作类 //duration: 动作类的持续时间 //ptCenter: 圆弧的中心点 //deltaAngle: 弧度的变化量,用正负来表示逆时针或顺时针方向 bool initWithDuration(float duration,const cocos2d::CCPoint& ptCenter,float deltaAngle); virtual CCObject* copyWithZone(cocos2d::CCZone* pZone); virtual voID startWithTarget(cocos2d::CCNode *pTarget); virtual CCActionInterval* reverse(voID); virtual voID update(float time);public: static CCArcBy* create(float duration,float deltaAngle);protected: cocos2d::CCPoint m_startposition; cocos2d::CCPoint m_prevIoUsposition; cocos2d::CCPoint m_ptCenter; float m_fAngleDelta;};
实现文件:
CCArcBy* CCArcBy::create(float duration,const CCPoint& ptCenter,float deltaAngle){ CCArcBy* pRet= new CCArcBy(); pRet->initWithDuration(duration,ptCenter,deltaAngle); pRet->autorelease(); return pRet;}bool CCArcBy::initWithDuration(float duration,float deltaAngle){ if(CCActionInterval::initWithDuration(duration)) { m_ptCenter= ptCenter; m_fAngleDelta= deltaAngle; return true; } return false;}CCObject* CCArcBy::copyWithZone(CCZone* pZone){ CCZone* pNewZone = NulL; CCArcBy* pcopy = NulL; if(pZone && pZone->m_pcopyObject) { //in case of being called at sub class pcopy = (CCArcBy*)(pZone->m_pcopyObject); } else { pcopy = new CCArcBy(); pZone = pNewZone = new CCZone(pcopy); } CCActionInterval::copyWithZone(pZone); pcopy->initWithDuration(m_fDuration,m_ptCenter,m_fAngleDelta); CC_SAFE_DELETE(pNewZone); return pcopy;}voID CCArcBy::startWithTarget(CCNode *pTarget){ CCActionInterval::startWithTarget(pTarget); m_prevIoUsposition = m_startposition = pTarget->getposition();}CCActionInterval* CCArcBy::reverse(){ return CCArcBy::create(m_fDuration,-m_fAngleDelta);}voID CCArcBy::update(float time){ cclog("%f",time); if(m_pTarget) {#if CC_ENABLE_STACKABLE_ACTIONS CCPoint currentPos = m_pTarget->getposition(); CCPoint diff = ccpsub(currentPos,m_prevIoUsposition); m_startposition = ccpAdd( m_startposition,diff); CCPoint newPos = m_ptCenter + ccpRotateByAngle(m_startposition-m_ptCenter,CCPointZero,m_fAngleDelta*time); m_pTarget->setposition(newPos); m_pTarget->setRotation(-CC_radians_TO_degrees(m_fAngleDelta*time)); m_prevIoUsposition = newPos;#else m_pTarget->setposition(m_ptCenter + ccpRotateByAngle(m_startposition-m_ptCenter,m_fAngleDelta*time));#endif // CC_ENABLE_STACKABLE_ACTIONS }}总结
以上是内存溢出为你收集整理的cocos2d-x实现node圆弧运动 (附源代码)全部内容,希望文章能够帮你解决cocos2d-x实现node圆弧运动 (附源代码)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)