【发布时间】:2019-08-01 20:49:11
【问题描述】:
我有 MC 的 rockThrowers 被添加到舞台的 3 个不同位置。它们使用运行良好的随机生成器随机生成。用户单击舞台上的一个按钮,rockThrowers 被添加到舞台并推入他们自己的数组 aRockThrowerArray 我希望能够检查它们产生的 3 个位置中的哪一个,而不是与下一个 rockThrowers 重叠被添加到舞台,如果是这样,那么在空位置添加一个新的。我尝试了不同的策略,主要是布尔值,并将它们从他们自己的类调用到我的主类,但似乎没有任何效果。这是我的
rockThrowers 类:
private function startPosition():void
{
// y position
this.y = (stage.stageHeight / 2) + 200;
//Start Speed
nSpeed = randomNumber(5, 8);
leftScreenSpawn = randomNumber(1, 3);
//For Left Screen
leftNeg = (stage.stageWidth / 2) - 200;
leftMiddle = (stage.stageWidth / 2) - 150;
leftPos = (stage.stageWidth / 2) - 100;
//Left Screen
if (leftScreenSpawn == 1)
{
this.x = leftNeg;
bLeftNeg = true; // Now if the left Rock thrower is destroyed then turn back to false on main engine class
}else
if (leftScreenSpawn == 2)
{
this.x = leftMiddle;
bLeftMiddle = true;
}else
if (leftScreenSpawn == 3)
{
this.x = leftPos;
bLeftPos = true;
}
//Move
startMoving();
}
现在在我的主类中,当用户单击左屏幕 Btn 时,我已经设置了这样的设置:
private function rockThrowerSpawn(e:MouseEvent):void
{
//Instantiate screens before hand
rockThrowerSpawnScreen.x = (stage.stageWidth / 2);
rockThrowerSpawnScreen.y = (stage.stageHeight / 2) + 200;
addChild(rockThrowerSpawnScreen);
rockThrowerSpawnScreen.left.addEventListener(MouseEvent.CLICK, chooseSpawnSideRockThrowers);
}
然后是 Spawn 函数:
private function chooseSpawnSideRockThrowers(e:MouseEvent):void
{
if (e.currentTarget == rockThrowerSpawnScreen.left) // Spawn LEFT
{
//add new rock thrower
rockThrowers = new mcRockThrowers();
//Add object
addChild(rockThrowers);
//Add to Array
aRockThrowerArray.push(rockThrowers);
//trace("LEFT SPAWN");
}
//Subtract resources and update text
nResources -= 10;
updateResourceTextField();
//Remove Listeners
rockThrowerSpawnScreen.left.removeEventListener(MouseEvent.CLICK, chooseSpawnSideRockThrowers);
rockThrowerSpawnScreen.destroy();
}
我知道仅此一项总是会产生随机位置我删除了所有不起作用的东西现在我回到了这个正方形。关于我如何做到这一点的任何想法?感谢所有支持。
【问题讨论】:
标签: actionscript-3 adobe flashdevelop