Hey everyone I have a little project that has a circle and when you click somewhere on the stage the circle will move to where you click.
here is the problem I can not seem to figure out how to show what the circles coords are.
I have tired
trace (character_mc.x);
trace (character_mc.y);
now my stage is 480x320 and the trace shows 150.1 and 108.1 and then when i click and my char moves across the screen the trace shows 150.15 and 108.15
it should be changing by a lot more right?
Also if i just click in the same spot and he doesn’t even move the trace numbers will just keep going up by .05
what the heck is going on?
I have attached all my code
Actionscript Code:
import flash.events.Event;
import flash.display.MovieClip;
import flash.events.MouseEvent;
character_mc["charAngle"] = 0;
character_mc["moveX"] = 0;
character_mc["moveY"] = 0;
character_mc["walkSpeed"] = 3;
var characterEndMC:MovieClip = new charEndMC();
function charLoop(event:Event)
{
if (character_mc.hitTestPoint(character_mc["charEnd"].x, character_mc["charEnd"].y, true))
{
character_mc["moveX"] = 0;
character_mc["moveY"] = 0;
this.removeChild(character_mc["charEnd"]);
character_mc.removeEventListener(Event.ENTER_FRAME, charLoop);
}
for (var i:int = 0; i < this.numChildren; i++)
{
this.getChildAt(i).x -= character_mc["moveX"];
this.getChildAt(i).y -= character_mc["moveY"];
}
character_mc.x += character_mc["moveX"] + .05;
character_mc.y += character_mc["moveY"] + .05;
}
function lookAtMouse()
{
var characterMC:MovieClip = character_mc;
characterMC["charAngle"] = Math.atan2(this.mouseY - characterMC.y, this.mouseX - characterMC.x) / (Math.PI / 180);
characterMC.rotation = characterMC["charAngle"];
}
function charMove(event:MouseEvent)
{
lookAtMouse();
this.addChild(characterEndMC);
characterEndMC.x = this.mouseX;
characterEndMC.y = this.mouseY;
character_mc["charEnd"] = characterEndMC;
character_mc["moveX"] = Math.cos(character_mc["charAngle"] * Math.PI/180) * character_mc["walkSpeed"];
character_mc["moveY"] = Math.sin(character_mc["charAngle"] * Math.PI/180) * character_mc["walkSpeed"];
character_mc.addEventListener(Event.ENTER_FRAME, charLoop);
}
stage.addEventListener(MouseEvent.CLICK, charMove);
stage.addEventListener(MouseEvent.CLICK, charPos);
function charPos(e:MouseEvent)
{
trace (character_mc.x);
trace (character_my.y);
}
Thanks