Jump to content

Getting the sprite halfWidth and halfHeight


Mike
 Share

Recommended Posts

Well the topic title says all :P

 

I was lazy enought to want to not use:

 

sprite.width / 2; //works as expected

 

so i tried:

 

sprite.halfWidth;  //undefined

 

so checked the phaser source and saw i have to use:

 

sprite._cache.halfWidth //works as expected ... but doen't feel ok _cache...

 

Also there is this:

 

sprite.body.halfWidth //works as excepted but i'm not 100% sure that this isn't the physics body width and not the sprite width

 

 

So a little info to clear this topic will be cool ? :)

 

 

Link to comment
Share on other sites

The cached halfWidth is the overall bounds half width I believe, not the frame half width. If your sprite isn't rotated that will be the same result. If it is rotated, you'll start to see the difference.

 

Body halfwidth is just the physics body, which can be quite different from the sprite if you've set it to be.

 

Honestly I'd just go with sprite.width / 2 :) (unless you know the sprite isn't going to rotate, then using the cache one is perfectly safe too)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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