Hey guys,
I have a most irritating problem with an IT assignment that is due in in less than just over 24 hours (i’m in grade 10).
For this assignment I have made a flash game in which you control a car and ‘avoid the obstacles’. (I’ve designed it to make it look like you’re moving). The car moves with the arrow keys and the WASD keys like it’s supposed too, but! It only does this for the first map (doesn’t matter which one).
The movement of the car is based on a grid. The car is 50 pixels high and the obstacles 50 pixels high, so obviously the car moves 50 pixels in any direction. However, once you have been in any map that involves the car moving (any at all), if you go back and then into another car moving map the car will move at the previous pixel length (50 for example) plus 50! I have written the script in Flash MX 2004 and it looks like this:
var myListener:Object = new Object();
myListener.onKeyDown = function () {
keypress=String.fromCharCode(Key.getAscii());
switch (keypress) {
case 'a':
car_mc._x -=_global.carmovement;
break;
case 'd':
car_mc._x +=_global.carmovement;
break;
case 'w':
car_mc._y -=_global.carmovement;
break;
case 's':
car_mc._y +=_global.carmovement;
break;
default:
//do nothing
}
}
Key.addListener(myListener);
var myListener:Object = new Object();
myListener.onKeyDown = function () {
keypress=Key.getCode();
switch (keypress) {
case 37:
car_mc._x -=_global.carmovement;
break;
case 39:
car_mc._x +=_global.carmovement;
break;
case 38:
car_mc._y -=_global.carmovement;
break;
case 40:
car_mc._y +=_global.carmovement;
break;
default:
//do nothing
}
}
Key.addListener(myListener);
This script is probably wrong but I NEED HELP GUYS!