【发布时间】:2013-12-09 21:20:45
【问题描述】:
我正在尝试在 AS3 中制作一个非常基本的 Pseudo 3D 游戏。当我按下某些键时,我的角色会上下移动,但我想要发生的是当角色 y 位置高于对象 y 位置时,角色应该出现在对象后面。 这是我目前的对象类代码:
package {
import flash.display.MovieClip;
import flash.utils.getTimer
import flash.events.Event;
public class bushMC extends MovieClip {
private var lastFrame:int = new int(0);
private var dt:Number = new Number();
private var main:Main;
public function bushMC(){
main = this.parent as Main;
stage.addEventListener(Event.ENTER_FRAME, update);
trace(main.getChildIndex(this));
}
private function update(e:Event):void{
dt = (getTimer() - lastFrame)/30;
lastFrame = getTimer();
if(main.char.y + 200 < this.y + 55 && main.getChildIndex(main.char) > main.getChildIndex(this)){
main.setChildIndex(this, main.getChildIndex(main.char)+1);
}
else if(main.getChildIndex(main.char) < main.getChildIndex(this)){
main.setChildIndex(this, main.getChildIndex(main.char));
}
}
}
}
我已尝试为每个计算编辑大量值(+1、-1、等于),但似乎找不到正确的值。我试过的一个几乎可以工作,但是当字符应该在对象后面时,它只是在前面闪烁,然后在后面连续闪烁。
提前致谢,凯尔。
【问题讨论】:
标签: actionscript-3 3d z-index