Sprite collision box problem

Hello

I’m using the original sprites from the webpage phaser tutorial.

I’m setting the display height and width using the following code:

        var player = this.physics.add.sprite(400, 120, 'dude');
        player.setDisplaySize(80, 80)
        player.setSize(80, 80)

but the result is:

image

im setting the same display width and heigth in the methods setDisplaySize(w,h) and setSize(w,h) (one to the rendering size, and the other to collition box), but, why the both sizes are different? and whath should I do to increment or reduce the collition box depending on the sprite display size?

Thanks.

Don’t use player.setSize(). Use player.body.setSize() instead, if you want to resize the body. But the body is scaled to the sprite display size automatically.

1 Like

As @samme mentioned, use the setSize method from body. You can use the regular setSize that a sprite has for stuff that doesn’t involve physics (like a background or UI elements). For stuff that may collide, you need to use the method from body.

1 Like