i have a character that is 64x64 pixels that i want to move along the x,y axis by clicking on a spot with the mouse. the character should move in increments of 64 pixels.
i have a character that is 64x64 pixels that i want to move along the x,y axis by clicking on a spot with the mouse.
the character should move in increments of 64 pixels.
Here is what i have.
// Mouse Controls
var iswalking = false; // is the character moving?
var goX = F1MC.x; // goX - the point on the X axis to which char must move
var goY = F1MC.y; // same as goX but on the Y axis
trace(goX)
trace("Char Start X");
trace(goY)
trace("Char Start Y");
var dir = "down"; // current direction of movement
stage.addEventListener(MouseEvent.CLICK, setposition);
// set the position to which char must move on click
function setposition(MouseEvent)
{
goX = mouseX
goY = mouseY
trace(goX)
trace("Mouse Click Position X");
trace(goY)
trace("Mouse Click Position Y");
}
The part below is in the Game Loop
// Mouse Click Movements
if(iswalking == false)
{
if(dir == "Down")
{
F1MC.gotoAndStop("F1 Stand Down Frame");
}
else if(dir == "Up")
{
F1MC.gotoAndStop("F1 Stand Up Frame");
}
else if(dir == "Left")
{
F1MC.gotoAndStop("F1 Stand Left Frame");
}
else if(dir == "Right")
{
F1MC.gotoAndStop("F1 Stand Right Frame");
}
}
// Move Down
if((goY-WalkSpeed) > F1MC.y)
{
F1MC.y += WalkSpeed;
F1MC.gotoAndStop("F1 Walk Down Frame");
dir = "Down";
}
// Move Up
else if((goY+WalkSpeed) < F1MC.y)
{
F1MC.y -= WalkSpeed;
F1MC.gotoAndStop("F1 Walk Up Frame");
dir = "Up";
}
// Move Right
else if((goX-WalkSpeed) > F1MC.x)
{
F1MC.x += WalkSpeed;
F1MC.gotoAndStop("F1 Walk Right Frame");
dir = "Right";
}
// Move Left
else if((goX+WalkSpeed) < F1MC.x)
{
F1MC.x -= WalkSpeed;
F1MC.gotoAndStop("F1 Walk Left Frame");
dir = "Left";
}
else
{
iswalking = false;
}
