help with mouse detection
Hi everyone, im really beginning in actionscript 3, so here we go : im trying to do a shooter kind of game that you have a hero at the bottom that can move left and rigth and you also use the mouse to shoot. But here si my problem (there many in the code).
I want the hero to move left and rigth, no problem thats nailed, but i want the hero to face left if the mouse is a certain amount of pixels from is ex and the same thing rigth. But my code here work with the left but when he go to the rigth it inverse the value ???? dont know why. Also the code always loop the animation if i do not move the mouse!!!! Here my code please somebody help me!!!!
var Key:KeyObject = new KeyObject(stage);
Mouse.hide();
var hs:Number=5;
var limitRight:Number=hero.x+hero.width+100;
var limitLeft:Number=hero.x-50;
//adding de target cursor
var Cible:MovieClip = new cible();
Cible.x=mouseX;
Cible.y=mouseY;
addChild(Cible);
//playing with cloud & adding mouse
var cloudSpeed:Number=2;
var cloudSpeedVar:Number=2;
stage.addEventListener(Event.ENTER_FRAME,onEnter);
function onEnter(e:Event):void
{
//playing with the mouse for target
Cible.x=mouseX;
Cible.y=mouseY;
trace(mouseX);
//adding cloud
smallCloud.x -=cloudSpeed;
smallCloud2.x -=cloudSpeed;
if(smallCloud.x < -295)
{
smallCloud.x = 555;
smallCloud.y = Math.random()*4;
cloudSpeed=Math.random()*cloudSpeedVar;
}
if(smallCloud2.x < -780)
{
smallCloud2.x = 780;
smallCloud2.y = Math.random()*4;
}
//controlling the hero
if (Key.isDown(Key.A))
{
hero.scaleX = 1;
hero.x -= hs;
hero.gotoAndStop('walk');
}
else if(mouseX
Copyright Gary Rosenzweig
