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  阅读(734)  评论(0)    收藏  举报
编辑推荐:
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· MySQL索引完全指南:让你的查询速度飞起来
· 一个字符串替换引发的性能血案:正则回溯与救赎之路
· 为什么说方法的参数最好不要超过4个?
· C#.Net 筑基-优雅 LINQ 的查询艺术
阅读排行:
· 我用这13个工具,让开发效率提升了5倍!
· 一次 .NET 性能优化之旅:将 GC 压力降低 99%
· Coze工作流实战:一键生成鸡汤视频——厉害的人,早已戒掉情绪
· 32岁入行STM32迟吗?
· C++服务开发环境-万事开头难
点击右上角即可分享
微信分享提示