如何在 Phaser 3 中引用 GameObject

问题描述

我觉得这应该是一个简单的答案,但我是 Phaser 的新手,不擅长使用 javascript 并且正在苦苦挣扎......

如何引用游戏对象 metrus(使用 Metrus 类创建)以在创建后对其进行处理?我需要单独引用每个对象,以便专门使用其 ID 来处理它。

我的游戏场景:

var metrus = [];

class Metrus extends Phaser.Physics.Arcade.Image {

constructor(scene,x,y,motion,direction,distance,id) {
super(scene,'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)));
                                
                                
 }

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)