cocos2d convertToWorldSpace [英] cocos2d convertToWorldSpace
问题描述
我不确定convertToWorldSpace是否有效。
-
我有spriteA, li>
-
我将它设置为位置40,40,并将其添加到场景中。
-
-
-
然后我打印[self convertToWorldSpace:spriteB.position]。而且,我还是得到80,80。
这里不应该有spriteB的位置不同吗?
我打印出spriteB的位置:80,80。
在你的情况下,如果你想知道你的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屋!