晚上好。我正在做一个简单的项目,其中涉及使用 EVENT_FRAME 处理程序以矩形方式(右、上、左、下、重复)移动的符号。这是我的代码
import flash.events.Event;
var moveRate:Number = 20;
var maxX:Number = 500;
var minX:Number = 80;
var maxY:Number = 60;
var minY:Number = 320;
var endOfLineX:int = 0;
var endOfLineY:int = 0;
roboSym.addEventListener(Event.ENTER_FRAME, move1);
roboSym.addEventListener(Event.ENTER_FRAME, move2);
function move1(e:Event):void
{
if (endOfLineX == 0)
{
roboSym.x += moveRate;
if (roboSym.x >= maxX)
{
endOfLineX = 1;
}
}
else if (endOfLineX == 1)
{
roboSym.x -= moveRate;
if (roboSym.x <= minX)
{
endOfLineX = 0;
}
}
}
function move2(e:Event):void
{
if (endOfLineY == 0)
{
roboSym.y -= moveRate;
if (roboSym.y <= maxY)
{
endOfLineY = 1;
}
}
else if (endOfLineY == 1)
{
roboSym.y += moveRate;
if (roboSym.y >= minY)
{
endOfLineY = 0;
}
}
}
问题是,运动一直是对角线运动,而不是直线运动。我知道我的逻辑中某处有错误,但我无法确定它是什么。