-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
Description
Version
- Phaser Version: 3.54.0
- Operating system: Windows
- Browser: Tested on both Chrome and FIrefox
Description
Error when dragging an object outside the game area, if the object is constrained and the object is on top of another interactive object.
In my testing, this did not occur when the game object was not constrained, and it did not occur when it was not on top of another interactive object. I discovered this when trying to create a volume slider for my game, for which the slider knob was constrained to the slider area.
Although it does not crash the game, the error shows up on console.
Steps to reproduce (using test code below):
- Click the green box and begin dragging it
- Keep dragging until the mouse pointer is outside the game area (e.g. in the white area of the page background)
- Release the mouse button
- Console will show:
Uncaught TypeError: Cannot read property 'renderList' of undefined
at initialize.sortGameObjects (phaser.min.js:1)
at initialize.processOverOutEvents (phaser.min.js:1)
at initialize.update (phaser.min.js:1)
at initialize.updateInputPlugins (phaser.min.js:1)
at initialize.onMouseUp (phaser.min.js:1)
at onMouseUpWindow (phaser.min.js:1)
This appears to be because the camera associated with the pointer is undefined when the event takes place outside the game area.
Example Test Code
https://codepen.io/lyger-zero/pen/PopNKbM
const game = new Phaser.Game({
parent: "phaser-root",
width: 800,
height: 600,
scene: {
create: create,
}
})
function create() {
const rect1 = this.add.rectangle(400, 300, 800, 600, 0xff0000).setInteractive();
const rect2 = this.add.rectangle(400, 300, 200, 100, 0x00ff00).setInteractive();
this.input.setDraggable(rect2);
rect2.on("drag", function(pointer, dragX, dragY) {
rect2.x = Phaser.Math.Clamp(dragX, 200, 600);
rect2.y = Phaser.Math.Clamp(dragY, 100, 400);
});
}
Additional Information
indextwo and Mayr-Katarn