setSize seems to works but not for x position

Hey All,

I’ve been working on this game for a few weeks.
My character can roll into these small tunnels(see image).
I have a simple function to check if the character is in a tunnel, it goes something like this:
If the player’s x position is more than the tunnel’s x position the player is in the tunnel.

player.setSize(30, 80, true)
if (player.x > platform.x) {
    // Player appears to be in tunnel
    inTunnel = true
}

It does work as intended, the only problem seems to be that the x position is based on the players original frame size:

    sceneParam.load.spritesheet('hero',
        'assets/player-idle.png',
        { frameWidth: 192, frameHeight: 94 }
    )

So in the image you can see that even though I’ve set the player’s size, the x position is technically less than the tunnel because it’s basing it’s x position on the original frame size(the debug test in the image illustrates what i mean).

I’ve tried using player.body.sourceWidth, player.displayWidth but it doesn’t seem to base the position on the size I have set.

Does any one know what I can do?

Pasted_Image_1_10_21__11_48_am

Thank you all
Moe

I figured it out.

Using player.body.position.x seems to ensure that it uses the x position of the set body,

Hope it helps any one else with a similar issue.

Thank you.