Ashish Posted September 2, 2016 Share Posted September 2, 2016 Hello everyone, I am new to phaser framework. I am working on a game where I am getting a coordinates for sprites through . The problem is how can I update my sprite according to incoming coordinates? ws.onmessage = function(event) { var mySpan = document.getElementById("messageGoesHere"); var mySpan2 = document.getElementById("messageGoesHere2"); var str = event.data; var array = str.split('|'); mySpan.innerHTML = parseInt(array[2]) mySpan2.innerHTML = parseInt(array[3]); x= parseInt(array[2]); y= parseInt(array[3]); alessandronunes 1 Link to comment Share on other sites More sharing options...
alessandronunes Posted September 2, 2016 Share Posted September 2, 2016 Hello @Ashish, please check this example: http://phaser.io/examples/v2/basics/04-image-follow-input On Update function you can use moveToPointer, moveToXY or moveToObject: function update () { // If the sprite is > 8px away from the pointer then let's move to it if (game.physics.arcade.distanceToPointer(sprite, game.input.activePointer) > 8) { // Make the object seek to the active pointer (mouse or touch). game.physics.arcade.moveToPointer(sprite, 300); } else { // Otherwise turn off velocity because we're close enough to the pointer sprite.body.velocity.set(0); } } Ashish 1 Link to comment Share on other sites More sharing options...
Ashish Posted September 2, 2016 Author Share Posted September 2, 2016 Thank you @alessandronunes for your help . I will try this for sure and I think this will help me a lot. Link to comment Share on other sites More sharing options...
Recommended Posts