cocos2dx 坐标系统详解

cocos2dx 坐标系统详解,第1张

概述1、在cocos2dx中,支持以下坐标系: ● 屏幕坐标系: 原点在左上角,X轴向右,Y轴向下。(比如处理触摸事件时CCTouch对象中的坐标就是屏幕坐标系) ● OpenGL坐标系: 原点在左下角,X轴向右,Y轴向上。(比如CCNode类的setPosition函数调用就是此坐标系) ● 世界坐标系:指相对于整个屏幕的坐标系,(0,0)就是屏幕的左下角 ● 本地坐标系:相对于父对象的坐标。 2、

1、在cocos2dx中,支持以下坐标系:

● 屏幕坐标系: 原点在左上角,X轴向右,Y轴向下。(比如处理触摸事件时CCtouch对象中的坐标就是屏幕坐标系)

● OpenGL坐标系: 原点在左下角,X轴向右,Y轴向上。(比如CCNode类的setposition函数调用就是此坐标系)

● 世界坐标系:指相对于整个屏幕的坐标系,(0,0)就是屏幕的左下角

● 本地坐标系:相对于父对象的坐标。


2、锚点(AnchorPoint)


● 一句话来描述就是:锚点我们可以看成用一根图钉将一张纸或者相片钉在墙上的那个点。


● 锚点的x和y取值范围在[0,1]之间。


● 精灵(Sprite)的锚点默认为(0.5,0.5),默认是不忽略锚点的,所以

?
1 virtual bool isIgnoreAnchorPointForposition(); //默认返回false

● 其他节点比如说cclayer和CCSense,锚点默认为(0,0),默认是忽略锚点

?
1 virtual bool isIgnoreAnchorPointForposition(); //默认返回true


所以,如果要在cclayer和CCSense中设置锚点,要如下设置

?
1 2 3 4 cclayer* layer1 = cclayercolor::create(ccc4( 255 , 0 , 255 ), 300 , 200 ); addChild(layer1); layer1->ignoreAnchorPointForposition( false ); //设置不忽略锚点,此时锚点会变为默认的(0.5,0.5) layer1->setAnchorPoint(ccp( 0 , 0 )); //然后再这里设置自定义锚点



<喎�"http://www.2cto.com/kf/ware/vc/" target="_blank" >vcD4KPHA+PGJyPgo8L3A+CjxwPjxzdHJvbmc+MyDX+LHq16q7u6Osz+rPul3iys3I58/Co6zTprjD0tG+rcu1tcO63MP3sNfBy6GjPC9zdHJvbmc+PC9wPgo8cD48c3Ryb25nPjxicj4KPC9zdHJvbmc+PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;">CCSprite *sprite1=CCSprite::create("Closenormal.png");cclOG("sprite1=(%f,%f)",sprite1->getContentSize().wIDth,sprite1->getContentSize().height);sprite1->setAnchorPoint(ccp(1,1));sprite1->setposition(ccp(20,40));CCSprite *sprite2=CCSprite::create("Closenormal.png");sprite2->setposition(ccp(-5,-20));sprite2->setAnchorPoint(ccp(1,1));CCPoint point1=sprite1->convertToNodeSpace(sprite2->getposition());//以sprite1左下角为参考点(0,0)定位sprite2锚点的坐标,并返回CCPoint point2=sprite1->convertToWorldspace(sprite2->getposition());//以sprite1左下角为参考点(0,0),定位(-5,20)这个点为sprite2锚点坐标,并返回CCPoint point3=sprite1->convertToNodeSpaceAR(sprite2->getposition());//以sprite1的锚点为参考点(0,0),定位sprite2锚点的位置,并返回CCPoint point4=sprite1->convertToWorldspaceAR(sprite2->getposition());//以sprite1的锚点为参考点(0,0),定位定位(-5,20)这个点为sprite2锚点坐标,并返回cclOG("point1=(%f,point1.x,point1.y);cclOG("point2=(%f,point2.x,point2.y);cclOG("point3=(%f,point3.x,point3.y);cclOG("point4=(%f,point4.x,point4.y);

输出结果如下:sprite1=(40.000000,40.000000) (图片大小) point1=(15.000000,-20.000000) point2=(-25.000000,-20.000000) point3=(-25.000000,-60.000000) point4=(15.000000,20.000000) 总结

以上是内存溢出为你收集整理的cocos2dx 坐标系统详解全部内容,希望文章能够帮你解决cocos2dx 坐标系统详解所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1009638.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存