如何在动作脚本3

时间:2016-03-15 11:27:28

标签: actionscript-3 flash

首先,很抱歉问这样一个愚蠢的问题。我是as3的新手。我正在以无聊的方式让英雄感动。我有3个动画。 1待机模式2步行前方和3步行。到目前为止运作良好,但我在jump.player面临的问题必须按住跳跃的关键。我不希望玩家拿着钥匙进行跳跃。它可以行走,但不会采取其他行动。

所以我想用一键按下完整动画,说实话,我不知道我必须使用哪种功能或如何操作。

这是我的代码

import flash.display.Stage;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.events.Event;



kim.gotoAndStop("kim Stand");

var dPressed:Boolean = false;
var aPressed:Boolean = false;
var wPressed:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN , keyDownHandaler);
stage.addEventListener(KeyboardEvent.KEY_UP , KeyUpHandaler);
stage.addEventListener(Event.ENTER_FRAME , gameLoop);


function keyDownHandaler(Devent:KeyboardEvent):void

{
    if (Devent.keyCode == Keyboard.D)
        {
            dPressed = true;
        }
    else if (Devent.keyCode == Keyboard.A)
        {
            aPressed = true;
        }
    else if (Devent.keyCode == Keyboard.W)
        {
            wPressed = true;
        }
}


function KeyUpHandaler (Uevent:KeyboardEvent):void 

{
if (Uevent.keyCode == Keyboard.D)
    {
        dPressed = false;
        kim.gotoAndStop("kim Stand");
    }
else if(Uevent.keyCode == Keyboard.A)
    {
        aPressed = false;
        kim.gotoAndStop("kim Stand");
    }
else if(Uevent.keyCode == Keyboard.W)
    {
        wPressed = false;
        kim.gotoAndStop("kim Stand");
    }


}

function gameLoop (Gevent:Event):void

{

if (dPressed)
    {
        kim.x += 5;
        kim.gotoAndStop("kim Move Right");
    }
else if(aPressed)
    {
        kim.x -= 5;
        kim.gotoAndStop("kim Move Left");
    }
else if(wPressed)
    {
        kim.gotoAndStop("kim Jump");
    }

}

1 个答案:

答案 0 :(得分:0)

假设您在keyFrame 5和10之间的kim MovieClip中的帧标签“kim Jump”上有一个完整的动画,你可以做类似的事情

// this will check if the jumping animation is already playing if the user press and holds the jump key and disable steerings
var jumping:Boolean;

function gameLoop (Gevent:Event):void
{

if (dPressed)
{
    kim.x += 5;

    if(!jumping)
        kim.gotoAndStop("kim Move Right");
}
else if(aPressed)
{
    kim.x -= 5;

    if(!jumping)
        kim.gotoAndStop("kim Move Left");
}
else if(wPressed)
{
    if(!jumping)
        kim.gotoAndPlay("kim Jump");

    jumping = true;
}

}

在跳跃动画的最后一帧你需要

_parent.jumping = false;
gotoAndStop("Your label for no animation");