私は、(タイマーイベントで)500ミリ秒ごとにボールを落とし、マウスの後ろにドラッグするプレートに当たったときにそれを取り除くと仮定する基本的なゲーム機能を持っています。事はです。私はdeleteChild();
機能を使用しようとしましたが、それが唯一の問題のカップルが発生し、その機能を停止させることなく、ボールオブジェクト」の外観を削除します。アクションスクリプト3.0で衝突イベント後にオブジェクトを完全に削除
- ボールがいっている、と打つのイベントをトリガ床。
- dropBall();ドロップボールをアニメートする機能で、実際に新しいボールをアニメーション化することはありません。
これは完全なスクリプトです:
//imports:
import flash.events.Event;
import fl.transitions.Tween;
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.TimerEvent;
//the function 'startGame, handles all basic game functions.
function startGame() {
//inisializes the variable 'Score' and gives it a value of 0.
var Score = 0;
//enter_frame listener. calls 'movePlate'
stage.addEventListener(Event.ENTER_FRAME, movePlate);
//function 'movePlate'. makes the plate follow the mouse
function movePlate(event:Event):void {
plate.x = mouseX;
}
//calls the dropBall function
dropBall()
//the function 'dropBall'. animates the droping ball
function dropBall() {
var oldpost = 0;
var randomNum:Number = Math.random() * 550;
var xAxis:int = Math.round(randomNum);
trace(randomNum);
trace(xAxis);
ball.x = xAxis;
base.x = xAxis;
var oldpost = xAxis;
var ballTween:Tween = new Tween(ball, "y", null, 0, 500, 1.2, true);
oldpost = xAxis;
}
//function 'gameTime'. the timer function that controlls the intervals between falling eggs and ratio of good to bad eggs.
var gameTime1:Timer = new Timer(1000);
gameTime1.addEventListener(TimerEvent.TIMER, gameTimer1Function)
function gameTimer1Function(evt:TimerEvent):void {
dropBall();
}
gameTime1.start();
//enter frame event listener. calls 'checkCollision'
addEventListener(Event.ENTER_FRAME,checkCollision);
//function checl collision. checks if the ball hits the plate
function checkCollision(event: Event):void {
if(ball.hitTestObject(plate)) collisionDetected();
}
//function collision detected
function collisionDetected():void {
Score ++;
trace(Score);
scoreText.text = Score;
}
//enter frame event listener. calls 'checkGameOver'.
addEventListener(Event.ENTER_FRAME,checkGameOver);
//function 'checkGameOver.
function checkGameOver(event: Event):void {
if(ball.hitTestObject(floor)) gameOver();
}
//function 'gameOver'.
function gameOver():void {
trace('GAME OVER!!! Your Score Is: ' + Score + '.');
trace('Asta la Vista Baby :D');
}
}
startGame();
どのように私は毎回新しいボールを作るように変更することはできますか?そして、それがそのように機能すると言うと、どうすればそれを取り除くことができるのですか? –
更新をご確認ください。 –
今、私はドロップボール機能がオフになるたびに新しいボールオブジェクトをインスタンス化するようにコードを変更しましたが、今は衝突チェック機能がエラーを起こすので、まだ衝突をチェックする方法がありません。ライブラリオブジェクト 'ball1'からインスタンス化されたオブジェクトがプレートに当たるかどうかを確認することは可能ですか? –