PDA

View Full Version : Script isnt allowing movement


Bdcoll
02-04-2011, 09:12 PM
Hi. Im trying to get this to work so it moves the objects by the defined speeds when the key is down. I cant see any issues with the code at all, yet it still does not work correctly. Any input would be greatly appreciated

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpFunction);
addEventListener(Event.ENTER_FRAME, enterFrameFunc);

var Speed1=-2
var Speed2=-5
var Jump = 1.2
var Gravity = 0.2
var Left,Right,Up,:Boolean = false;

Fence .x=550;
Fence .y=377;
Background .x=550;
Background .y=200
Truck .x=95
Truck .y=355
WheelF .x=132.6
WheelF .y=381.6
WheelR .x= 38.5
WheelR .y=382.5

function keyDownFunction(event:KeyboardEvent) {
if (event.keyCode==37||event.keyCode==65) {
Left=true;
}
if (event.keyCode==39||event.keyCode==68) {
Right=true;
}
if (event.keyCode==38||event.keyCode==87) {
Up=true;
}
}

function keyUpFunction(event:KeyboardEvent) {
if (event.keyCode==37||event.keyCode==65) {
Left=false;
}
if (event.keyCode==39||event.keyCode==68) {
Right=false;
}
if (event.keyCode==38||event.keyCode==87) {
Up=false;
}
}

function moveChar() {
if (Left) {
Background.x-=Speed2;
Fence.x -= Speed1
}
if (Right) {
Background.x+=Speed2;
Fence.x+=Speed1;
}
if (Up) {
Truck.y+=Up;
}
}



function enterFrameFunc(event:Event) {
moveChar();
}