GAMEOBJECT_DRAG and GAMEOBJECT_DRAG_END events return different x/y values
@photonstorm is already working on this.
Since Feb 10, 2025.
- Dominant language
- JavaScript
- Stars
- 40.3k
- Forks
- 7.2k
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.