Jump to content
Sign in to follow this  
sshukul

Sprite with bone pivot point calculation

Recommended Posts

Hi I'm the maintainer of the implementation of Spriter for the Moai SDK game engine :

https://github.com/sshukul/MoaiSpriter

I was having some problems with rotations of sprites attached to bones which I'm guessing has to do with pivot points. Basically when I rotate a bone attached sprite, the pivot point seems off during the tween (images attached). The actual keyframes render correctly.

This makes sense as right now my plugin just sets it to the default pivot point which is the top left corner of the sprite, but it looks like within Spriter the sprites attached to bones have their pivot points shifted to the bone's starting point. 

My question is: How is this bone based pivot point calculated from the SCML? I searched through the SCML Reference here but couldn't find anything:

http://www.brashmonkey.com/ScmlDocs/ScmlReference.html

The way the Moai game engine works is that I can pass it a pivot point for the rotation animations  and it would render the rotations and tweens internally, but my plugin would have to perform the calculations for the pivot points.

The closest I got was the unmapFromParent function which seems to recalculate the sprite's x and y coords independently when detached from a parent bone? Do I basically have to reverse this function to find out the x,y coords of the parent bone in relation to the sprite?

Or am I off base here and the problem is just something else entirely?

Screenshot 2018-12-31 at 1.15.48 PM.png

Screenshot 2018-12-31 at 1.14.00 PM.png

Share this post


Link to post
Share on other sites

Hello.  It should be the same math that you use to get a child bone position from a parent bone.  Use that to calculate the pivot point from a sprite's location.   So if you say that your sprite's position is like the parent bone's position, then the child in this situation would be at position (-pivot.x * scale.x * image.width, -pivot.y * scale.y * image.height), the resulting position of that transformation is where you should position the sprite.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...