dude78

change sprite bounds

Recommended Posts

Hello guys. I use:

this.load.atlas('spriteName');

to load a sprite.

 

To see its bounds and body (for interacting with other objects) we can use:

this.debug.body('spriteName');
this.debug.spriteBounds('spriteName');

 

At the beginning these sizes are the same but we can change body size in such a way: (docs)

this.spriteObject.body.setSize(width, height [, offsetX] [, offsetY]);

 

The question: how to change sprite bounds? Is there any way?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

@dude78 sometimes it looks like this forum is dead :D What do you mean by changing sprite bounds? You cannot change texture size but you can change size of sprite which uses it. Lets say you have 'character.png' image 100x200 pixels size. Once you load it, it will have 100x200 pixel size texture. You can create sprite using this texture and by default it will be also 100x200 but you can easily change its width/height by my_sprite.width =150 or my_sprite.scale.x = 0.7 to make its width 100*0.7 = 70 pixels. That will change sprite's bounds... also you can directly change x/y propery of sprite to move it around screen and that will also affect bounds. If I understand your question wrongly, just let me know.

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.