var i:Number;
for (i=0;i<6;i++)
{
var brick:Sprite=new Sprite();
brick.graphics.beginFill(0x02589E);
brick.graphics.drawRect(0,0,70,7);
brick.graphics.endFill();
brick.y=10;
brick.x=12+(80*i);
addChild(brick);
}
addEventListener(Event.ENTER_FRAME,destroy);
var ball:Sprite=new Sprite();
ball.graphics.beginFill(0xff0000);
ball.graphics.drawCircle(0,0,7);
ball.graphics.endFill();
ball.x=200;
ball.y=230;
addChild(ball);
.......一些球移动的代码......
function destroy(e:Event):void
{
if(ball.hitTestObject(brick)){
removeChild(brick);
}
}
当球与砖发生碰撞时,只移除最后一个砖。但如果球与砖发生碰撞,我想单独移除所有砖。