1

I am having difficulty with one part of my simple HTML5 game. I've decided to make it multiplayer. How do I go about making a change to the position of a div on my screen visible on the other users screen?

It's a two player game, with a simple move left and move right function to move divs. My first thought was to use sessions, but when I got to writing some code, I realised I knew nothing, so I headed over to CSS Tricks (couldn't find anything for my use), headed over to Dave Walsh (nothing listed) and couldn't find anything of use on Google, no matter what search term I put in.

I know this is possible with modern browsers as I've seen it done in a lot of games online now, however I'm baffled as to how it's done.

Any answer with some links would be greatly appreciated.

4

2 回答 2

3

我想你可能对这篇文章感兴趣。这是一个使用 NodeJS 制作在线多人游戏的例子。它揭示了一些概念并给出了实际代码。

于 2013-07-30T15:27:29.570 回答
1

在简单的情况下,您有 2 种可能性: 1- 定期自动刷新两个用户的页面 - 不是很花哨 2- 使用 ajax 查询来自其他玩家的可能移动的服务器

如果是回合制游戏,选项 2 会很有效。对于在线游戏,我认为您需要更复杂的服务器技术,例如 Node.js。

于 2013-07-30T15:16:01.060 回答