AS3 - 如何循环角色动画的状态(移动和停止)

时间:2017-02-09 22:53:57

标签: actionscript-3 flash actionscript

我有一个D-Pad用于我的手机游戏,当按下该角色应该移动时,动画应该从 State-1 交换到 State-2 ,并且不断重复。

我不知道如何将静止动画切换到移动状态,然后经过一段时间后用户可以看到它,它会切换到静止状态,然后再回到移动状态。

这个过程应该继续发生,直到用户放开UP D-Pad或击中我设置的舞台碰撞障碍。

// NOTE: 1 means standing still, 2 means moving in that direction
var down1_anim:MovieClip = new anim_Down1;
var down2_anim:MovieClip = new anim_Down2;
var left1_anim:MovieClip = new anim_Left1;
var left2_anim:MovieClip = new anim_Left2;
var right1_anim:MovieClip = new anim_Right1;
var right2_anim:MovieClip = new anim_Right2;
var up1_anim:MovieClip = new anim_Up1;
var up2_anim:MovieClip = new anim_Up2;


function moveUpTouchDOWN(e:TouchEvent):void
{
    stage.addEventListener(TouchEvent.TOUCH_END,moveUpTouchUP); //listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.
    addEventListener(Event.ENTER_FRAME,moveUp); //while the mouse is down, run the tick function once every frame as per the project frame rate
}

function moveUpTouchUP(e:TouchEvent):void
{
    removeEventListener(Event.ENTER_FRAME,moveUp);
    stage.removeEventListener(TouchEvent.TOUCH_END,moveUpTouchDOWN);
    // when FINGER LIFTED play up1_anim (stop movement animation)
    if(up2_anim.stage)
    {
        removeChild(up2_anim)
        addChild(up1_anim)
        up1_anim.x = charPosKeeper_mc.x
        up1_anim.y = charPosKeeper_mc.y
    }
    else if(up1_anim.stage)
    {
        // IN NO CASE, SHOULD IT REACH THIS, IF IT DOES, THAT'S A BUG.
        // not sure why i have this then hm
        removeChild(up1_anim)
    }

}

function moveUp(e:Event):void
{
    if(area1 == true)
    {
        if(charPosKeeper_mc.hitTestObject(barrierRoof1_game))
        {
            //maybe play a collision sound here?
        }
        else if(charPosKeeper_mc.hitTestObject(barrierRoof2_game))
        {
            charPosKeeper_mc.y = charPosKeeper_mc.y - walkspeed;
        }
        else{
            if(up1_anim.stage)
            {
                removeChild(up1_anim)
                charPosKeeper_mc.y = charPosKeeper_mc.y - walkspeed;
                addChild(up2_anim);
                up2_anim.x = charPosKeeper_mc.x
                up2_anim.y = charPosKeeper_mc.y
            }
            else{
                charPosKeeper_mc.y = charPosKeeper_mc.y - walkspeed;
                addChild(up2_anim);
                up2_anim.x = charPosKeeper_mc.x
                up2_anim.y = charPosKeeper_mc.y
            }
        }
    }
    // This else statement is a short term fix, when you add more regions
    // this else becomes else if checking if your in area2,area3,etc.
    else{
    }
}

0 个答案:

没有答案