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

/**

* 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. [EffectiveC++]item36:绝不重新定义继承而来的non-virtual函数

  2. SAP Cloud for Customer销售订单External Note的建模细节

    SAP Cloud for Customer的销售订单创建页面里,我们可以给一个订单维护External Note,当这个订单同步到S/4HANA生成对应的生产订单后,这个note可以作为备注提示生产 ...

  3. python进阶介绍(进阶1)

    转载请标明出处: http://www.cnblogs.com/why168888/p/6411664.html 本文出自:[Edwin博客园] python进阶介绍(进阶1) 1. python基础 ...

  4. linux 安装pip 和python3

    前言: python3应该是python的趋势所在,当然目前争议也比较大,这篇随笔的主要目的是记录在linux6.4下搭建python3环境的过程 以及碰到的问题和解决过程. 另外,如果本机安装了py ...

  5. INFORMATICA 操作流程

  6. 弃坑pexpect,入坑paramiko

    上文书说到,ssh库pexpect的使用,简直就是个“月亮公主”——满眼全是坑.勉强把程序写好了,跑起来的时候发现了一个新坑,让我不可抗拒的把它弃掉了——经常莫名其妙的连不上服务器!开线程连接14台服 ...

  7. eclipse去掉xml验证的方法

    eclipse Multiple annotations found at this line错误,eclipse开发过程中,一些XML配置文件会报错,但是这些其实不是错,飘红的原因是因为eclips ...

  8. js判断值是不是全是数字

    if(isNaN(value)){ 不是数字 }else{ 全是数字 }

  9. js 中 函数的返回值问题

    var result=''; function searchByStationName( address ) { // map.clearOverlays();//清空原来的标注 var keywor ...

  10. Mybatis resultMap灵活用法(使用子查询)

    ### 背景查询广州每个景点的总流量,和每个景点每日流量 #### 数据表 t_广州|唯一标识id|地点place|流量counts|日期date||:---:|:---:|:---:|:---:|| ...