When I pressed spacebar + arrow keys on the keyboard, it shoot projectile
I would like to support this for touchscreen devices with vJoystick + buttons to do similar functions …
When I added a regular button, it just detect the button press or the vJoystick but not BOTH together ?
Should I use rex-plugins of Button - Notes of Phaser 3 ??
this.buttonFire = this.add.sprite(600, 400, "buttonFire").setInteractive();
this.buttonFire.setDepth(1).setScrollFactor(0).setScale(0.5);
this.buttonFire.on("pointerdown", () => {
console.log("clicked");
this.input.keyboard.emit("SPACE");
});
this.buttonFire.on("pointerup", (pointer) => {
console.log("released");
});
Secondly, I am not sure if this works, I also wanna emit the spacebar key when button is pressed
this.buttonFire.on('pointerdown', ()=> {
this.input.keyboard.emit('SPACE')
})
Phaser3 engine support 1 touch pointer by default. Need to add one more touch pointer.
scene.input.addPointer(1)
Reference
Thanks for the scene.input.addPointer() , it is now working …
Once I enabled multi touch, the emit is not working, I didn’t see the emit method on this, basically I want to trigger the spacebar when a button is touch/clicked…
https://newdocs.phaser.io/docs/3.55.1/Phaser.Input.Keyboard
this.buttonFire.on('pointerdown', ()=> {
console.log("Clicked")
this.input.keyboard.emit('SPACE')
})
Missing this
(scene instance here) as scope parameter.
this.buttonFire.on('pointerdown', ()=> {
console.log("Clicked")
this.input.keyboard.emit('SPACE')
}, this)
Still not working, this is the entire code … maybe I missed something…
The setTint() is working so I know my button event is triggered… it just didn’t trigger the spacebar
// Add an extra touch pointer
this.input.addPointer(2);
this.buttonFire = this.add.sprite(650, 600, "buttonFire");
this.buttonFire.setDepth(1).setInteractive().setScrollFactor(0).setScale(0.5);
this.buttonFire.on(
"pointerdown",
(pointer) => {
console.log("clicked");
this.buttonFire.setTint(0xff0000);
this.input.keyboard.emit(Phaser.Input.Keyboard.KeyCodes.SPACE);
},
this
);
this.buttonFire.on(
"pointerup",
(pointer) => {
console.log("released");
this.buttonFire.setTint(0xffffff);
},
this
);
Dm me Redirecting...
I can help you
I ended up with 4 arrow keys buttons for touch, easier to press and single touch instead of combo of vJoystick + buttons …
closing this …