Cocos2d-x to achieve node arc motion (with source code), cocos2d-xnode
Record what you write!
Header file:
/* ARC tracking class */class CCArcBy: public cocos2d: CCActionInterval {public: // initialize the arc tracking class // duration: duration of the sequence class // ptCenter: the center of the arc // deltaAngle: the variation of the radians. Positive and Negative values are used to indicate bool initWithDuration (float duration, const cocos2d: CCPoint & ptCenter, float deltaAngle) in a counterclockwise or clockwise direction ); 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, const cocos2d: CCPoint & ptCenter, float deltaAngle); protected: cocos2d: CCPoint m_startPosition; cocos2d:: CCPoint m_previousPosition; cocos2d: CCPoint m_ptCenter; float m_fAngleDelta ;};
Implementation file:
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, const CCPoint& ptCenter, 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 classpCopy = (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_ptCenter, -m_fAngleDelta);}void CCArcBy::update(float time){CCLog("%f", time);if(m_pTarget){#if CC_ENABLE_STACKABLE_ACTIONSCCPoint 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;#elsem_pTarget->setPosition(m_ptCenter + ccpRotateByAngle(m_startPosition-m_ptCenter, CCPointZero, m_fAngleDelta*time));#endif // CC_ENABLE_STACKABLE_ACTIONS}}
Cocos2d-x code
Obtain the screen Coordinate Position of the touch point and convert it to the OpenGL coordinate system, that is, the coordinate system of the game logic layer.
Cocos2d-x how to achieve a drop-down list? It is best to include code with gratitude
If you are using a mobile phone, we do not recommend that you use a drop-down list because the small drop-down list on the mobile phone screen is not clear enough, the best solution is to put the content of the drop-down list in full screen as much as possible and then use the scroll bar. For details, refer to the following article:
Codingnow.cn/cocos2d-x/1024.html