AS3动画将无法播放

时间:2012-08-12 18:41:58

标签: actionscript-3

编程相当新,慢慢掌握它。我遇到了一个问题,我花了几个小时试图修复,但似乎无法得到我正在寻找的结果。我为我的角色制作了动画。他向左,向上,向下,向右,向上,向右,向下运行,但向左和向下左侧动画不播放。他向正确的方向移动,但正在播放的动画是向右和向右。我已经将upLeft和downLeft的动画更改为我的“空闲”动画,它可以正常工作。如果所有其他动画都能正常工作,我不确定为什么会这样。

这是我的播放器动画的代码。任何帮助或建议都会很棒。提前致谢

包{

import flash.display.MovieClip;
import flash.display.*;
import flash.events.*;


public class PlayableCharacter extends Character 
{
    private var dx:int;
    private var dy:int;
    var ready:Boolean;


    public function PlayableCharacter(x:int=0, y:int=0, dx:int = 3, dy:int = 3) 
    {
        // constructor code
        this.x = x;
        this.y = y;

        this.dx = dx;
        this.dy = dy;
        ready = true;
        gotoAndStop("Idle");



        addEventListener(Event.ENTER_FRAME,onEnter);
        addEventListener(Event.ADDED_TO_STAGE, onStage);
    }

    private function onEnter(e:Event)
    {

        //doing animation stuff

        if(!leftPressed && !rightPressed && !downPressed && !upPressed)
        {
            gotoAndStop("Idle");
        }

        //Go Left
        if(leftPressed && !upPressed && !downPressed && !rightPressed)
        {
            //do something left
            goDown(-dx)
            gotoAndStop("Run");
        }

        //Go Right
        if(rightPressed && !upPressed && !downPressed && !leftPressed)
        {
            //do something right
            goDown(dx)
            gotoAndStop("Run");
        }

        //Go Up
        if(upPressed && !leftPressed && !rightPressed && !downPressed)
        {
            goUp(-dy)
            gotoAndStop("RunUp");

        }

        //Go Down
        if(downPressed && !upPressed && !rightPressed && !leftPressed)
        {
            goUp(dy)
            gotoAndStop("RunDown");
        }

        //Go UpRight
        if(rightPressed && upPressed && !leftPressed && !downPressed)
        {
            goDown(dx)
            goUp(-dy)
            gotoAndStop("UpRight");
        }

        //Go DownRight
        if(rightPressed && downPressed && !leftPressed && !upPressed)
        {
            goDown(dx)
            goUp(dy)
            gotoAndStop("DownRight");
        }

        //Go UpLeft
        if(leftPressed && upPressed && !rightPressed && !downPressed)
        {
            goDown(-dx)
            goUp(-dy)
            gotoAndStop("UpLeft");
        }

        // Go Downleft
        if(leftPressed && downPressed && !rightPressed && !upPressed)
        {
            goDown(-dx)
            goUp(dy)
            gotoAndStop("DownLeft");

        }



        if (x > stage.stageWidth)
            x = stage.stageWidth;
        else if (x < 0)
            x = 0;

        if (y > stage.stageHeight)
            y = stage.stageHeight;
        else if (y < 0)
            y = 0;
    }

    public function onStage(e:Event)
    {

    }

        public function goUp(dy:int=0)
    {
        y += dy;


        if(scaleY > 0 && dy < 0)
        {
            scaleY *= 1;
        }
        else if(scaleY < 0 && dy > 0)
        {
            scaleY *= -1;
        }


    }

        public function goDown(dx:int =0)
    {
        x += dx;


        if(scaleX > 0 && dx < 0)
        {
            scaleX *= -1;
        }
        else if(scaleX< 0 && dx > 0)
        {
            scaleX *= -1;
        }


    }


}

}

1 个答案:

答案 0 :(得分:0)

乍一看,我发现你的代码没有任何问题。我总是建议不要使用帧标签,而是使用它们的数字。 函数“goUp”和“goDown”的名称暗示方向错误,我将它们改为“goVertical”和“goHorizo​​ntal”。 leftPressed,rightPressed,...变量是如何设置的?您是否尝试在每个“if”中添加一条跟踪,以查看问题是否执行了错误的if-block或错误地解决了动画?您是否仔细检查了帧的名称,并且可能使用各自的数字进行了尝试?