微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 Phaser 3 中引用 GameObject

如何解决如何在 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 举报,一经查实,本站将立刻删除。