Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7190311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:29:12+00:00 2026-05-28T19:29:12+00:00

I have a question which I cannot find an answer to. I’m experimenting with

  • 0

I have a question which I cannot find an answer to.

I’m experimenting with building a multiplayer game with Node.JS and Socket.IO. I have built a chat room as my first experiment, so I have broadcasts working etc. Now I’m at the point where I want to get something working with Canvas.

The problem I’m having is getting my head around multiple and independent players. I know that each player will send their x,y cords to the server and the server will broadcast those, but how does the client know how many players to display, I’m guessing they have to be stored in an array somewhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:29:13+00:00Added an answer on May 28, 2026 at 7:29 pm

    My implementation will be very naive and simplified, no lag compensation, extrapolation and such, but it should point out a general conception of “multiplayering” with node.

    I think the simplest approach is to have an associative array containing players(entities) on both client and server. Then from client side you send commands like {action: "move", target:[32, 100]} and process this command with server logic (where the real game is running). To each socket on connection you should assign a player object or id so you can access it like:

    var lastPlayerID = 0;
    var players = {};
    
    server.on("connection", function(socket) {
    
      var newcommer = new Player({id: lastPlayerID});      
      players[lastPlayerID] = newcommer;
      socket.player = newcommer; // or lastPlayerID
      lastPlayerID++;      
    
      socket.onMessage = function(message) {
        this.player.doSomething(); 
      }
    
    });
    

    Then each let’s say 100ms you could send snapshots to all connected players:

    {
      timestamp: game.delta,
      players: {
        1: {x: 32, y: 100},
        2: {x: 14, y: 11}
      }
    }
    

    And then at client side receive data and interpolate from old to new values.

    // duration in this simplified example is snapshot sending interval in [ms]
    Player.prototype.interpolateTo = function(data, duration) {
      if(typeof data.x != "undefined") {
        // step needed to get `destination x` within `duration` miliseconds
        this.stepValues.x = Math.abs(data.x - this.x) / duration;
        this.target.x = data.x;
      } 
      // ...
    }
    
    // step you call for each game loop iteration
    Player.prototype.step = function(delta) {
      if(this.x < this.target.x) {
        this.x += delta * this.stepValues.x
      }
    }
    

    This is a sufficient algorithm for a semi-arcade game with 20 objects at maximum. Decreasing snapshot’s interval makes it almost suitable for strategy game with more objects. Your main enemy is bandwidth usage which you can decrease minimizing packet’s size. For instance read about BiSON, LZW and don’t send data which haven’t changed since last snapshot.

    My reputation doesn’t allow me to post all the links, so I have attached them here:
    http://pastebin.com/Kh3wvF1D

    General introduction to multiplayer conceptions by Glenn Fiedler:

    http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/

    Some multiplayer techniques from Quake:
    This will give u a clue about interpolation and extrapolation(prediction)

    http://fabiensanglard.net/quakeSource/quakeSourcePrediction.php

    Valve’s article about latency compensation and general optimisations:

    https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

    Multiplayer techniques in Age of Empires:

    http://zoo.cs.yale.edu/classes/cs538/readings/papers/terrano_1500arch.pdf#search=%22Real%20time%20strategy%20networking%20lockstep%22

    You can also read my article about optimizing bandwidth usage

    http://rezoner.net/minimizing-bandwidth-usage-in-html5-games-using-websocket,299

    +1 for Ivo’s Wetzel Mapple.js it’s a big pile of knowledge.

    https://github.com/BonsaiDen/Maple.js

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple question but cannot find a simple answer. I have
I would have another question I cannot find answer on. I know that the
This might be a noob question, but can't find an answer anywhere. I have
OK, this must be a duplicate question, but I cannot find the answer: I
I have been looking around for an answer to my question but couldn't find
Sorry for the silly question, but I cannot seem to find an answer on
Just small question as I cannot find an answer that resolves my problem. I
I have a question which is described below: What problems would arise for testing
I have a question which I think involves conditional entropy in the field of
I have a question which may be somewhat silly because I'm pretty sure I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.