cocos2dX改变锚点位置
生活随笔
收集整理的這篇文章主要介紹了
cocos2dX改变锚点位置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
改變錨點時,同過計算偏移量修正position從而保持CCNode在屏幕上的位置不變
?
1 void CLayer::change_anchorpoint(CCNode* node,CCPoint newpt) 2 { 3 float dx, dy, diffx, diffy, height, width; 4 width = node->getContentSize().width; 5 height = node->getContentSize().height; 6 7 diffx = (newpt.x - node->getAnchorPoint().x)*width; 8 diffy = (newpt.y - node->getAnchorPoint().y)*height; 9 node->setPositionX(node->getPositionX() + diffx); 10 node->setPositionY(node->getPositionY() + diffy); 11 node->setAnchorPoint(newpt); 12 }newpt為新錨點的位置
轉載于:https://www.cnblogs.com/codingdiary/p/4127076.html
總結
以上是生活随笔為你收集整理的cocos2dX改变锚点位置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转】PCA算法学习_1(OpenCV中
- 下一篇: 成绩转换