I'm trying to let the player of my PhaserJS game (with MatterJS physics) move a (static?) object around. That is: the player is allowed to move the object, but otherwise it should be static
to the world of MatterJS. Here's a minimal scenario reproducing my situation:
class MyScene extends Phaser.Scene {
create() {
this.matter.add.rectangle(60, 120, 100, 10).isStatic = true;
this.matter.add.pointerConstraint({ /* solve it here?! */ });
}
dropBall() {
this.matter.add.circle(150, 20, 10);
}
}
const game = new Phaser.Game({
banner: false,
width: 300,
height: 150,
physics: {
default: 'matter',
matter: { debug: true, setBounds: true },
},
scene: [MyScene]
});
document.addEventListener("DOMContentLoaded", () => {
document.getElementById("start").addEventListener("click", () => {
game.scene.getScenes(false)[0]?.dropBall();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
<div>1. Move platform to middle. 2. Then <button id="start">Drop a ball!</button></div>
I want the player to only be able to move the static
rectangle around with the mouse. Technically the ball-dropping feature in my example is not needed for the question, but I'd hope it gives some context. Plus it shows that the pointerConstraint
does something because you now can move the balls around (which shouldn't be possible).