cocos2d中锚点概念
这两天看了下锚点的概念。
/**
* 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);
最新文章
- centos 进度条卡死
- Android drawableleft drawableTop 设置图片的大小
- iOS获取当前时间
- 异步委托(APM)使用Func异步操作,处理耗时操作
- 【CSS3】CSS3:border-image的详解和实例
- Xcode 6 UITextField 键盘不弹出
- cordova的android notify消息通知插件
- 详解Makefile 函数的语法与使用
- Android显示YUV图像
- JSON 数组格式
- 【APIO2016】【UOJ205】【LOJ2568】烟花表演 可合并堆
- 洛谷P2805 植物大战僵尸
- python,栈的小例子
- Java操作队列
- java基础-day25
- 当php版本为5.6时的提示信息解决方法
- RabbitMQ入门:主题路由器(Topic Exchange)
- linux 系统网卡无法识别,缺少驱动
- LeetCode——Submission Details
- Hive语句执行优化-简化UDF执行过程