我有一个基本的游戏功能,每隔500毫秒就会掉落一个球(带有一个计时器事件),并且当它碰到一个拖动鼠标之后的盘子时就会摆脱它。事情是;我尝试使用deleteChild();
函数,但它只删除了球对象的视觉外观而没有停止它的功能,这会导致一些问题:
这是完整的脚本:
//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();
答案 0 :(得分:2)
你的代码没有像你解释的那样工作。它的工作原理如下:
你只有一个球,而且它每秒钟都在咆哮,引用gameTime1
嘀嗒声叫做dropBall(),它执行以下操作:
var ballTween:Tween = new Tween(ball, "y", null, 0, 500, 1.2, true);
<强>更新强>
关于如何导出movieclipt int oclass,请遵循以下教程: http://www.kirupa.com/developer/flashcs3/movieclips_classes_AS3_pg1.htm
然后在你的逻辑中:
功能(createBall)
应该是这样的:
if ( hitPanel )
{
increaseScrore ()
}
if ( hitFloor )
{
decreaseLive ()
}
increase...
和decrease..
完成后,所有内容都应该是removeBall
函数,而在increase..
中则调用createBall
所以一切都开始重演了。P.S。没有冒犯,但你可以学习编程语言,在这种情况下,我看到你知道一点,但如果你错过了一些逻辑,你将无法在论坛上找到它...阅读一些关于逻辑/架构的基本信息应用程序等...请看看如何对这些实例进行处理。
P.S.S。投资一些知道wtf是OOP。 ;)
祝你好运!节日快乐:)答案 1 :(得分:0)
您是否尝试将球设置为null
?