cocos2d-x實現node圓弧運動 (附原始碼),cocos2d-xnode
紀錄下自己寫的東西!
標頭檔:
/*圓弧動作類*/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, const cocos2d::CCPoint& ptCenter, 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, 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 代碼
擷取觸摸點螢幕座標位置,然後轉換到OpenGL座標系的位置,也就是遊戲邏輯層的座標系。
各位cocos2d-x怎實現一個下拉式清單? 最好有代碼附上感激不盡
如果你是在手機上做的話不建議使用下拉式清單這種東西因為手機螢幕小下拉式清單表現不夠清晰,最好的解決方案是把下拉式清單的內容盡量放到全屏然後用捲軸的方式來實現。具體可以參考下面這篇文章:
codingnow.cn/cocos2d-x/1024.html