hey guys
this is probably a simple solution but im making a car game and when u complete a level the listener is still sending information even though i stopped listening
heres some code. can you help?
public function startRacing() {
//place girls
placeGirls();
// make sure car is on top
//gamesprite.setChildIndex(gamesprite.car,gamesprite.numChildren-1);
// add listeners
this.addEventListener(Event.ENTER_FRAME,gameLoop);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
//set car loc
gamesprite.car.x = -50;
gamesprite.car.y = 842.0;
gamesprite.car.rotation = -90;
// set up game variables
pointsText.text = String("0");
level = 0;
bounce = 1;
score = 0;
speed = 0;
gameMode = "wait";
timeDisplay.text = "";
gameStartTime = getTimer()+3000;
centerMap();
}
start the game and initialize the listeners
// note key presses, set properties
public function keyDownFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
arrowLeft = true;
} else if (event.keyCode == 39) {
arrowRight = true;
} else if (event.keyCode == 38) {
arrowUp = true;
} else if (event.keyCode == 40) {
arrowDown = true;
}
}
public function keyUpFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
arrowLeft = false;
} else if (event.keyCode == 39) {
arrowRight = false;
} else if (event.keyCode == 38) {
arrowUp = false;
} else if (event.keyCode == 40) {
arrowDown = false;
}
}
recognize the buttons
// game over, remove listeners
public function endGame() {
this.removeEventListener(Event.ENTER_FRAME,gameLoop);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
gotoAndStop("gameover");
}
end the game and destroy the listeners
but when u hit the play again button
the last arrows you pressed are still being sent so the car is moving in circles without any buttons down or anything
any idea?
i can send the whole thing if you need more
thanks