I'm making a game with simple mouse control. Basically, if the player moves the cursor to the right of the character, he moves right and vice versa. But if you stop moving the mouse, Flash ignores a condition which stops the character until you move the mouse again, so the guy just keeps moving in the same direction until you move the cursor. Why is this happening if mouseX and the player's position are being updated each frame? Here are the input conditions:
stage.addEventListener(MouseEvent.MOUSE_MOVE, CTRLupdateMousePosition)
private function CTRLupdateMousePosition(e:Event):void
{
if (mouseX > shaman_legs.x-2 - shaman_legs.width / 2 && mouseX < shaman_legs.x+2 + shaman_legs.width / 2) {
CTRLleftButtonDown = false
CTRLrightButtonDown = false
} else if (mouseX < shaman_legs.x - shaman_legs.width / 2 && GlobalVariableLibrary.COREgamePaused == false) {
CTRLleftButtonDown = true
CTRLrightButtonDown = false
} else if (mouseX > shaman_legs.x + shaman_legs.width / 2 && GlobalVariableLibrary.COREgamePaused == false) {
CTRLleftButtonDown = false
CTRLrightButtonDown = true
}
}
And here is the code that responds to player's input by moving the character and playing animation:
addEventListener(Event.ENTER_FRAME, playerControl)
private function playerControl(e:Event):void {
trace("LeftDown:"+CTRLleftButtonDown, "RightDown:"+CTRLrightButtonDown)
boxSensor.x = shaman_legs.x
soulCatcher.x = shaman_legs.x
if (CTRLleftButtonDown == false && CTRLrightButtonDown == false && GlobalVariableLibrary.COREgamePaused == false) {
shaman_legs.gotoAndPlay("idle")
shaman_armsDown.gotoAndPlay("idle")
} else if (CTRLleftButtonDown && shaman_legs.x > 40 && GlobalVariableLibrary.COREgamePaused == false) {
shaman_legs.gotoAndPlay("walkLeft")
shaman_armsDown.gotoAndPlay("walk")
shaman_legs.x -= GlobalVariableLibrary.CHARspeed
shaman_mask.x -= GlobalVariableLibrary.CHARspeed
shaman_armsDown.x -= GlobalVariableLibrary.CHARspeed
shaman_armsUp.x -= GlobalVariableLibrary.CHARspeed
} else if (CTRLrightButtonDown && shaman_legs.x < 760 && GlobalVariableLibrary.COREgamePaused == false) {
shaman_legs.gotoAndPlay("walkRight")
shaman_armsDown.gotoAndPlay("walk")
shaman_legs.x += GlobalVariableLibrary.CHARspeed
shaman_mask.x += GlobalVariableLibrary.CHARspeed
shaman_armsDown.x += GlobalVariableLibrary.CHARspeed
shaman_armsUp.x += GlobalVariableLibrary.CHARspeed
}
}