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为新锚点的位置

posted @ 2014-11-27 20:04  Reise  阅读(707)  评论(0编辑  收藏  举报