0

对编程相当陌生,慢慢掌握它。我遇到了一个问题,我花了几个小时试图解决,但似乎无法得到我正在寻找的结果。我为我的角色制作了跑步动画。他向左、向上、向下、向右、向上、向下、向右奔跑,但向上向左和向下向左跑,动画不播放。他朝正确的方向移动,但正在播放的动画是 upRight 和 downRight。我已将 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;
        }


    }


}

}

4

1 回答 1

0

乍一看,我没有发现您的代码有任何问题。我总是建议不要使用标签作为框架,而是使用它们的数字。函数“goUp”和“goDown”的名称暗示了错误的方向,我将它们更改为“goVertical”和“goHorizo​​ntal”。leftPressed, rightPressed, ... 变量是如何设置的?您是否尝试过在每个“if”中添加跟踪,以查看问题是执行了错误的 if 块还是动画处理错误?您是否仔细检查了框架的名称并使用它们各自的编号进行了尝试?

于 2012-08-12T18:50:10.373 回答