Jump to content

Weird sprite movement render problem


eddieone
 Share

Recommended Posts

Hi, nice to meet everyone here.

 

I have a html5 demo where sprites using P2JS move fine. But for remote players I try to move the x value and the rendering goes all funky.

 

problem.png

 

Should remote players also get rendered using P2JS?

 

Here's the code in question

socket.on('player update', function (data) {  players[data.username] = {username:data.username, posX:data.posX, posY:data.posY};    if(players[data.username].body == undefined){        var character = game.add.sprite(data.posX, data.posY, 'player');        character.scale.set(2);        character.smoothed = false;        players[data.username].body = character;        log('player body added');    }    players[data.username].body.x = data.posX;    players[data.username].body.y = data.posY;  });
Link to comment
Share on other sites

The issue is because you're fighting with the physics calculations, which are also trying to adjust the x and y positions of the objects every frame. I believe in P2 you have to set body.static = true which allows all of the collision stuff to work, but lets you control its position manually.

Link to comment
Share on other sites

Try this?

socket.on('player update', function (data) {  if (players[data.username] && players[data.username].hasOwnProperty('body')) {    players[data.username].body.x = data.posX;    players[data.username].body.y = data.posY;    return;  }  players[data.username] = {username:data.username, posX:data.posX, posY:data.posY};  var character = game.add.sprite(data.posX, data.posY, 'player');  character.scale.set(2);  character.smoothed = false;  players[data.username].body = character;  log('player body added');});

Just changes the way the player and player body is checked a bit. Also, without interpolation, this character will appear to 'jerk' around rather than move smoothly, though I assume you already know that.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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