Hey guys, has anyone ever made a script or have any idea on how could I achieve 4 directions movements using click?
It's similar to the MMORPG called Tibia. I want the player to go Up, Down, Left or Right only, no diagonal directions.
This is my current piece of code:
function updatePlayerPosition(moveType, player, eventData){
var playerPos = player.getPosition();
// 0 = Click / 1 = Keys
if (moveType === 0){
// Mouse Click Moving
var x = eventData.screenPosition.x;
var y = eventData.screenPosition.y;
player.moveTo(x, y, 200);
} else if (moveType === 1){
// Keyboard W A S D
var key = eventData.charName;
switch (key.toUpperCase()) {
case "A":
player.playAnimation('walkLeft', 'ping-pong');
player.setVelocity(-playerMove, 0);
break;
case "D":
player.playAnimation('walkRight', 'ping-pong');
player.setVelocity(playerMove, 0);
break;
case "W":
player.playAnimation('walkUp', 'ping-pong');
player.setVelocity(0, -playerMove);
break;
case "S":
player.playAnimation('walkDown', 'ping-pong');
player.setVelocity(0, playerMove);
break;
default: null
}
} else if (moveType === 2){
// Player Stopped
player.setVelocity(0, 0);
player.getSprite().getCurrentAnimation().stop();
}
}
I know I'll probably have to get the lastPosition and the clickPosition and make some kind of comparisson, but I'm not sure which, any clues on this?
Thanks in advance!