首页 > 其他 > 详细

cocos2dX改变锚点位置

时间:2014-11-27 21:55:55      阅读:320      评论:0      收藏:0      [点我收藏+]

改变锚点时,同过计算偏移量修正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为新锚点的位置

cocos2dX改变锚点位置

原文:http://www.cnblogs.com/codingdiary/p/4127076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!