phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
36.94k stars 7.08k forks source link

Resetting a static body should reapply the offset #6729

Closed samme closed 7 months ago

samme commented 7 months ago

Version

Description

Create a game object with a static Arcade Physics body. Give the body an offset with setOffset(x, y).

Reset the body with any coordinates. Now the body position doesn't include the offset.

Call setOffset(x, y) again. The body position is the same — still no offset.

Example Test Code

const image = this.physics.add.staticImage(0, 0, '32x32').setOffset(16, 16);

// These pass.
console.assert(image1.body.x === 0);
console.assert(image1.body.y === 0);

// Reset on the original position.
image.body.reset(0, 0);

// These fail.
console.assert(image1.body.x === 0);
console.assert(image1.body.y === 0);

Also https://codepen.io/samme/pen/wvOjoGK?editors=0010

rgk commented 7 months ago

:v: