對編程來說是新手,慢慢地掌握它。我遇到了一個問題,我花了幾個小時試圖修復,但似乎無法得到我期待的結果。我爲我的角色製作了運行動畫。他向左,向上,向下,向右跑,向上,向下,向下但是向上和向下左動畫不播放。他在正確的方向移動,但正在播放的動畫是upRight和downRight。我已經將upLeft和downLeft的動畫更改爲我的「空閒」動畫,並且工作正常。如果所有其他動畫都能正常工作,我不確定爲什麼會發生這種情況。AS3動畫不會播放
這是我的播放器動畫代碼。任何幫助或建議都會很棒。在此先感謝
包{
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;
}
}
}
}
如果更改動畫效果,問題可能不在於您的發佈代碼,更可能與您的動畫有關。驗證「UpLeft」和「DownLeft」動畫是您認爲的動畫。 – 2012-08-12 18:50:38
謝謝,我一遍又一遍地翻過來,一遍又一遍地改變他們的名字。 – user1593823 2012-08-12 19:15:58