Jump to content

Move sprite to array! Help!


Recommended Posts

Hello all, trying to move player to an array value, anyone got any advice on how I can do this?


Thanks in advance :D


The player movement is based on a dice roll total for a Snakes and Ladders game. So not trying to move the player at x,96 just want to place the sprite at location 4 if dice total is 4 etc. 

    if(player.moved) {
        //move player to new pos
        console.log("The player needs to be moved " + player.moved + " by this many places: "  + player.number);
        player.position += player.number;
    var location = new Array (100);
    //first row (Right to Left)
    location[1] = player.position.x=0,player.position.y=864;
    location[1] = serverPlayer.position.x=0,serverPlayer.position.y=864;
    location[2] = player.position.x=96,player.position.y=864;
    location[2] = serverPlayer.position.x=96,serverPlayer.position.y=864;
    location[3] = player.position.x=192,player.position.y=864;
    location[3] = serverPlayer.position.x=192,serverPlayer.position.y=864;
Link to comment
Share on other sites

Well, for the array, one solution might be to have Phaser.Point objects be at those positions and just save/adjust their property values each time.

location[1]['player'].x = 0;location[1]['player'].y = 864;location[1]['server'].x = 0;location[1]['server'].y = 864;

Something else to consider is a function that calls a lookup-table like this and returns a Phaser.Point. That way, you only need to write your logic once and can return the new object, using it as the property of another object.

//Assuming 'position' is just a Phaser.Point property on playerplayer.position = getPlayerPosition(diceTotal);//Assuming 'position' is just a Phaser.Point property on serverPlayerserverPlayer.position = getServerPosition(diceTotal);
Link to comment
Share on other sites

Argh.. I just wrote a (I think cool) example on how to do it and use tweens to animate it.. then managed to close my browser and lost it.

Out of spite (against my browser operating skills) I will now write it again in webstorm and post functioning code.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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