Jump to content

Sprite body anchor


mm
 Share

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.

Link to comment
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.

Link to comment
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. :)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...