not exactly sure what to call whats going on. I need to create a definition for the clients main player physics body and i can’t read it or any of its properties, no matter where or how i call it, from update(). Also if this is a bit hard to understand Im a young and new JS programmer so bare with me. Im willing to change the construction of my scenes if i need to if anyone recommends something easier.
class MainScene extends Phaser.Scene {
constructor() {
super({ key: 'MainScene' })
}
preload() {
this.load.image('grass','./assets/map.png',);
this.load.spritesheet('graf', './assets/wang.png', { frameWidth: 200, frameHeight: 170})
}
create() {
this.add.image(100,400,'grass');
this.playerMap = {};
Client.askNewPlayer();
window.myScene = this;
this.body = this.matter.bodies.circle(
1,
1,
10,
{
isSensor: true
}
);
}
addNewPlayer(id, x, y) {
if(id == clientID){
this.playerMap[id] = this.matter.add.sprite(x, y, 'graf','', {'shape' : this.body['player-20-00']}).setScale(.5);
this.player = this.playerMap[id];
this.cameras.main.centerOn(this.player.x, this.player.y)
}
else{
this.playerMap[id] = this.add.sprite(x,y,'graf').setScale(.5);
}
}
removePlayer(id){
this.playerMap[id].destroy();
delete this.playerMap[id];
}
movePlayer(id, x, y) {
// var player = this.playerMap[id];
// var distance = Phaser.Math.Distance.Between(player.x,player.y,x,y);
// var duration = distance*10;
// var tween = this.add.tween(player);
// tween.to({x:x,y:y}, duration);
// tween.start();
}
cameraOn(){
this.cameras.main.centerOn(this.player.x, this.player.y)
}
update(){
//haven't been able to access any variables Ive called from here
}
}