Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何让我的游戏在2分钟后重新启动?_Actionscript 3_Flash_Actionscript - Fatal编程技术网

Actionscript 3 如何让我的游戏在2分钟后重新启动?

Actionscript 3 如何让我的游戏在2分钟后重新启动?,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,所以我对AS3还不熟悉,并且一直在努力达到这一点,所以对于任何错误或由错误造成的错误,我深表歉意 我现在想要的就是在2分钟后重新开始我的游戏。有人知道我怎么做吗?我完全不知所措 这是我的密码: package { import flash.display.Sprite; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import Ship; import Coin; import CoinB; import flash

所以我对AS3还不熟悉,并且一直在努力达到这一点,所以对于任何错误或由错误造成的错误,我深表歉意

我现在想要的就是在2分钟后重新开始我的游戏。有人知道我怎么做吗?我完全不知所措

这是我的密码:

package 
{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import Ship;
import Coin;
import CoinB;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.utils.getTimer;

public class Main extends Sprite
{
    // constructor code
    private var Player1:Ship;
    private var Coin1:Coin;
    private var Coin2:Coin;
    private var Coin3:CoinB;
    private var Coin4:CoinB;
    private var score:int = 0;
    private var container;
    /*private var timer:Timer;*/

    public function Main():void
    {
        //Sets the position of player
        //adds player to stage
        this.Player1 = new Ship(259,365);
        addChild(this.Player1);

        Cont.visible = false;

                {
        addChild(interval_timer);
        /*addChild(frame_timer);*/
        /*frame_timer.y = 50;*/         
        var time_count:Timer = new Timer(1000);
        time_count.addEventListener(TimerEvent.TIMER, show_time);
        stage.addEventListener(Event.ENTER_FRAME,on_enter_frame);
        time_count.start();
    }

        //adds event listeners
        stage.addEventListener(KeyboardEvent.KEY_DOWN, hit);
        stage.addEventListener(Event.ENTER_FRAME, death);
        stage.addEventListener(KeyboardEvent.KEY_DOWN, retry);

        //add a Coin here
        Coin1 = new Coin(stage.stageWidth / 2,stage.stageHeight / 2,75,10);
        stage.addChild(Coin1);
        Coin2 = new Coin(stage.stageWidth / 2,stage.stageHeight / 2,125,-5);
        stage.addChild(Coin2);
        Coin3 = new CoinB(stage.stageWidth / 2,stage.stageHeight / 2,25,15);
        stage.addChild(Coin3);
        this.addEventListener(Event.ENTER_FRAME, fire);
    }

            public function show_time(event:TimerEvent)
    {
        interval_timer.text = event.target.currentCount;
    }
    public function on_enter_frame(event:Event)
    {
        var elapsed = getTimer();


    public function fire(e:Event)
    {

        if (Player1.hitTestObject(Coin1))
        {
            score += 50;
            Score.text = score.toString();

        }
        if (Player1.hitTestObject(Coin2))
        {
            score +=  10;
            Score.text = score.toString();
        }

    }

    public function death(e:Event)
    {

        if (Player1.hitTestObject(Coin3))
        {
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, hit);
            score = 0;
            Score.text = score.toString();
/*          gameOver.visible = true;*/

            Cont.visible = true;
            this.removeChild(this.Player1);
            this.Player1 = new Ship(259,365);
            Coin1.visible = false;
            Coin2.visible = false;
            Player1.visible = false;
            Coin3.visible = false;
            removeChild(interval_timer);



        }


    }

    public function hit(evt:KeyboardEvent):void
    {
        //this will move the player right if the "Right" arrow key is pressed.
        if (evt.keyCode == Keyboard.RIGHT)
        {
            this.Player1.right();
            this.Player1.rotation = 90;
        }
        //this will move the player left if the "Left" arrow key is pressed.

        else if (evt.keyCode == Keyboard.LEFT)
        {
            this.Player1.left();
            this.Player1.rotation = 270;
        }
        if (evt.keyCode == Keyboard.DOWN)
        {
            this.Player1.down();
            this.Player1.rotation = 180;
        }
        //this will move the player up if the "Up" arrow key is pressed.
        else if (evt.keyCode == Keyboard.UP)
        {
            this.Player1.up();
            this.Player1.rotation = 0;
        }
}

public function retry(evt:KeyboardEvent):void
{
//restarts game. 
//adds event listener so that the player can move again
if (evt.keyCode == Keyboard.R)


    Cont.visible = false;
    stage.addEventListener(KeyboardEvent.KEY_DOWN, hit);
    Coin1.visible = true;
    Coin2.visible = true;
    Player1.visible = true;
    Coin3.visible = true        
    addChild(this.Player1);

    addChild(interval_timer);

   }

  }
  }

非常感谢您的帮助。谢谢。

一般来说,在2分钟结束时,您将使用触发功能

大概是这样的:

var gameTimer:Timer = new Timer(120 * 1000); // 120 seconds * 1000 milliseconds
gameTimer.addEventListener(TimerEvent.TIMER, onGameTimerTick);
gameTimer.start();

function onGameTimerTick(e:TimerEvent):void {
    //stop the timer
    gameTimer.removeEventListener(TimerEvent.TIMER, onGameTimerTick);
    gameTimer.stop();

    restartMyGame();
}