-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Version
- Phaser Version: Phaser 3.87.0
- Operating system: Windows
- Browser: Chrome
Description
The documentation for GAMEOBJECT_DRAG and GAMEOBJECT_DRAG_END both say that the x and y values are in "world space", however this doesn't seem to be correct because if you are dragging an object that is inside of a container, you can still use the values directly to set the position of the object to where the mouse is.
However, there is another contradiction which is the GAMEOBJECT_DRAG_END x and y values seem to be in the local space of the object being dragged, so they differ from the GAMEOBJECT_DRAG values.
Example Test Code
export default class DragEventIssue extends Phaser.Scene {
create() {
this.add.rectangle(this.scale.width * .75, this.scale.height / 2, 100,100, 0xff0000).setInteractive({ draggable: true })
.on(Phaser.Input.Events.GAMEOBJECT_DRAG, (pointer, x, y) => console.log(x,y))
.on(Phaser.Input.Events.GAMEOBJECT_DRAG_END, (pointer, x, y) => console.log(x,y)); // should return the same values but doesn't
const r = this.add.rectangle(this.scale.width / 4, this.scale.height / 2, 100,100, 0xff0000).setInteractive({ draggable: true })
.on(Phaser.Input.Events.GAMEOBJECT_DRAG, (pointer, x, y) => {
console.log(x,y);
r.setPosition(x,y);
})
.on(Phaser.Input.Events.GAMEOBJECT_DRAG_END, (pointer, x, y) => console.log(x,y)); // should return the same values but doesn't
}
}
Additional Information
The documentation should probably be updated to clarify that the x/y values are in the "parent space" - which might be the scene and thus "world space" but might be in a container's space. The GAMEOBJECT_DRAG_END values should be fixed to return the same values as the GAMEOBJECT_DRAG event, or at least the documentation should be updated to indicate what space they are in to avoid confusion. This may affect other DRAG events such as DRAG but I haven't checked.