这两天看了下锚点的概念。

/**

* Sets the anchor point in percent.

*

* anchorPoint is the point around which all transformations and positioning manipulations take place.

* It's like a pin in the node where it is "attached" to its parent.

* The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner.

* But you can use values higher than (1,1) and lower than (0,0) too.

* The default anchorPoint is (0.5,0.5), so it starts in the center of the node.

*

* @param anchorPoint   The anchor point of node.

*/

virtual void setAnchorPoint(const CCPoint& anchorPoint);

anchorPoint is the point around which all transformations and positioning manipulations take place.

是为了在定位位置和翻转的时候用的参考点。

CCSprite* sprite5 = CCSprite::create("CloseNormal.png");

sprite5->setAnchorPoint( ccp(0.5,0.5) );

sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite5);

此时 (ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2)) 点正在sprite5的中心点( ccp(0.5,0.5))

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();

CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

// 右上角

CCSprite* sprite1 = CCSprite::create("CloseSelected1.png");

sprite1->setAnchorPoint( ccp(0,0) );

sprite1->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite1);

// 左上角

CCSprite* sprite2 = CCSprite::create("CloseNormal.png");

sprite2->setAnchorPoint( ccp(1,0) );

sprite2->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite2);

// 左下角

CCSprite* sprite3 = CCSprite::create("CloseNormal.png");

sprite3->setAnchorPoint( ccp(1,1) );

sprite3->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite3);

// 右下角

CCSprite* sprite4 = CCSprite::create("CloseNormal.png");

sprite4->setAnchorPoint( ccp(0,1) );

sprite4->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite4);

// 中间

CCSprite* sprite5 = CCSprite::create("CloseNormal.png");

sprite5->setAnchorPoint( ccp(0.5,0.5) );

sprite5->setPosition(ccp(origin.x+visibleSize.width/2, origin.y+visibleSize.height/2));

this->addChild(sprite5);

cocos2d中锚点概念的更多相关文章

  1. Cocos2D中节点Z序的计算规则

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交 ...

  2. Cocos2D中Action的进阶使用技巧(一)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 大家对Cocos2d中动作的使用大概都很清楚了,其实本身act ...

  3. cocos2d中的坐标系统

    cocos2d中Layer的默认锚点是left.buttom sprite的锚点设置 setAnchorPoint(cc.p(0.5,0.5)); 默认锚点:中心 setAnchorPoint(cc. ...

  4. WebLogic 中的基本概念

    完全引用自: WebLogic 中的基本概念 WebLogic 中的基本概念 上周参加了单位组织的WebLogic培训,为了便于自己记忆,培训后,整理梳理了一些WebLogic的资料,会陆续的发出来, ...

  5. cocos2d中的可见性检测

    游戏的在进行一次渲染的时候,通常会提交大量的渲染对象给gpu.在这些需要渲染的对象中,并不是所有对象都会出现镜头中,即有一部分对象是不可见的. 通常有两种方式来完成不可见对象的剔除工作: (1)直接交 ...

  6. Web开发中的主要概念

    一.Web开发中的主要概念1.静态资源:一成不变的.html.js.css2.动态资源:JavaWeb.输出或产生静态资源.(用户用浏览器看到的页面永远都是静态资源) 3.JavaEE:十三种技术的集 ...

  7. Cocos2d 中的Sprite大小调整问题

    以前用UIImageView,比如  UIImageView *view = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"b ...

  8. cocos2d 中判断CGPoint或者CGSize是否相等

    cocos2d 中判断CGPoint是否相等 调用CGPointEqualToPoint(point1, point2) 判断CGSize是否相等 调用CGSizeEqualToSize(size1, ...

  9. 理解SQL Server中索引的概念

    T-SQL查询进阶--理解SQL Server中索引的概念,原理以及其他   简介 在SQL Server中,索引是一种增强式的存在,这意味着,即使没有索引,SQL Server仍然可以实现应有的功能 ...

随机推荐

  1. MyEcplise的注册代码

    代码分析 package test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputSt ...

  2. python csv写入数据,消除空行

    import csv rowlist=[{'first_name': 'mark', 'last_name': 'zhao','age':21}, {'first_name': 'tony', 'la ...

  3. What Is a Computer System?

    What Is a Computer System? A combination of Five or Six Elements The term computer is used to descri ...

  4. stl sort使用不当造成崩溃

    #include <iostream>#include <vector>#include <algorithm>using namespace std; bool ...

  5. is和as在类型转换时的性能差异

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/xxdddail/article/details/36655219 is和as是.NET中经常使用的操 ...

  6. 在thinkphp5.0中调用ajax时, 返回的JSON 格式数据在html前台不能用时

    在thinkphp5.0中调用ajax时,如果控制器返回的数据为json格式,视图层接收到返回值即为json格式的数据,此时应该把 JSON 文本转换为 JavaScript 对象,方便调用.具体代码 ...

  7. 【转】java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener

    http://www.cnblogs.com/softidea/p/6064091.html Caused by: java.lang.NoClassDefFoundError: org/spring ...

  8. GetSystemMetrics()函数的用法 转

    转自 http://www.cnblogs.com/lidabo/archive/2012/07/10/2584725.html 可以用GetSystemMetrics函数可以获取系统分辨率,但这只是 ...

  9. 使用Storyboard拖线容易出错的地方

    使用Storyboard拖线容易出错的地方: 在Storyboard中,选中某个控件,按住ctrl键进行拖线,建立Outlet和Action后,不能手动再去修改自动生成的代码,然后再次进行连线,这样会 ...

  10. 课时10.第一个HTML网页(掌握)

    网页的固定格式 编写网页和写信一样都有一套规范和要求,这套规范和要求中规定了写信的固定格式 写信基本结构 亲爱的xx: 你好! 我.................. ...... 此致 敬礼! xx ...