Frage

I have icons that are children of node "shelf", which is a child of "self"(the scene). I also have decorations that are children of node "vehicle", which is also a child of "self".

When an icon is dragged off of the shelf and onto the vehicle, the icon node is removed and a decoration node is spawned in its place, which is made a child of "vehicle" instead of "shelf". This is a problem: when the decoration node is spawned, it jumps far away in the scene because the coordinate systems of "shelf" and "vehicle" are incongruous.

How can I convert the new decoration node from its position in the "shelf" node to its new position in "vehicle" so that it doesn't jump?

(I can post code if you need it, but it will be very long and messy.)

War es hilfreich?

Lösung

Assuming you're using Sprite Kit, you can use the SKNode method convertPoint:toNode: to convert points between coordinate systems.

So for instance, as soon as dragging ends on top of the vehicleNode:

CGPoint iconPos = iconNode.position; // this is position on shelf node
iconPos = [shelfNode convertPoint:iconPos toNode:vehicleNode];

// ... remove iconNode from shelfNode
// ... make new decorationNode

decorationNode.position = iconPos; // this is now position on vehicle node

// ... add decorationNode to vehicleNode
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top