SKNode position not working, always going to default 0,0

独自空忆成欢 提交于 2019-11-30 20:24:21

I've been having this same issue. I have a subclass of SKSpriteNode that most of my in-game nodes use as a superclass. I've added this method, which I use whenever I run into the positioning problem:

- (void)refreshPhysicsBodyAndSetPosition:(CGPoint)position {

    /*
     * Weird thing here: if I just set the position of these nodes, they
     * end up at position (0,0). However, if I remove the physics body, set
     * the position, and then re-add the physics body, the nodes are
     * placed correctly.
     */

    SKPhysicsBody *tempPhysicsBody = self.physicsBody;
    self.physicsBody = nil;

    // Position and re-add physics body
    self.position = position;
    self.physicsBody = tempPhysicsBody;
}

Obviously, this isn't a real answer to the issue, but it's a workaround that may help some of you. I have a question opened on the Apple Developer forum, which you can view here:

https://devforums.apple.com/thread/222332

Hoping I hear back soon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!