Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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.

Guest
Sep 23, 2015 Sep 23, 2015

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

TOPICS
ActionScript
720
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Sep 24, 2015 Sep 24, 2015

Never mind solved the problem.  It wasn't the code. I somehow managed to shift the sprite up and left 1 pixel in the scene.  since the origin point for the sprite was the top left corner that 1 pixel shift was enough to be considered 1 block up and 1 block left.  Not sure why it only affected if moving up or left. but re aligning the sprite has solved the issue.

Translate
LEGEND ,
Sep 24, 2015 Sep 24, 2015

What is failing to happen with the code you show?  I would expect that the object will never reach its destination due to not accounting for distances less than the WalkSpeed value, which you say is 64.  Where do you set that value?  How is this code implemented in what you are calling the game loop?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 24, 2015 Sep 24, 2015

Never mind solved the problem.  It wasn't the code. I somehow managed to shift the sprite up and left 1 pixel in the scene.  since the origin point for the sprite was the top left corner that 1 pixel shift was enough to be considered 1 block up and 1 block left.  Not sure why it only affected if moving up or left. but re aligning the sprite has solved the issue.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2016 Feb 01, 2016
LATEST

can i get your project?? only move character. I really need example for that...Thank you very much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines