cocos2d anchor point 锚点解析
来源:互联网 发布:java搜索引擎框架 编辑:程序博客网 时间:2024/06/11 02:30
cocos2d anchor point 锚点解析
anchor point 究竟是怎么回事? 之所以造成不容易理解的是因为我们平时看待一个图片是 以图片的中心点 这一个维度来决定图片的位置的。而在cocos2d中决定一个 图片的位置是由两个维度 一个是 position 也就是图片的中心点 另外一个是anchor point。只要我们搞清楚他们的关系,自然就迎刃而解。
他们的关系是这样的:
actualPosition.x = position.x + width*(0.5 - anchor_point.x); acturalPosition.y = position.y + height*(0.5 - anchor_point.y)
actualPosition 是sprite实际上在屏幕显示的位置, poistion是 程序设置的, achor_point也是程序设置的。
具体看下面的例子一:
- CCSprite *sprite = [CCSprite spritewithFile:@"blackSquare.png"];
- sprite.position=ccp(0,0);
- sprite.anchorPoint=ccp(0,0);
- [self addChild:sprite];
具体效果如下:
根据上面的公式: 假设精灵的width = height = 10.
actualPosition.x = 0 + 10*(0.5 - 0) = 5; actualPosition.y = 0 + 10*(0.5 - 0) = 5;
(5, 5) 这个结果正是现在图片的在屏幕上的实际位置。
例子 二:
- CCSprite *sprite = [CCSprite spritewithFile:@"blackSquare.png"];
- sprite.position=ccp(0,0);
- sprite.anchorPoint=ccp(-1,-1);
- [self addChild:sprite];
具体效果如下:
根据上面的公式: 假设精灵的width = height = 10.
actualPosition.x = 0 + 10*(0.5 - (-1)) = 15; actualPosition.y = 0 + 10*(0.5 - (-1)) = 15;
(15, 15) 这个结果正是现在图片的在屏幕上的实际位置。
例子三
- CCSprite *sprite = [CCSprite spritewithFile:@"blackSquare.png"];
- sprite.anchorPoint=ccp(1,1);
- sprite.position=ccp(sprite.contentSize.width , sprite.contentSize.height);
- [self addChild:sprite];
根据上面的公式: 假设精灵的width = height = 10.
actualPosition.x = 10 + 10*(0.5 - (1)) = 5; actualPosition.y = 10 + 10*(0.5 - (1)) = 5;
(5, 5) 这个结果正是现在图片的在屏幕上的实际位置。
- cocos2d anchor point 锚点解析
- cocos2d anchor point 锚点解析
- cocos2d anchor point 锚点解析
- cocos2d anchor point 锚点解析(转)
- cocos2d anchor point 锚点解析(转)
- cocos2d-x anchor point 锚点解析
- cocos2d anchor point 锚点解析
- cocos2d anchor point 锚点解析
- cocos2d anchor point 锚点解析
- cocos2d anchor point 解析
- cocos2d--利用Anchor Point巧妙旋转
- Anchor Point
- OpenCV中的anchor的Point(-1,-1)解析
- GEF中的锚点Anchor
- cocos2d-x 3.2锚点,Point,addchild,getcontensize
- 我学cocos2d-x (一) 游戏基本概念:坐标系与Anchor Point
- 锚点的理解 J2me anchor
- 锚点的理解 J2me anchor
- 将传入的任意中文字符转换为拼音
- xmanager AIX连接失败
- Top 150 Questions - 1.1
- 组合数之递归算法
- POJ1364 差分约束系统
- cocos2d anchor point 锚点解析
- 横空出世,席卷互联网--评微软等公司数据结构+算法面试100题
- 数据挖掘算法之 kmeans
- iOS指南系列:如何解决奔溃问题-深入调试
- nginx源码那些事之----初认识
- 创建文本后,写入文本,报“正由另一进程使用,因此该进程无法访问该文件”
- 数据挖掘算法之 apriori
- Java核心技术 卷I 手记(一)
- Android培训班(99)内核解压过程12