好吧,所以这个框架,你躲避小行星,如果你击中一个大的,它会摧毁你,你会去另一个框架,但你可以选择回到前面提到的框架。有时候当我重新登陆时,当我回来时,一些小行星已经离开那里,就像这个http://imgur.com/a/o9UHC一样,似乎有时会有更多的小行星出现在那个场景的重装上。这是代码:
var speedAgainX = Math.floor(Math.random() * 20 - 10);
var speedAgainY = Math.floor(Math.random() * 20 - 10);
var speedAgainX1 = Math.floor(Math.random() * 20 - 10);
var speedAgainY1 = Math.floor(Math.random() * 20 - 10);
var speedAgainX2 = Math.floor(Math.random() * 20 - 10);
var speedAgainY2 = Math.floor(Math.random() * 20 - 10);
var speedAgainX3 = Math.floor(Math.random() * 20 - 10);
var speedAgainY3 = Math.floor(Math.random() * 20 - 10);
var nCount1:Number = -0;
timer_Text1.text = nCount1.toString();
addEventListener(Event.ENTER_FRAME,massCollect);
function massCollect(e:Event){
if(Cosmo.hitTestObject(Asteroid5)){
removeChild(Asteroid5);
nCount1++;
timer_Text1.text = nCount1.toString();
addChild(Asteroid5);
Asteroid5.x = Math.floor(Math.random() * 20 - 10);
Asteroid5.y = Math.floor(Math.random() * 20 - 10);
Asteroid5.x = Asteroid5.x + speedAgainX;
Asteroid5.y = Asteroid5.y + speedAgainY;
if (Asteroid5.x > 1100 || Asteroid5.x < -100)
{
speedAgainX = -speedAgainX;
}
}
if(Cosmo.hitTestObject(Asteroid6)){
removeChild(Asteroid6);
nCount1++;
timer_Text1.text = nCount1.toString();
addChild(Asteroid6);
Asteroid6.x = Math.floor(Math.random() * 20 - 10);
Asteroid6.y = Math.floor(Math.random() * 20 - 10);
Asteroid6.x = Asteroid6.x + speedAgainX1;
Asteroid6.y = Asteroid6.y + speedAgainY1;
if (Asteroid6.x > 1100 || Asteroid6.x < -100)
{
speedAgainX1 = -speedAgainX1;
}
}
if(Cosmo.hitTestObject(Asteroid7)){
removeChild(Asteroid7);
nCount1++;
timer_Text1.text = nCount1.toString();
addChild(Asteroid7);
Asteroid7.x = Math.floor(Math.random() * 20 - 10);
Asteroid7.y = Math.floor(Math.random() * 20 - 10);
Asteroid7.x = Asteroid7.x + speedAgainX2;
Asteroid7.y = Asteroid7.y + speedAgainY2;
if (Asteroid7.x > 1100 || Asteroid7.x < -100)
{
speedAgainX2 = -speedAgainX2;
}
}
if(Cosmo.hitTestObject(Asteroid8)){
removeChild(Asteroid8);
nCount1++;
timer_Text1.text = nCount1.toString();
addChild(Asteroid8);
Asteroid8.x = Math.floor(Math.random() * 20 - 10);
Asteroid8.y = Math.floor(Math.random() * 20 - 10);
Asteroid8.x = Asteroid8.x + speedAgainX3;
Asteroid8.y = Asteroid8.y + speedAgainY3;
if (Asteroid8.x > 1100 || Asteroid8.x < -100)
{
speedAgainX3 = -speedAgainX3;
}
}
if (Cosmo.hitTestObject(Deathroid1)){
gotoAndStop(352, "Scene 1");
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
removeChild(Asteroid5);
removeChild(Asteroid6);
removeChild(Asteroid7);
removeChild(Asteroid8);
}
if (Cosmo.hitTestObject(Deathroid2)){
gotoAndStop(352, "Scene 1");
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
removeChild(Asteroid5);
removeChild(Asteroid6);
removeChild(Asteroid7);
removeChild(Asteroid8);
}
if(nCount1 == 10){
gotoAndStop(351, "Scene 1");
removeEventListener(Event.ENTER_FRAME,massCollect);
removeEventListener(Event.ENTER_FRAME,massGain);
}
}
答案 0 :(得分:0)
这个块:
if(Cosmo.hitTestObject(Asteroid6)){
removeChild(Asteroid6);
nCount1++;
timer_Text1.text = nCount1.toString();
addChild(Asteroid6);
Asteroid6.x = Math.floor(Math.random() * 20 - 10);
Asteroid6.y = Math.floor(Math.random() * 20 - 10);
Asteroid6.x = Asteroid6.x + speedAgainX1;
Asteroid6.y = Asteroid6.y + speedAgainY1;
if (Asteroid6.x > 1100 || Asteroid6.x < -100)
{
speedAgainX1 = -speedAgainX1;
}
}
当Cosmo与它碰撞时,你基本上正在重建Asteroid6。不过,我认为这只是支架放置的问题。其余部分也一样。
此外,您的整个代码有点混乱。您应该查看数组,以便更好地管理小行星。