我在 AS3 中打乒乓球。然而,当球击中我的桨时,我想移除它的一部分(桨)。我的球和我的桨都是电影剪辑。我该怎么做?什么是最好的删除方式,而不是整个影片剪辑,而只是其中的一部分。
这是我的代码:
import flash.events.Event;
var ballSpeedX:int = 4;
var ballSpeedY:int = 4;
init();
function init():void {
stage.addEventListener(Event.ENTER_FRAME, loop);
}
function loop(e:Event):void {
playerPaddle.x = mouseX;
if(playerPaddle.hitTestObject(ball)){
if(ballSpeedY >= 0){
ballSpeedY *= -1;
ball.removeSelf();
}
}
if(playerPaddle.y - playerPaddle.height/2 < 0){
playerPaddle.y = playerPaddle.height/2;
//check if bottom of paddle is below bottom of screen
} else if(playerPaddle.y + playerPaddle.height/2 > stage.stageHeight){
playerPaddle.y = stage.stageHeight - playerPaddle.height/2;
}
ball.x += ballSpeedX;
ball.y += ballSpeedY;
if(ball.x <= ball.width/2){
ball.x = ball.width/2;
ballSpeedX *= -1;
}else if(ball.x >= stage.stageWidth-ball.width/2){
ball.x = stage.stageWidth-ball.width/2;
ballSpeedX *= -1;
}
if(ball.y <= ball.height/2){
ball.y = ball.height/2;
ballSpeedY *= -1;
} else if(ball.y >= stage.stageHeight-ball.height/2){
ball.y = stage.stageHeight-ball.height/2;
ballSpeedY *= -1;
}
}