SKSPriteNode位置无故变为0,0 [英] SKSPriteNode position changes to 0,0 for no reason

查看:26
本文介绍了SKSPriteNode位置无故变为0,0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 方法,并且在 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屋!

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