SKSPriteNode位置无缘无故地变为0,0 [英] SKSPriteNode position changes to 0,0 for no reason
问题描述
我在 didBeginContact
方法中创建 SKSpriteNode
,其中包含联系地址:
I create an SKSpriteNode
in didBeginContact
method with location of contact:
CommonBox *boxTwo = [[CommonBox alloc] initWithTexture:[self.mainAtlas textureNamed:@"box07"]];
boxTwo.name = @"regularBox";
boxTwo.position = contact.contactPoint;
[self addChild:boxTwo];
此处的位置是正确的。然后调用update方法,并且在执行任何代码之前,在更新方法开始时将box的位置神奇地改变为0,0。这是为什么?
这两个事件之间不执行其他代码。这真让我抓狂。我尝试从该对象中删除所有碰撞和接触位掩码,但无论如何它都会变为零。对象是合法的等等。
The position is correct here. Then update method is called and the position of box is magically changed to 0,0 at start of update method, before any code at all is executed. Why is that? No other code is executed between these two events. This is driving me crazy. I tried removing all collision and contact bit masks from this object, but it changes to zeroes anyway. Object is legal and so on.
编辑:如果我从该节点移除物理主体,我将获得所需的位置。但是如果它有物理体,我如何设置我的节点位置?
if I remove physics body from that node I will get desired position. But how do I set my position of node if it has physics body?
推荐答案
我发现了我的错误 - 你必须创建设置节点位置后的物理体。在物理主体有位置后设置位置不会做任何事情。
I found out my mistake - you have to create physics body after you set node position. Setting position after physics body has position doesn't do anything.
这篇关于SKSPriteNode位置无缘无故地变为0,0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!