I feel like this should be a simple answer but I am new here and struggling…
How do I reference the gameobject metrus (created with the Metrus class) to do things with it after it has been created? I need to reference each object individually to do things with it specifically using its ID.
My GameScene:
var metrus = [];
class Metrus extends Phaser.Physics.Arcade.Image {
constructor(scene, x, y, motion, direction, distance, id) {
super(scene, x, y, 'metrustotalsprite', direction.offset);
this.id = id;
this.name = id;
this.startX = x;
this.startY = y;
this.distance = distance;
this.scene = scene;
this.setDataEnabled();
this.data.set('id', id);
var unitSprite = this.scene.matter.add.gameObject(this, { shape: 'circle', width: 30, height: 30, circleRadius: 15}).setName(id);
unitSprite.displayWidth = 30;
unitSprite.displayHeight = 30;
unitSprite.scale = 0.4;
}
}
class GameScene extends Phaser.Scene {
constructor() {
super('GameScene')
}
preload () {
//ASSET PRELOAD HERE, ETC
}
create () {
//I CREATE MY WORLD TILES HERE AND OTHER SIMPLE FUNCTIONS
//THEN I GO THROUGH AN AJAX CALL TO GET DATA FOR THIS:
thisUnit = metruss.push(this.add.existing(new Metrus(this, centerX + txOffset, centerY + tyOffset, unitAction, unitDirection, 150, unitId)));
}
}