• Runtimes
  • [as3 starling] Skeleton's coordinates

Hi,

Maybe I'm wrong, but I encountered a suspicious issue. Starling's runtime includes a example with the walking boy. Setting a position for the boy looks like:

private var skeleton:SkeletonAnimationSprite;
skeleton.x = 320;
skeleton.y = 420;

SkeletonAnimationSprite is a Starling's sprite, so we set a starling.displayObject coordinates (not a Spine's skeleton coordinates). The Spine's skeleton will be have (0,0) all the time, but a Spine's manual says, that x,y should be „The drawing position of the skeleton in world coordinates.”

I think the example should have form:

private var skeleton:SkeletonAnimationSprite;
skeleton.skeleton.x = 320;
skeleton.skeleton.y = 420;

I know it is very simple example and a visual effect will be the same for both solutions, but I think first code includes a dangerous guidepost. If we set only Starling's coordinates we can't use, for example, a Spine's native „hitTest” or „containsPoint”/”intersectsSegment” (bounding box functions). They require proper world coordinates from Spine's skeleton and they don't use Starling's world coordinates.

Related Discussions
...
  • Змінено

There was recently some related discussion here:
viewtopic.php?f=7&t=1337

Some runtimes (eg libgdx) use the skeleton x/y to position the skeleton. Other runtimes (Startling, Unity, Tk2D, etc) have a container (eg a scene graph node) that the skeleton is relative to. Usually you want to position the container, eg in Unity the container is a GameObject and may have a collider attached for physics. The container position may be important for other reasons, eg to rotate or scale the container. In some cases you probably could leave the container at 0,0 and position the skeleton using the skeleton's x/y, but I think many times you'll need to position the container.

The skeleton only really knows about the coordinate system for the container it is in. If the container is translated, scaled, and rotated, the skeleton won't how to change its world bone positions or the bounding box vertices to the coordinate system you desire. What if you want them in the container's parent's parent coordinate system? I think it makes most sense to do the transform to the coordinate system of your choice.

For the simple case, you could set the skeleton x/y and not the container position, or use some code like I posted in the thread I linked above. For more complex cases you'll need to transform the bone position, bounding box polygons, etc as appropriate to get them in the coordinate system you want. If there is something we can do to make that easier, that would be great.

I gotcha, thanks Nate for your explanation.