I am trying to add my game objects onto my scene. The code I am using is:
export default class WorldObject extends Phaser.GameObjects.Graphics {
constructor (scene, data) {
super(scene, data.x, data.y);
this.beginFill(0xFFFF0B);
this.drawRect(10, 10, 20, 20);
this.endFill();
}
In my scene I create this with
this.worldObjects = this.add.group();
let obj = new WorldObject(this);
this.worldObjects.add(obj);
However when I run this code I get the error beginFill is not a function, from within the constructor in my extended class.
Does anyone have any pointers on what I am doing wrong here?
Thanks
samme
October 9, 2019, 6:19pm
2
That is the class from which my object extends, so it is definitely using the Phaser 3 API
The developer in the link below has done what I am trying to do. So it must have worked at some point. Unless this functionality has since been removed.
I’m new to phaser and I have a custom class that extends Graphics. I want to trigger a function when the object is clicked. The code shown below draws the unit but never registers any events.
If instead, I try passing “this” to setInteractive then the onClick fires any time the mouse is over any part of the canvas. Is there a way to specify a hit box for registering clicks?
Thanks!
class Unit extends Phaser.GameObjects.Graphics {
constructor(scene, x, y, stats){
super(scene, x…
samme
October 10, 2019, 3:47pm
4
The class is right, but there are no beginFill()
or endFill()
methods. You need fillRect() .