加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos2d-x源码阅读1 UI树1(第一次系统而有成效的阅读源码的感悟

发布时间:2020-12-14 20:19:27 所属栏目:百科 来源:网络整理
导读:之前我很少看源码,觉得枯燥又没有头绪。说实话现在看的也少,不过作为程序员要想成长,必须要突破自己的瓶颈吧。 也许我的天赋不在写代码这里,也许这是一个越走越难的路,也许这又是一个有金矿的浅坑,坚持下去就会挖到金矿。 然而没有那么多可以选择叻,

之前我很少看源码,觉得枯燥又没有头绪。说实话现在看的也少,不过作为程序员要想成长,必须要突破自己的瓶颈吧。

也许我的天赋不在写代码这里,也许这是一个越走越难的路,也许这又是一个有金矿的浅坑,坚持下去就会挖到金矿。

然而没有那么多可以选择叻,试着去强大吧,即使自己不擅长,即使落后很多,即使,即使,即使,即使,。。。。

http://cn.cocos2d-x.org/tutorial/show?id=2157

推荐大家去这里看这个视频,自己看源码可能没有头绪,跟着王老师的视频效果还是很好的。

这里是我根据视频记录下来的主要的函数,涉及了Node的所有添加,删除,设置属性和查找,具体的细节还是大家自己去看视频对着源码阅读。感觉真不错。(*^__^*) ……

自己去看视频吧,去看吧。


virtual void ignoreAnchorPointForPosition(bool newValue) ;只能用于Scene和Layer,用在其他控件报错,为true则不管设置的锚点是多少,都以(0,0)作为锚点 virtual void setAnchorPoint(const Vec2& anchorPoint);用百分比设置本地化坐标系,就是自己坐标系 virtual const Vec2& getAnchorPoint() const; 返回的锚点的位置(百分比) virtual const Vec2& getAnchorPointInPoints() const; 返回锚点的位置(具体像素值) virtual void setPosition(const Vec2 &position); 是设置自己在父UI的坐标系的位置,position相对于OpenGL坐标系 virtual void setNormalizedPosition(const Vec2 &position); 用0-1之间的值设置位置,0-1之间是相当于 pos/getParent()->getContentSize(); virtual const Mat4& getNodeToParentTransform() const;得到一个矩阵,可以转换子UI的坐标到父UI的坐标 virtual AffineTransform getNodeToParentAffineTransfrom() const; 得到一个仿射变换,可以转换子UI的坐标到父UI的坐标,比Mat4矩阵要小 virtual const Mat4& getParentToNodeTransform() const; 得到一个矩阵,可以转换父UI的坐标系到子UI的坐标系 virtual AffineTransform getParentToNodeAffineTransfrom() const; 得到一个仿射变换,可以把父UI的坐标系转换到子UI的坐标系 virtual Mat4 getNodeToWorldTransfrom() const; virtual AffineTranfrom getNodeToWorldAffineTransfrom() const; virtual Mat4 getWorldToNodeTransfrom() const; virtual AffineTransfrom getWorldToNodeAffineTransfrom() const; Vec2 convertToNodeSpace(const Vec2& worldPoint) const; Vec2 convertToWorldSpace(const Vec2& nodePoint) const; Vec2 convertToNodeSpaceAR(const Vec2&worldPoint) const;加入了锚点坐标系,如果锚点为(0,0)则和 convertToNodeSpace一样,否则以锚点为准 Vec2 convertToWorldSpaceAR(const Vec2& nodePoint) const;加入了锚点坐标系,如果锚点为(0,0)则和 convertToWorldSpace一样,否则以锚点为准 Vec2 convertTouchToNodeSpace(Touch * touch) const; Vec2 convertTouchToNodeSpaceAR(Touch * touch) const; virtual void addChild(Node * child,int localZorder,int tag); virtual Node * getChildByTag(int tag) const; virtual Node * getChildByName(const std::string & name) const; virtual void setParent(Node * parent); virtual Node * getParent() {return _parent;} virtual void removeFromParent(); virtual void removeFromParentAndCleanup(bool cleanup); virtual void removeChild(Node * child,bool cleanup = true); virtual ssize_t getChildrenCount() const; virtual void removeAllChildren(); virtual void removeAllChildrenWithCleanup(bool cleanup);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读