How to enable multitouch ? jsfiddle inside

#1

Hi,

I have two sprites (button_move and button_fire) with two touchs events. I want to have multitouch enabled : when i press on the same time on the two buttons, normaly the alpha of the two buttons is 0.5. But it’s not working.

I have follow the docs, especially this :
https://rexrainbow.github.io/phaser3-rex-notes/docs/site/index.html/touchevents/
https://labs.phaser.io/index.html?dir=input/multitouch/&q=

And i made a jsfiddle about it :

https://jsfiddle.net/espace3d/vLq08gke/12/

the full code is :

var config = {
    type: Phaser.AUTO,
    width: 480,
    height: 640,
    parent: 'phaser-example',
    input :{
		activePointers:2,
	  },
    scene: {
        create: create,
        update: update
    }
};

var game = new Phaser.Game(config);
var button_move;
var button_fire;
var flag_move=false;
var flag_fire=false;

function create ()
{
	button_move=this.add.sprite(100,100,'image').setInteractive();
	button_move.on('pointerdown',function(pointer1){
		flag_move=true
	})
	button_fire=this.add.sprite(300,100,'image').setInteractive();
	button_fire.on('pointerdown',function(pointer2){
		flag_fire=true
	})
}

function update()
{
 if (flag_move){
  	button_move.alpha=.5
 }
 if (flag_fire){
  	button_fire.alpha=.5
 }
}

Thanks for your help.

Countdown Timer
#2

Hi @espace,
This is from Phaser docs:

By default Phaser creates 2 pointer objects: mousePointer and pointer1 .

You should put in your game config : activePointers: 3
Hope it helps. Good luck !! :grinning:
Regards.

1 Like
#3

Hey, add this before your input listeners: this.scene.input.addPointer(3);

1 Like
#4

hi @jjcapellan and @Jake.Caron,

Finally it was so simple, thanks a lot both

i choose the solution from jjcapellan but the solution from Jake Caron works also

https://jsfiddle.net/espace3d/vLq08gke/14/

#5

Glad it worked. It is a bit wonky that you need to have 3 active pointers to get 2 touch-points. I would have thought that pointer1 would be both the first touch and/or the mouse pointer.

#6

Yes it’s not logical.