Jump to content

2 browsers multiplayer game objects revert to starting locations


Recommended Posts

I have a multiplayer game and when testing I open up 2 browsers. Both characters move and I can see that movement on either, but when I click on browser A, the remote character on browser B reverts back to it's starting location. The same happens if I click browser B. I'm not doing any reverting of original position so I'm under the assumption that Phaser is doing this for some reason.


Has anyone ran into this before? The remote clients are added dynamically at run-time. The server is sending each client the remote clients position 5 times a second and I logged this and the values don't change so not sure why the remote clients position gets reset to it's original position.



Here is my remote client addition code if that helps:


function AddRemoteClient(clientID, x, y) {    remoteClients[clientID] = game.add.sprite(x, y, 'player');    remoteClients[clientID].anchor.setTo(0.5, 0.5);    remoteClients[clientID].scale = { x: 2, y: 2 };    game.physics.p2.enable(remoteClients[clientID]);    remoteClients[clientID].body.fixedRotation = true;    remoteClients[clientID].body.setCircle(10, 0, 30);    remoteClients[clientID].animations.add('north.stand', [1], 6, true);    remoteClients[clientID].animations.add('north.walk', [0, 1, 2], 6, true);    remoteClients[clientID].animations.add('east.stand', [4], 6, true);    remoteClients[clientID].animations.add('east.walk', [3, 4, 5], 6, true);    remoteClients[clientID].animations.add('south.stand', [7], 6, true);    remoteClients[clientID].animations.add('south.walk', [6, 7, 8], 6, true);    remoteClients[clientID].animations.add('west.stand', [10], 6, true);    remoteClients[clientID].animations.add('west.walk', [9, 10, 11], 6, true);    remoteClients[clientID].animations.play(playerDir.concat('.stand'));    // add the player to the layer between layer2 and layer3    actorLayer.add(remoteClients[clientID]);}


Link to comment
Share on other sites

There's nothing in Phaser that will reset a Sprite position from one location to another, other than Sprite.reset, and you have to explicitly call that from your code, it doesn't happen automatically.


Has the game paused when you swap from one browser to another? If so you most likely want to disable that.

Link to comment
Share on other sites

OK, I fixed it, but not sure why it works. The remote clients were P2 physics enabled but when their positions come in I just set their direct x/y values (no body work). If I remove the physics from the remote clients (which they don't need anyway but I just copied the code from the local player creation) then it doesn't have this issue.

//game.physics.p2.enable(remoteClients[clientID]);//remoteClients[clientID].body.fixedRotation = true;//remoteClients[clientID].body.setCircle(10, 0, 30);

So this was causing the issue. I'm not sure why though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...