【发布时间】:2016-08-17 03:06:15
【问题描述】:
我遇到了这个问题,当我按下向上键让我的玩家跳跃时,玩家会进入跳跃动画,但在半空中时会立即返回到空闲动画。我的问题是如何让玩家保持跳跃动画,然后在他到达地面后返回空闲状态。
import KeyObject;
import flash.events.Event;
var hsp = 15;
var vy:Number = 0;//Vertical speed variable
var grav:Number = 20;//gravity variable
var jumped:Boolean = false;//Checking if we jumped, false means
//not jumping
warMage.gotoAndStop("idleWarmage");
//Player initially starts with idle animation
var Key:KeyObject = new KeyObject(stage);//Adds the new method for keyboard check
//The stage always checks for these events and functions
stage.addEventListener(Event.ENTER_FRAME, onEnter);
stage.addEventListener(Event.ENTER_FRAME, gameloop);
function onEnter(e:Event):void
{
if(Key.isDown(Key.RIGHT))//Check if right arrow is pressed
{
warMage.x += 15;//Move at this speed
warMage.gotoAndStop("RunWarmage");//Play this animation
warMage.scaleX = 1;//Keep the image svale to right
}
else if(Key.isDown(Key.LEFT))//Check if left arrow is pressed
{
warMage.x -= 15;//Move left
warMage.scaleX = -1;//Flip the image
warMage.gotoAndStop("RunWarmage");//Play this animation
}
else if(Key.isDown(Key.UP))//Check if spacebar is pressed
{
if(!jumped)//the boolean is true
{
vy -= 70;//Player jumps 50 pixels upward
jumped = true;
warMage.gotoAndStop("JumpWarmage");//Play the jump animation
}
}
else
{
warMage.gotoAndStop("idleWarmage");//Return to idle state
}
}
function gameloop(e:Event):void
{
if(warMage.x + 36.55 < 0)//Setting room boundaries
{
warMage.x = 0;//Setting boundary on right
}
if(warMage.x + 55.22 > 999)//Setting boundary on left
{
warMage.x = 999;
}
vy += grav;
if(!ground.hitTestPoint(warMage.x + 36.55, warMage.y + 55.22, true))//If we're not on a surface
{
warMage.y += vy;//apply gravity to the player
}
for(var i = 0;i < 109; i++)
{ //If the warmage is on the ground
if(ground.hitTestPoint(warMage.x + 36.55, warMage.y + 55.22, true))
{
warMage.y--;//A pixel above the platform
vy = 0;//Gravity isn't applied on the player
jumped = false;//We're not jumping
}
}
}
【问题讨论】:
-
根据您发布的代码,您一键启动,它将转到“idleWarmage”,
-
是否有特定的命令可以说保持动画直到玩家到达地面?
-
没有现成的命令。只有当 jumped 为 false 时,Warmag 才能进入空闲状态。当跳跃动画完成时,您应该将跳跃变量设为 false。
标签: actionscript-3 flash animation