使用相同的socket.io来区分类

时间:2019-06-15 22:11:03

标签: javascript

我目前正在开发一个带有phaser3的小型node.js游戏。

我不能放this.socket = io();在班级游戏上等于班级inicio。

我在node.js中有一个服务器

当我调用“ this.socket = io()”时,会创建另一个连接,但是我希望已经添加的连接。

class inicio extends Phaser.Scene {
    constructor() {
        super( { key: 'inicio'} );
      }

    upload(){ }

    create(){
        this.socket = io();
        this.f = false;
        this.add.text(100,100,'Space Wars',{font: "bold 100px Arial",fill: '#FFF'});
        const clickButtonRed = this.add.text(250, 300, 'Red', { font: "bold 50px Arial",fill: '#FF0000' })
        .setInteractive()
        .on('pointerdown', () => this.jogo(this.teamt="red") );

        const clickButtonBlue = this.add.text(400, 300, 'Blue', { font: "bold 50px Arial",fill: '#0000FF' })
        .setInteractive()
        .on('pointerdown', () => this.jogo(this.teamt="blue"));     
    }

    jogo(teamt){
     /// this.add.text(100,300,teamt );
     this.f = true;
    }
    update(){
      if(this.f==true){
        this.socket.emit('team',this.teamt); 
        console.log('ya made it'); 
        this.scene.start('game');
      }
    }

}
class game extends Phaser.Scene {

  constructor() {
    super( { key: 'game'} );
  }

  preload(){
    this.load.image('ship', 'assets/spaceShips_001.png');
    this.load.image('otherPlayer', 'assets/enemyBlack5.png');
    this.load.image('star', 'assets/star_gold.png');
  }

  create() {
    var self = this;
    this.socket = io();
}
}```

0 个答案:

没有答案