所以,我有一个游戏,你必须活着45秒,但如果你死了它进入场景4,你可以点击重新启动场景3(这是你尝试不死的地方)。我的问题是我的计时器。我在场景3中声明了计时器,但它似乎从第一场开始,当我死了,计时器没有重启或停止,所以我可以一遍又一遍地死,只要我一直在玩总共45秒,我自动获胜。我不确定这个错误发生在哪里,所以我只是要粘贴我的所有代码。 //场景1
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,Intro);
function Intro(e:Event)
{
var mySound:Sound = new E();
mySound.play();
Asteroid1.y = Asteroid1.y + 20;
Asteroid2.y = Asteroid2.y + 24;
Asteroid3.y = Asteroid3.y + 16;
Asteroid4.y = Asteroid4.y + 28;
Asteroid5.y = Asteroid5.y + 17
Asteroid6.y = Asteroid5.y + 22
Asteroid1.x = Asteroid1.x + 19;
Asteroid2.x = Asteroid2.x + 18;
Asteroid3.x = Asteroid3.x + 14;
Asteroid4.x = Asteroid4.x + 17;
Asteroid5.x = Asteroid5.x + 21
Asteroid6.x = Asteroid6.x + 20
if(Asteroid1.y > 768){
Asteroid1.y = -40;
}
if(Asteroid2.y > 768){
Asteroid2.y = -40;
}
if(Asteroid2.x > 1024){
Asteroid2.x = -40;
}
if (Asteroid1.x > 1024){
Asteroid1.x = -40
}
if(Asteroid3.x > 1024){
Asteroid3.x = -20;
}
if (Asteroid3.y > 768){
Asteroid3.y = -20;
}
if (Asteroid4.y > 768){
Asteroid4.y = -20;
}
if(Asteroid4.x > 1024){
Asteroid4.x = -20;
}
if (Asteroid5.y > 768) {
Asteroid5.y = -30;
}
if (Asteroid5.x > 1024) {
Asteroid5.x = -40;
}
if (Asteroid6.y > 768){
Asteroid6.y = -30;
}
if (Asteroid6.x > 1024) {
Asteroid6.x = -30;
}
}
//Scene 2
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,IntroS2);
function IntroS2(e:Event) {
Asteroid5.y = Asteroid5.y + 20;
Asteroid6.y = Asteroid6.y + 18;
Asteroid7.y = Asteroid7.y + 16;
Asteroid8.y = Asteroid8.y + 22;
Asteroid9B.y = Asteroid9B.y + 17
Asteroid5.x = Asteroid5.x + 20;
Asteroid6.x = Asteroid6.x + 22;
Asteroid7.x = Asteroid7.x + 14;
Asteroid8.x = Asteroid8.x + 18;
Asteroid9B.x = Asteroid9B.x + 16
if (Asteroid5.y > 768) {
Asteroid5.y = -40;
}
if (Asteroid6.y > 768) {
Asteroid6.y = -40;
}
if (Asteroid5.x > 1024) {
Asteroid5.x = -40;
}
if (Asteroid6.x > 1024) {
Asteroid6.x = -20;
}
if (Asteroid7.x > 1024) {
Asteroid7.x = -20;
}
if (Asteroid7.y > 768) {
Asteroid7.y = -20;
}
if (Asteroid8.y > 768) {
Asteroid8.y = -20;
}
if (Asteroid8.x > 1024) {
Asteroid8.x = -20;
}
if (Asteroid9B.x > 1024){
Asteroid9B.x = -30;
}
if (Asteroid9B.Y >768){
Asteroid9B.y = -20;
}
}
//场景2最后一帧
stop();
stage.addEventListener(MouseEvent.CLICK, _onStageMouseDown);
function _onStageMouseDown(e:MouseEvent):void
{
removeEventListener(Event.ENTER_FRAME,IntroS2);
gotoAndStop(1, "Scene 5");
}
//Scene 3
import flash.events.Event;
addEventListener(Event.ENTER_FRAME,ms3);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
myTimer.addEventListener(TimerEvent.TIMER, handleTimerTick);
stage.removeEventListener(MouseEvent.CLICK, _onStageMouseDown1);
stage.removeEventListener(MouseEvent.CLICK, _onStageMouseDown);
Mouse.hide();
//TIMER
var myTimer:Timer = new Timer(1000, 1); // 1 second
myTimer.addEventListener(TimerEvent.TIMER, onEnterFrame);
myTimer.start();
//TIMER
function ms3(e:Event){
Mouse.hide();
Planet3.y = mouseY;
Planet3.x = mouseX;
Asteroid9.x = Asteroid9.x + 26;
Asteroid9.y = Asteroid9.y + 21;
if (Asteroid9.x > 1024){
Asteroid9.x = -40
}
if (Asteroid9.y > 768){
Asteroid9.y = -40
}
Asteroid10.x = Asteroid10.x + 22;
Asteroid10.y = Asteroid10.y + 23;
if (Asteroid10.x > 1024){
Asteroid10.x = -40
}
if (Asteroid10.y > 768){
Asteroid10.y = -40
}
Asteroid11.x = Asteroid11.x + 18;
Asteroid11.y = Asteroid11.y + 21;
if (Asteroid11.x > 1024){
Asteroid11.x = -40
}
if (Asteroid11.y > 768){
Asteroid11.y = -40
}
Asteroid12.x = Asteroid12.x + 24;
Asteroid12.y = Asteroid12.y + 22;
if (Asteroid12.x > 1024){
Asteroid12.x = -40
}
if (Asteroid12.y > 768){
Asteroid12.y = -40
}
// Hit Test
if(Planet3.hitTestObject(Asteroid9)||
Planet3.hitTestObject(Asteroid10)||
Planet3.hitTestObject(Asteroid11)||
Planet3.hitTestObject(Asteroid12))
{
gotoAndStop(1, "Scene 4");
}
}
//TIMER SECTION
function resetTimer():void
{
// check if timer already initialize
if(myTimer != null)
{
// just reset
myTimer.stop();
myTimer.reset();
}
else
{
// initialize timer and set a 45 sec delay;
myTimer = new Timer(4500,1);
myTimer.addEventListener(TimerEvent.TIMER, handleTimerTick);
}
myTimer.start();
}
function handleTimerTick(event:TimerEvent):void
{
// stop and null timer;
myTimer.stop();
myTimer.removeEventListener(TimerEvent.TIMER, handleTimerTick);
myTimer = null;
// goto my 4th scene
gotoAndStop(1, "Scene 4");
}
// whenever a hit test is performed and a timer reset is needed just call
resetTimer();
function onEnterFrame(e:Event):void {
var startTime:int=getTimer();
var currentTime:int=getTimer();
trace(currentTime);
if (currentTime>45000){
gotoAndStop(1, "Scene 6");
}
}
这些都是真正重要的场景,4-6只是动画和点击鼠标等等。在场景4-6中没有引用计时器。有任何想法吗?如果需要,我会编辑额外的信息。