Note that there are some explanatory texts on larger screens.

plurals
  1. PONode/Socket IO Multiple Players
    primarykey
    data
    text
    <p>I am using node &amp; socketi IO to create a simple multiplayer game. When a new client joins, I create a new HTML element with an ID which is each clients socket.id.</p> <p>The clients are mobile devices, and when they move, I'm sending the 'deviceorientation' values, hoping to give each client control over one of the HTML elements. I'm doing something incorrectly though, which I can't quite figure out, as all that happens is all the clients fight for control over the newest HTML element, rather than having control over the HTML element with their own socket id.</p> <p>On the server:</p> <pre><code>servio.on('connection', function (socket) { servio.sockets.emit('newplayer',socket.id); socket.on('move', function(data) { socket.broadcast.emit('clientmove', data); console.log(data.myid); }); }); </code></pre> <p>On the client:</p> <pre><code>iosocket.on('newplayer', function(data) { myid = data; $('body').append('&lt;div class="dot _jsDot" id="'+myid+'"&gt;&lt;/div&gt;'); }); window.addEventListener("deviceorientation", handleOrientation, true); function handleOrientation(event) { var absolute = event.absolute; var alpha = event.alpha; var beta = event.beta; var gamma = event.gamma; vals = { betaVal : beta, gammaVal : gamma, myid : myid } iosocket.emit('move', vals); } iosocket.on('clientmove', function(data) { var x = Math.round(data.gammaVal)*3; var y = Math.round(data.betaVal)*3; $('#'+data.myid+'').css({'left':x + $(window).outerWidth()/2}); $('#'+data.myid+'').css({'top':y + $(window).outerHeight()/2}); }); </code></pre> <p>I'm hoping I'm overlooking something small rather than some fundamental mess up. If anyone more experienced with node &amp; socket io can offer some advice, that would be great.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload