zoukankan      html  css  js  c++  java
  • 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时,参数所参照的坐标即是父节点的坐标系

  • 相关阅读:
    MySQL——索引
    MySQL——逻辑分层与存储引擎
    APP测试总结
    如何提高测试的质量
    测试用例的基础
    opencv图像处理常用操作一
    【bug】【Cannot find reference 'imread' in '__init__.py | __init__.py'】
    Numpy学习笔记
    工业互联网
    Python基本的数据清洗
  • 原文地址:https://www.cnblogs.com/new0801/p/6177224.html
Copyright © 2011-2022 走看看