Prevent Location Offset With SpriteKit Camera Node

拜拜、爱过 提交于 2019-12-01 11:21:39

问题


I have noticed that the centerOnNode: method as shown,

- (void)centerOnNode:(SKNode *)node {

    cameraOffset = [node.scene convertPoint:node.position fromNode:node.parent];
    node.parent.position = CGPointMake(node.parent.position.x - cameraOffset.x, node.parent.position.y - cameraOffset.y);

}

greatly impacts the relative positioning of child nodes. As soon as this method runs, the child nodes do in fact seem to be impacted. The following image show the logic of NO movement then with moving left and slightly down:

I drew a light blue box to estimate the physics body that it seems the paths are referencing instead of the updated frame. The lines and circles that you see represent 2 methods I am using for pathfinding.

  • The line with the dots are just ray tests that I am doing to see if a ray along the green line intersects the square physics body.
  • The single point you see at the top corner is from using GameplayKit to construct a path that avoids the black square as an obstacle.

I am struggling to figure out how to avoid the camera repositioning from effecting the positioning of the children in the scene.

FYI: I have tested the pathfinding with moving the character but NOT the camera and it works perfectly (shown below)

Clearly the camera offset is the issue. If anyone can tell me what to do to keep the camera movement and the precision of the pathfinding I would greatly appreciate it.

来源:https://stackoverflow.com/questions/35705597/prevent-location-offset-with-spritekit-camera-node

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