所以我认为这个问题非常清楚。如果播放器按a或d键,则动画片段正常移动。但是如果玩家按A或D并快速释放并按A或D,则该角色将冲刺或冲刺或其他。这是代码:
function key_down(event:KeyboardEvent)
{
switch (event.keyCode)
{
case 65 :
leftKey = true;
break;
case 66 :
punchKey = true;
break;
case 87 :
upKey = true;
break;
case 68 :
rightKey = true;
break;
case 83 :
downKey = true;
break;
case 78 :
jumpKey = true;
break;
case 77 :
kickKey = true;
break;
}
}
function key_up(event:KeyboardEvent)
{
switch (event.keyCode)
{
case 65 :
leftKey = false;
num++;
if(num % 2 ==1){
canRun = true;
}
else {
canRun = false;
}
break;
case 66 :
punchKey = false;
punchButton = true;
break;
case 87 :
upKey = false;
break;
case 68 :
rightKey = false;
break;
case 83 :
downKey = false;
break;
case 78 :
jumpKey = false;
jumpButton = true;
break;
case 77 :
kickKey = false;
kickButton = true;
break;
}
}
if (leftKey || rightKey || downKey || upKey)
{
if (! isJumping && ! isPunching && ! isKicking && ! isRunning )
{
// 5.frame is the walking animation
speed = 7;
hero.gotoAndStop(5);
}
if(! isJumping && ! isPunching && ! isKicking && isRunning ){
// isRunning means that the character is Dashing
// 17.frame is the sprint animation
speed = 10;
hero.gotoAndStop(17);
}
if (leftKey)
{
hero.scaleX = -1;
speedX -= speed;
}
if (rightKey)
{
hero.scaleX = 1;
speedX += speed;
}
答案 0 :(得分:0)
这是逻辑,你必须为你的项目调整它。这适用于多个键btw。
var thresholdTime = 250;
var delaysUntilKeyUp = [];
public function onKeyDown(e):void {
delaysUntilKeyUp[e.keyCode] = getTimer();
switch (event.keyCode) {
case 65 :
//do something
break;
}
}
public function onKeyUp(e):void {
delaysUntilKeyUp[e.keyCode] = getTimer() - delaysUntilKeyUp[e.keyCode];
switch (event.keyCode) {
case 65 :
if( delaysUntilKeyUp[e.keyCode] <= thresholdTime ){
// do something when the key was released quickly
} else {
// do something else, or maybe do nothing
}
break;
}
}