Skip to content
Advertisement

How can set pointerDown for each of rectangle on Phaser 3

I’m trying to set up the Conway’s Game of Life using Phaser.

My question is this: how can I make a Rectangular of the Phaser.geom class contain a click event?

Class Dots:

JavaScript

Class Game:

JavaScript

Advertisement

Answer

You are setting interactive on the graphics serveral time, it the forEach-loop. I think this can be done only once, so you are overriding it, but I’m no expert.

I would set the interactivity once, for the whole region:

JavaScript

And than in the “click event” select the Rectangle/Dot

JavaScript

To get the Rectangle/Dot clicked, there are many ways, here is one:

JavaScript

btw.:
I would add the graphics once in the create method:

JavaScript

and in the draw method just clear the graphics-object.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement