如何在没有窗口的情况下运行Phaser引擎?

我目前正在使用HTML5框架Phaser创build一个多人游戏。

这是一个僵尸在地图上产生的游戏,玩家必须射杀他们。 僵尸的目标是最接近他们的玩家。

目前,我在devise策略上遇到了一个问题。 由于运动跟踪,我不确定这种types的游戏是否可以使用Phaser。

目前,客户端正在处理所有的玩家移动,所以无论何时玩家移动,它都会将其广播到服务器,并将其发送给所有其他客户端。

不过,我想僵尸和子弹是由服务器专门控制的。 服务器然后更新每个客户端与每个僵尸的速度和他们的当前位置。 我的推理是,任何不是玩家input的东西都应该由服务器来计算。 这样可以防止两个客户说僵尸在不同时间死亡,然后尝试彼此交stream,在不同地点同时发射子弹,或者僵尸在客户之间的不同时间产卵。

这是一个僵尸类的例子:

function Zombie(game, data){ this.game = game; this.id = data.id; Phaser.Sprite.call(this, this.game, data.x, data.y, 'zombie'); this.anchor.setTo(0.5,0.5); this.animations.add('right', [0,1,2,3], 7, true); this.animations.add('left', [4,5,6,7], 7, true); this.game.physics.arcade.enable(this); this.body.collideWorldBounds = true; this.health = data.health; this.maxHealth = data.maxHealth; this.speed = data.speed; this.target = this.game.player; this.waiting = 100; this.name = "zombie"; this.healthBary = 20; this.healthBar = this.game.add.sprite(this.x, this.y + this.healthBary, 'player_health'); this.healthBar.anchor.setTo(0.5, 0.5); CollisionManager.addObjectToGroup(this, 'baddies'); this.game.add.existing(this); } Zombie.prototype = Object.create( Phaser.Sprite.prototype ); Zombie.prototype.constructor = Zombie; Zombie.prototype.update = function(){ this.updateHealthBar(); this.moveTowards(this.target); Zombie.prototype.uTarget = function(target) { this.target = target; }; Zombie.prototype.moveTowards = function(target){ var x = target.x - this.x; var y = target.y - this.y; var mag = Math.sqrt((x * x) + (y * y)); var nx = x / mag; var ny = y / mag; this.body.velocity.x = nx * this.speed; this.body.velocity.y = ny * this.speed; if(this.body.velocity.x >= 0){ this.animations.play('right'); } else if(this.body.velocity.x < 0){ this.animations.play('left') } } Zombie.prototype.updateHealthBar = function(){ this.healthBar.x = this.x; this.healthBar.y = this.y + this.healthBary; var p = (this.health / this.maxHealth); p = parseFloat(p.toFixed(1)); this.healthBar.frame = 10 - (p * 10); } Zombie.prototype._damage = function(amount){ this.health -= amount; if(this.health <= 0){ this.kill; this.die(true); } } Zombie.prototype.die = function(points){ if(this.game){ //this.game.baddie_die_sfx.play(); } WaveManager.onMap--; CollisionManager.removeObjectFromGroup(this, "baddies"); if(this.healthBar){ this.healthBar.destroy(); } socket.emit("kill zombie", {id: this.id}); this.kill(); this.destroy(); } 

问题是我无法在服务器上创buildPhaser游戏对象(因为它在Linux服务器上运行),因为没有可以使用的窗口。 为了碰撞检测,子弹和僵尸需要是Phaser对象,但是我不能在服务器上这样做。

我知道我可以创build一个僵尸和子弹的服务器端vector,每个子弹/僵尸的位置在任何给定的时间的信息,然后更新客户端,但后来我将无法使用Phaser中的CollisionManager 。

现在看来,我唯一的解决办法就是创build我自己的碰撞检测系统。 有其他的想法吗?

我也在寻找答案。 Phaser论坛的pipe理员表示,这将是不可能的,没有黑客入侵。 请参阅这篇文章和另一篇文章