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时,参数所参照的坐标即是父节点的坐标系

  • 相关阅读:
    bash八大扩展一网打尽
    MySQL命令行导出数据库
    Windows 7上的DirectX 11.1
    把KlayGE嵌入其他GUI框架
    KlayGE的资源载入系统
    学习路漫漫……
    写下我的第一篇Post,呵呵
    今天学习:CSS中的类class和标识id选择符(.和#号)
    Remove Duplicates from Unsorted List
    2012 TODO List
  • 原文地址:https://www.cnblogs.com/new0801/p/6177224.html
Copyright © 2011-2022 走看看