Jump to content

How does the .anchor work?


Noaml1
 Share

Recommended Posts

I think it sets the point which the 'body' of the sprite is centered - like, this is where the sprite will revolve around or this is what will be considered in things such as onFloor() or to check if its in the bounds.
I'm trying to use it on a sword to a) make it stay with my character and appear in his hand
b ) have a realistic fall - by this i mean, if it falls upright, i want it to slowly fall to its side...i realize that if i dont change the anchor, it floats in air and thinks its on the floor (it is much taller than it is wide)

Link to comment
Share on other sites

Actually all anchor does is set the position of the texture relative to the x/y coordinates. Here I've prepared this example to show:

 

http://examples.phaser.io/_site/view_full.html?d=sprites&f=anchor.js&t=anchor

 

Notice how the Sprite x/y position doesn't change at all, but the texture is shifting anyway?

 

For positioning a sword on a hand of a Sprite I wouldn't use anchor, I'd put the character into a Group and then position the sword that way. Or use Sprite.pivot (which is given in pixel values) to pivot a sprite around another.

Link to comment
Share on other sites

  • 3 weeks later...
 Share

  • Recently Browsing   0 members

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