Jump to content

moveToXY with socket.IO problem


Recommended Posts


          activeBullets[bullet.id][bullet.num] = game.add.sprite(connectedSprites[bullet.id].x - 8,connectedSprites[bullet.id].y - 8, 'bulletSprite');


          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?


              activeBullets[socket.id] = [game.add.sprite(connectedSprites[socket.id].x - 8,connectedSprites[socket.id].y - 8, 'bulletSprite')]
              firstFired= true;
                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.moveToXY(activeBullets[socket.id][activeBullets[socket.id].length-1], game.input.mousePointer.x, game.input.mousePointer.y, 300);




Link to comment
Share on other sites

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


  • Recently Browsing   0 members

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