Actionscript 3 如何阻止电影剪辑沿对角线移动?
大家好,这件事把我难住了。因此,我有一系列名为《鲨鱼》的电影剪辑,从舞台的左侧或右侧添加到舞台上。现在,当它们被添加时,我让它们在正或负x位置移动,所以在一条水平线上。但是为了使玩家在水流中向前移动,而所有其他物体都经过玩家,我还让鲨鱼移动剪辑阵列在正y位置移动,垂直向下移动。但是当我这样做时,在我的输入框中有值,数组中的Actionscript 3 如何阻止电影剪辑沿对角线移动?,actionscript-3,flash-cs6,enterframeevent,Actionscript 3,Flash Cs6,Enterframeevent,大家好,这件事把我难住了。因此,我有一系列名为《鲨鱼》的电影剪辑,从舞台的左侧或右侧添加到舞台上。现在,当它们被添加时,我让它们在正或负x位置移动,所以在一条水平线上。但是为了使玩家在水流中向前移动,而所有其他物体都经过玩家,我还让鲨鱼移动剪辑阵列在正y位置移动,垂直向下移动。但是当我这样做时,在我的输入框中有值,数组中的鲨鱼电影剪辑似乎在移动对角线,这是我根本不想要的。是否有人知道如何解决这个问题,使电影剪辑向下移动,并在屏幕上沿直线移动 以下是我迄今为止在shark课程中所学的内容: pri
鲨鱼
电影剪辑似乎在移动对角线,这是我根本不想要的。是否有人知道如何解决这个问题,使电影剪辑向下移动,并在屏幕上沿直线移动
以下是我迄今为止在shark课程中所学的内容:
private function startPosition():void
{
//Pick the frames for start position
var nRandom:Number = randomNumber(1, 2);
//Setup goto and stop on timeline
this.gotoAndStop(nRandom);
//Pick a random speed
nSharkSpeed = randomNumber(3, 5);
//Pick a random number for start position
var nLeftOrRight:Number = randomNumber(1, 2);
//If our nLeftOrRIght == 1 start on the left side
if (nLeftOrRight == 1)
{
//Start shark on left side and move to right
this.x = (stage.stageWidth / 2) - 240;
sSharkDirection = "R";
}else
{
//Start shark on right side and move to left
this.x = (stage.stageWidth / 2) + 240;
sSharkDirection = "L";
}
//Set y position
this.y = (stage.stageHeight / 2) - 400;
//Move our shark
startMoving();
}
private function startMoving():void
{
addEventListener(Event.ENTER_FRAME, sharkLoop);
}
private function sharkLoop(e:Event):void
{
//test what direction fish is moving in
//If fish is moving right
if (sSharkDirection == "R")
{
//Move Shark right
this.x += nSharkSpeed;
}else
{
//Move Shark left
this.x -= nSharkSpeed;
}
this.y += nSharkSpeed;
}
任何帮助都将不胜感激,谢谢 看起来你的代码做了它想做的事情:你说过,首先,你希望鲨鱼水平移动,其次,垂直移动。改变X和Y坐标会使我们产生对角线移动=) 看来你的代码还可以 也许,您应该重新考虑应用程序的逻辑。此外,您还可以删除/注释更改鲨鱼X位置的代码部分:
if (sSharkDirection == "R")
{
//Move Shark right
this.x += nSharkSpeed;
}else
{
//Move Shark left
this.x -= nSharkSpeed;
}
所有的鲨鱼只能靠Y移动