Cocos2d-html5中的坐标系统
2015-05-10 17:39
330 查看
在cocos2d-html5中,Scene和Layer的默认锚点是(left,bottom),而其它节点(Node)的默认锚点是(center,center)。无论是Layer还是其它节点,其坐标原点都是父节点的左下角,即(left,bottom)。只是有一个例外,cc.MenuItem是以cc.Menu的锚点为坐标原点。
首先测试Layer:
// 获取尺寸
this.winSize = cc.Director.getInstance().getWinSize();
// 灰色层
this.layer1 = cc.LayerColor.create(cc.c4(200, 200, 200, 255), this.winSize.width, this.winSize.height);
this.addChild(this.layer1, 0);
// 绿色层
this.layer2 = cc.LayerColor.create(cc.c4(0, 255, 0, 255), 200, 200);
this.addChild(this.layer2, 1);
运行结果:
改变layer2的位置:
this.layer2.setPosition(200, 200);
运行结果:
默认情况下,Scene和Layer是不能设置锚点的,要想设置锚点可以使用方法ignoreAnchorPointForPosition(newValue)。
参数newValue
false:锚点可设置
true:锚点被强制设置为(0, 0),无法改变
测试Sprite:
// 添加精灵
this.sprite = cc.Sprite.create("res/bear.png");
this.addChild(this.sprite);
运行结果:
改变sprite的位置:
this.sprite.setPosition(cc.p(100, 100));
运行结果:
#cyg { font: 14px "微软雅黑"; line-height: 1.6em; } #cyg h2 { margin: 1.33em 0 1em 0; font-size: 16px; } #cyg h3 { margin: 1.33em 0 1em 0; font-size: 14px; } #cyg p { margin: 1em 0; } #cyg_code { max-height: 320px; overflow-y: hidden; margin: 1em 0; padding-left: 40px; border: 2px solid rgb(200, 200, 200); background: rgb(231, 229, 220); font: 12px courier,arial,sans-serif; list-style: decimal; } #cyg_code li { min-height: 20px; line-height: 20px; padding: 0 1em; border-left: 3px solid rgb(108, 226, 108); background: rgb(240, 240, 240); white-space: pre; } #cyg_code li:nth-child(even) { background: rgb(230, 230, 230); } #cyg_code em { font-style: normal; color: rgb(117, 113, 94); } #cyg_code strong { font-weight: normal; color: rgb(153, 129, 255); } #cyg_code b { font-weight: normal; color: rgb(166, 226, 46); } #cyg_code cite { font-style: normal; color: rgb(198, 93, 8); } #cyg_code span { color: rgb(249, 38, 76); } #cyg_code q { color: rgb(102, 217, 239); }
首先测试Layer:
// 获取尺寸
this.winSize = cc.Director.getInstance().getWinSize();
// 灰色层
this.layer1 = cc.LayerColor.create(cc.c4(200, 200, 200, 255), this.winSize.width, this.winSize.height);
this.addChild(this.layer1, 0);
// 绿色层
this.layer2 = cc.LayerColor.create(cc.c4(0, 255, 0, 255), 200, 200);
this.addChild(this.layer2, 1);
运行结果:
改变layer2的位置:
this.layer2.setPosition(200, 200);
运行结果:
默认情况下,Scene和Layer是不能设置锚点的,要想设置锚点可以使用方法ignoreAnchorPointForPosition(newValue)。
参数newValue
false:锚点可设置
true:锚点被强制设置为(0, 0),无法改变
测试Sprite:
// 添加精灵
this.sprite = cc.Sprite.create("res/bear.png");
this.addChild(this.sprite);
运行结果:
改变sprite的位置:
this.sprite.setPosition(cc.p(100, 100));
运行结果:
#cyg { font: 14px "微软雅黑"; line-height: 1.6em; } #cyg h2 { margin: 1.33em 0 1em 0; font-size: 16px; } #cyg h3 { margin: 1.33em 0 1em 0; font-size: 14px; } #cyg p { margin: 1em 0; } #cyg_code { max-height: 320px; overflow-y: hidden; margin: 1em 0; padding-left: 40px; border: 2px solid rgb(200, 200, 200); background: rgb(231, 229, 220); font: 12px courier,arial,sans-serif; list-style: decimal; } #cyg_code li { min-height: 20px; line-height: 20px; padding: 0 1em; border-left: 3px solid rgb(108, 226, 108); background: rgb(240, 240, 240); white-space: pre; } #cyg_code li:nth-child(even) { background: rgb(230, 230, 230); } #cyg_code em { font-style: normal; color: rgb(117, 113, 94); } #cyg_code strong { font-weight: normal; color: rgb(153, 129, 255); } #cyg_code b { font-weight: normal; color: rgb(166, 226, 46); } #cyg_code cite { font-style: normal; color: rgb(198, 93, 8); } #cyg_code span { color: rgb(249, 38, 76); } #cyg_code q { color: rgb(102, 217, 239); }
相关文章推荐
- 【iOS-Cocos2d游戏开发之十】添加粒子特效并解决粒子系统特效与Layer之间的坐标问题;
- cocos2d-X学习之坐标系统
- cocos2D坐标系统
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第十一课:Cocos2D-X坐标系统2-3
- cocos2d-x坐标系统
- Cocos2d-x 详解坐标系统
- Cocos2d-x 详解坐标系统
- 【Cocos2d-html5游戏引擎学习笔记(9)】Action系统动作
- Cocos2d-x 详解坐标系统
- cocos2d 坐标系统参考
- cocos2dx概要及开发技术------Cocos2d-x坐标系统
- cocos2d-X学习之坐标系统
- Cocos2d坐标系统
- Cocos2d-x 详解坐标系统
- cocos2d中的坐标系统
- Cocos2d-x v3.1 坐标系统(五)
- 理解Cocos2d-x坐标系统
- iPhone应用Cocos2D坐标系统设置
- cocos2d-x开发记录:二,基本概念(动作,动画,坐标系统)
- 学习3-Cocos2D-X坐标系统