Getting the sprite halfWidth and halfHeight

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 ? :)



Share this post

Link to post
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)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.