oom1993 Posted June 19, 2018 Share Posted June 19, 2018 socket.on('bulletFromServ',function(bullet){ activeBullets[bullet.id][bullet.num] = game.add.sprite(connectedSprites[bullet.id].x - 8,connectedSprites[bullet.id].y - 8, 'bulletSprite'); game.physics.arcade.enable(activeBullets[bullet.id][bullet.num]); game.physics.arcade.moveToXY(activeBullets[bullet.id][bullet.num], bullet.xDest, bullet.yDest, 300); }); Hi, i am having an issue with socket IO together with the moveToXY physics method. When the client receives the "bulletFromServ" message above. I try to initialize a sprite and then use the information sent with the bullet parameter to fill in the parameters of the moveToXY method. However, the sprites are created in the correct position but do not move at all. This snippet of code is within the create function but i have also tried using it in the update function with no luck. I use the moveToXY function in the below code which doesnt involve a socket call and it works fine. The snippet below also includes the emit to the server with the bullet details. Any ideas why the sprite is rendered but does not move to the position i specify with the moveToXY call? if(!firstFired){ activeBullets[socket.id] = [game.add.sprite(connectedSprites[socket.id].x - 8,connectedSprites[socket.id].y - 8, 'bulletSprite')] firstFired= true; }else{ activeBullets[socket.id].push(game.add.sprite(connectedSprites[socket.id].x - 8,connectedSprites[socket.id].y - 8, 'bulletSprite')); } activeBullets[socket.id][activeBullets[socket.id].length-1].checkWorldBounds = true; activeBullets[socket.id][activeBullets[socket.id].length-1].outOfBoundsKill = true; game.physics.arcade.enable(activeBullets[socket.id][activeBullets[socket.id].length-1]); game.physics.arcade.moveToXY(activeBullets[socket.id][activeBullets[socket.id].length-1], game.input.mousePointer.x, game.input.mousePointer.y, 300); socket.emit('bullet', {id:socket.id, x:activeBullets[socket.id][activeBullets[socket.id].length-1].x, y:activeBullets[socket.id][activeBullets[socket.id].length-1].y, xDest:game.input.mousePointer.x, yDest:game.input.mousePointer.y, num:activeBullets[socket.id].length-1 }); Thanks Link to comment Share on other sites More sharing options...
oom1993 Posted June 19, 2018 Author Share Posted June 19, 2018 I managed to find the issue. I'n the socket IO segment i never initialized the bullet.ID object to an array like I did in the lower segment of code. Instead, I just immediately added an index. Initializing the object with an array seemed to fix it. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts