public function keyD(p:KeyboardEvent):void
{
trace(p.keyCode);
//a=65 d=68 w=87 s=83
//to program the 4 arrow keys
if (p.keyCode==Keyboard.LEFT)
{
vx=-5;
}
else if (p.keyCode==Keyboard.RIGHT)
{
vx=5;
}
else if (p.keyCode==Keyboard.UP)
{
vy=-5;
}
else if (p.keyCode==Keyboard.DOWN)
{
vy=5;
}
}
public function keyU(e:KeyboardEvent):void
{
//we want to program the 4 arrow keys
if (p.keyCode==Keyboard.LEFT) //Make player move left
{
vx=0;
}
else if (p.keyCode==Keyboard.RIGHT) //Make player move right
{
vx=0;
}
else if (p.keyCode==Keyboard.UP) //Make player move up
{
vy=0;
}
else if (p.keyCode==Keyboard.DOWN) //Make player move down
{
vy=0;
}
}
public function gameLoop(e:Event):void
{
//this function is called 24 times each second
p.x+=vx;//move the player horizontally
p.y+=vy;//move the player vertically
答案 0 :(得分:4)
keyU
中的参数名为e
,而不是p
,因此您的switch-case运算符会将null与某些内容进行比较。将e
替换为p
或将所有p
替换为e
s。