eddieone Posted July 15, 2014 Share Posted July 15, 2014 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. Should remote players also get rendered using P2JS? Here's the code in questionsocket.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 More sharing options...
lewster32 Posted July 15, 2014 Share Posted July 15, 2014 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 More sharing options...
eddieone Posted July 15, 2014 Author Share Posted July 15, 2014 It looks like it's not a redering problem. It keep adding a sprite because it doesn't see the body property. Any idea why the above code wouldn't work? Link to comment Share on other sites More sharing options...
lewster32 Posted July 15, 2014 Share Posted July 15, 2014 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 More sharing options...
eddieone Posted July 15, 2014 Author Share Posted July 15, 2014 Nice it worked! This is my second javascript project and my first phaser project. I'm a convert from the flash games of last decade. Here's what we made today http://unbounded.nid.io/test It might have some potential. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts