cocos2dx进阶学习之坐标转换

在cocos2dx中,有四种坐标系

GL坐标系:左下为原点,x轴向右,y轴向上

UI坐标系:左上为原点,x轴向右,y轴向下

世界坐标系:与GL坐标系相同

本地坐标系:是节点(CCNode)的坐标系,原点在节点左下角,x轴向右,y轴向上


GL坐标和UI坐标转换在导演类(CCDirector)中

CCPoint CCDirector::convertToGL(const CCPoint& obPoint);
CCPoint CCDirector::convertToUI(const CCPoint& obPoint);

世界坐标系和本地坐标系转换在节点类(CCNode)中

CCPoint CCNode::convertToNodeSpace(const CCPoint& worldPoint);
CCPoint CCNode::convertToWorldSpace(const CCPoint& nodePoint);
CCPoint CCNode::convertToNodeSpaceAR(const CCPoint& worldPoint);
CCPoint CCNode::convertToWorldSpaceAR(const CCPoint& nodePoint);

UI坐标系用在触摸事件的参数中,在重载

virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event)

函数时,touch中携带的坐标就是UI坐标系,当用来判断某个精灵是否被点击时,需要将touch转为GL坐标系世界坐标系和GL坐标系是一样的,在cocos2dx中用这种坐标系最多

节点坐标系指以节点左下角为原点的坐标系,用于放置子节点,当某个节点setPosition时,参数所参照的坐标即是父节点的坐标系


转载于:https://my.oschina.net/u/555701/blog/214691

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值