Sign in to follow this  
mm

Sprite body anchor

Recommended Posts

Hello, there is a small difference between the sprite body anchor between phaser 2.6 and older versions. In previous versions the body will anchor with the sprite anchor, meaning that if you set the sprite anchor to 0.5 in both axis the body stayed in the center of the sprite, changing the body size would keep it in centre, in the newer version the body is always anchored to the top left of the sprite regardless the anchor of the sprite. Is this behaviour intended? Just wondering if I should re-center my sprites bodies or if this will change to the old behaviour.

 

Thanks.

Share this post


Link to post
Share on other sites

I think that behavior is correct as the anchor of the sprite should not change the anchor of the body persay. Since the body is based around physics it should be changed separately. For instance you may want a sprite of the wing of a plane to be anchored in a manor that isnt relative to its body so that you have have that wing show over the top and allow the wing to be passed under based on some kind of angle. If it was top down the anchor might be off to the right hand side, and you may want the body to be on the top left. If it was a plat former you may want it to be center top for an anchor but the body to be top center.

Share this post


Link to post
Share on other sites

Changing `anchor` changes the absolute position of the sprite texture (and body) but not the body relative to the texture. You can move the body relative to the texture only by using body.setSize(). I don't think this will change soon. :)

 

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.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.