• Runtimes
  • [WebGL] updateOffset() unexpectedly changes x position

I have some code like this:

attachment.y = 50;
attachment.updateOffset(attachment);

When the call to updateOffset() is made, the y position will update as expected, but the x position also changes for the attachment with end result of misaligning the attachment leftward of where it should be. If I don’t call updateOffset() the attachment is aligned as expected on x.

The code has this problem for just one of my skeletons, with all other skeletons working fine. Two differences for the problem skeleton are 1. the attachment is parented to a bone instead of directly to root. 2. Skeleton Jsons are exported from the latest 3.7 beta as of last night whereas all the other skews are exported from an older 3.7 version. (Can look up exact versions when I get home.)

I am using the latest webgl runtime from the 3.7 branch on github.

Will dig into this deeper and try to narrow it down, but maybe there is something easy to fix that I’m doing wrong.

  • Düzenlendi

I was speaking not of the .x value itself changing.

The rendered horizontal position of the attachment changes. So just looking at the screen, there is an eye lid (the attachment) on a face that is positioned to the left of the face.

If I comment out the call to updateOffset() the attachment will be rendered horizontally correct when I see it on the screen. So something about this call makes the horizontal misalignment occur.

Got it, thanks. It is working correctly. The region attachment position (x and y properties) are in the parent bone's coordinate system. The attachment will move horizontally on your screen when you adjust x only if the bone axes align with the screen axes. Your root bone aligns with the screen axes, so you get the behavior you expect. Some other bone may be rotated, scaled, or sheared.

You can use Bone worldToLocal to convert a world position to a bone's coordinates, and Bone localToWorld goes the other way.

I figured it out.

The problem attachment depicts eye lids. I want them to blink in a downward motion. That is what my code snippet above does in its full, non-simplified version.

For the skeleton that wasn't working, there was a neck bone with a rotation value of 90 degrees. The Y value I was adjusting was moving along the screen X axis because of this 90 degree rotation. It makes sense for it to work this way. I just got confused because visually, in the editor, the attachments at a quick glance didn't look turned at 90 degrees. I remade my skeleton in the Editor to remove the 90 degree rotation, and after that, the blink code was again moving the lids vertically instead of horizontally.


I missed your message before I posted mine. Still, your explanation is useful. Thanks!