我有一个基本的游戏功能,每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();
那么我该如何改变它,所以每次都会换新球呢?并且让我们说它是这样的,我如何确保它能够摆脱它? – 2011-12-25 17:25:01
请检查更新。 – 2011-12-26 00:04:10
现在我改变了代码,所以每次drop ball函数关闭时它都会实例化一个新的球对象,但是我仍然不知道如何检查碰撞,因为现在碰撞检查函数会产生错误。是否有可能检查从库对象'ball1'实例化的对象是否碰到板块? – 2011-12-26 11:38:21