简体   繁体   中英

HTML5 Multiplayer Browser Game

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.

I think you may be interested in this article. It is an example of making online multiplayer game with NodeJS. It reveals some concepts as well as gives the actual code.

You have 2 possibilities within the simple ones: 1- refresh automatically the page of both users periodically - not very fancy 2- use ajax to query the server of a possible move from the other player

The option 2 would work well if it is a turn-by-turn game. In case of online game, I think you would need much more complex server technology like Node.js for instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM