多人html5游戏中的Lance.gg不同步

时间:2018-05-17 04:34:53

标签: javascript html5 game-engine multiplayer lance

我正在尝试制作multiplayer game in HTML5。我找到了lance.gg并且玩耍。我像这样修改了Pong游戏。

  • 删除Paddle(仅剩下Ball)
  • 将重力设置为(0, 0.1)
  • 每次键盘输入空格键设置Ball.velocity.y = -3

这是结果https://youtu.be/MmQOqR71Df0。正如您所看到的,它并没有真正在窗口上同步。如何让它在众多玩家之间顺利移动?

1 个答案:

答案 0 :(得分:1)

The Ball.js class defines the following getter:

get bendingVelocityMultiple() { return 0.0; }

This instructs the client to ignore the server's velocity updates. The result is that the client and server velocities fall out-of-sync, and results in the video you captured.

If you set instead:

get bendingVelocityMultiple() { return 0.8; }

Then the problem will go away. Having bendingVelocityMultiple set to zero might be useful in other cases though, for example if you want to transplant the ball back to the center when a player has lost.

Take a look at the documentation for GameObject

的文字居中