cocos2d convertToWorldSpace [英] cocos2d convertToWorldSpace

查看:177
本文介绍了cocos2d convertToWorldSpace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定convertToWorldSpace是否有效。




  • 我有spriteA, li>

  • 我将它设置为位置40,40,并将其添加到场景中。



  • 我打印出spriteB的位置:80,80。


  • 然后我打印[self convertToWorldSpace:spriteB.position]。而且,我还是得到80,80。
    这里不应该有spriteB的位置不同吗?



解决方案

在你的情况下,如果你想知道你的spriteB在当前世界的位置,你必须从其父(spriteA)调用convertToWorldSpace方法:


[spriteA convertToWorldSpace:spriteB.position];


convertToWorldSpace:方法将节点的变换应用于给定位置。你应该总是从父的sprite调用这个方法。


I'm not sure convertToWorldSpace works.

  • I have spriteA which is the parent.

  • I set it to position 40,40 for example and add it to the scene.

  • I have a second spriteB which I set at position 80,80.

  • I add spriteB to spriteA.

  • I print out the position of spriteB: 80,80.

  • I then print [self convertToWorldSpace:spriteB.position]. And, I still get 80,80. Shouldn't spriteB position be different here?

解决方案

In your case if you want know the position of your spriteB in the current world you must call the "convertToWorldSpace" methods from its parent (the spriteA) :

[spriteA convertToWorldSpace:spriteB.position];

The "convertToWorldSpace:" method applies the node's transformation to the given position. You should always call this methods from the parent's sprite.

这篇关于cocos2d convertToWorldSpace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆