Phaser3 多人服务器/客户端游戏中的碰撞处理

时间:2021-03-25 08:56:22

标签: node.js phaser-framework multiplayer

我有一个关于如何在 Phaser3 多人游戏中处理物理问题的问题。

  1. 我有一个客户端,我正在使用图层加载我的瓦片地图。
  2. 我有一台服务器,负责处理所有游戏物理。

我在尝试处理碰撞时遇到了问题,因为服务器的 game.js 脚本包含物理所在的配置:

const config = {
type: Phaser.HEADLESS,
parent: 'phaser-example',
width: 800,
height: 600,
autoFocus: false,
physics: {
    default: 'arcade',
    arcade: {
        debug: false,
        gravity: { y: 0 }
    }
},
scene: {
    preload: preload,
    create: create,
    update: update
}};
.........
function create() {

const self = this;
this.players = this.physics.add.group();

this.scores = {
    blue: 0,
    red: 0
};

this.star = this.physics.add.image(randomPosition(700), randomPosition(500), 'star');

this.physics.add.collider(this.players);.......

另一方面,我在客户端添加了 tilemap:

function preload() {
this.load.tilemapTiledJSON('map1', 'assets/maps/map1/level1.json');
this.load.image('background', 'assets/maps/map1/background.png');
this.load.image('tiles', 'assets/maps/map1/platformPack_tilesheet.png');

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

function create() {

const backgroundImage = this.add.image(0, 0,'background').setOrigin(0, 0);
backgroundImage.setScale(2, 0.8);

const map = this.make.tilemap({key:'map1'});

const tileset = map.addTilesetImage('platformPack_tilesheet', 'tiles');

const platforms = map.createStaticLayer('Platforms', tileset, 0, 200);
map.setCollisionByExclusion(-1, true);............

问题是我不知道怎么用

physics.add.collider(this.players, this.platforms);

处理碰撞,因为我在客户端没有物理。 我将不胜感激任何有关代码的帮助,或有关移相多人游戏中物理的文章或如何实现它的任何想法。

谢谢。

0 个答案:

没有答案
相关问题