JLauchlan Posted May 17, 2014 Share Posted May 17, 2014 Hello all, trying to move player to an array value, anyone got any advice on how I can do this? Thanks in advance 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 More sharing options...
Videlais Posted May 17, 2014 Share Posted May 17, 2014 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 More sharing options...
jpdev Posted May 18, 2014 Share Posted May 18, 2014 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. JLauchlan 1 Link to comment Share on other sites More sharing options...
jpdev Posted May 18, 2014 Share Posted May 18, 2014 Encountered a tween-bug (posted here). But with a workaround it's working fine: http://jppresents.net/static/examples/boardgame/ Click the yellow dice to play. Sourcecode: http://jppresents.net/static/examples/boardgame/game.js I hope you like it JLauchlan, Heppell08 and iShellz 3 Link to comment Share on other sites More sharing options...
JLauchlan Posted May 18, 2014 Author Share Posted May 18, 2014 Appreciate the help guys, ill do what I can to get it working, many thanks. Link to comment Share on other sites More sharing options...
Recommended Posts