ActionScript 3.0 在进入下一帧后删除数组/childs
我的情况是:
var ster:Array;
ster = new Array();
stage.addEventListener(Event.ENTER_FRAME, groente);
function groente(event:Event)
{
if(Math.round(Math.random()*140) == 1)
{
ster.push(new groente1_MC());
addChild(ster[ster.length-1]);
ster[ster.length-1].x = machine.x
ster[ster.length-1].y = machine.y
ster[ster.length-1].scaleX = 0.2;
ster[ster.length-1].scaleY = 0.2;
}
for(var i:int = 0; i < ster.length-1; i++)
{
ster[i].y = ster[i].y + 5;
if( hero.hitTestObject(ster[i]) ) {
ster[i].visible = false;
score = score +1;
Score.text = ""+ score;
}
}
}
现在的问题是,进入下一帧后。我仍然可以看到 groente1_MC。而且在我的舞台上还有更多的产卵。我怎样才能删除所有这些并在进入下一帧后停止生成它们?
What I have this:
var ster:Array;
ster = new Array();
stage.addEventListener(Event.ENTER_FRAME, groente);
function groente(event:Event)
{
if(Math.round(Math.random()*140) == 1)
{
ster.push(new groente1_MC());
addChild(ster[ster.length-1]);
ster[ster.length-1].x = machine.x
ster[ster.length-1].y = machine.y
ster[ster.length-1].scaleX = 0.2;
ster[ster.length-1].scaleY = 0.2;
}
for(var i:int = 0; i < ster.length-1; i++)
{
ster[i].y = ster[i].y + 5;
if( hero.hitTestObject(ster[i]) ) {
ster[i].visible = false;
score = score +1;
Score.text = ""+ score;
}
}
}
Now the problem is, after going to the next frame. I can still see the groente1_MC. And there are still more spawning in my stage. How can i delete all these and stop spawning them after going to the next frame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要删除 ENTER_FRAME 侦听器以停止对象的移动和创建,然后循环遍历数组,从舞台中删除每个对象,然后再清除数组:
You need to remove the ENTER_FRAME listener to stop the movement and creation of objects, then loop though the array removing each object from the stage before clearing the array:
尝试
示例:
tf.text
是try
example:
tf.text
is