Jump to content

How to can I update my sprite position according input coordiates


Ashish
 Share

Recommended Posts

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]);

 

Link to comment
Share on other sites

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);
    }

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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