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

/**

* 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);

最新文章

  1. centos 进度条卡死
  2. Android drawableleft drawableTop 设置图片的大小
  3. iOS获取当前时间
  4. 异步委托(APM)使用Func异步操作,处理耗时操作
  5. 【CSS3】CSS3:border-image的详解和实例
  6. Xcode 6 UITextField 键盘不弹出
  7. cordova的android notify消息通知插件
  8. 详解Makefile 函数的语法与使用
  9. Android显示YUV图像
  10. JSON 数组格式
  11. 【APIO2016】【UOJ205】【LOJ2568】烟花表演 可合并堆
  12. 洛谷P2805 植物大战僵尸
  13. python,栈的小例子
  14. Java操作队列
  15. java基础-day25
  16. 当php版本为5.6时的提示信息解决方法
  17. RabbitMQ入门:主题路由器(Topic Exchange)
  18. linux 系统网卡无法识别,缺少驱动
  19. LeetCode——Submission Details
  20. Hive语句执行优化-简化UDF执行过程

热门文章

  1. C/C++ 合法整数与字符
  2. Simotion 凸轮同步,偏移凸轮起点
  3. No module named _sqlite3
  4. D3——基本知识点
  5. Angular4.0--创建类实例
  6. xml-apis-ext.jar
  7. BZOJ 3680: 吊打XXX (模拟退火)
  8. redis持久化那些事(kēng)儿
  9. Linux 查看所有登录用户的操作历史
  10. BZOJ3033:太鼓达人(DFS,欧拉图)