Jump to content

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



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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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