LearningPhaser9 Posted July 29, 2015 Share Posted July 29, 2015 And what does it do? Sorry Im new to phaser and learning javascript as I go Link to comment Share on other sites More sharing options...
drhayes Posted July 29, 2015 Share Posted July 29, 2015 Think of the image that makes up your sprite as a rectangle. The upper-left corner is (0,0). The lower-right corner is (width - 1, height - 1). The anchor gives a position in the sprite as a percentage of both its width and its height. So an anchor of (0.5, 0.5) is the position (width * 0.5, height * 0.5) in that rectangle. Likewise, an anchor of (0.2, 1) is the position (width * 0.2, height * 1) in your sprite. Phaser uses that to position the sprite. When you set the sprite.x or sprite.y properties you are setting the position of the *anchor* of the sprite in the world. For a platformer, it makes a lot of sense to set the anchor of the player to (0.5, 1). That's the middle of the sprite in the x direction, and the bottom of the sprite in the y direction. Make sense? sbonavida, in mono, soso and 1 other 4 Link to comment Share on other sites More sharing options...
wayfinder Posted July 30, 2015 Share Posted July 30, 2015 A small correction, the anchor is the registration point of the texture (i.e. which point in the texture is going to be at the sprite's exact (x, y) position.) sbonavida, drhayes and in mono 3 Link to comment Share on other sites More sharing options...
drhayes Posted July 30, 2015 Share Posted July 30, 2015 Ah, okay, good point. sbonavida 1 Link to comment Share on other sites More sharing options...
Recommended Posts