我有一个应该重新启动整个游戏的功能,但是当它循环播放时,它就会中断。如何在重启功能中解决此问题?

时间:2019-04-08 12:41:47

标签: actionscript-3 reset restart application-restart

基本上,我有一个应该回到0函数的函数,在该函数中游戏重新开始,但是由于某种原因,游戏决定忽略第一次创建的所有内容并忽略重新启动按钮的init()部分。

我不得不求助于removeChild(),因为游戏刚刚破裂。

有什么办法可以使间隔,图像和(图像)按钮正常工作吗?

这是init部分:

fscommand("quit");

这是重新启动部分:

private function init(e:Event = null):void
        {

            gameBackground.y = -600; //start position for scrolling animation
            gameLogo.x = (stage.stageWidth/2 - gameLogo.width/2 + 50);
            gameLogo.y = 55;
            gameLogo.scaleX = 0.8;
            gameLogo.scaleY = 0.8;

            startBtn.scaleX = 0.4;
            startBtn.scaleY = 0.4;

            startBtn.x = (stage.stageWidth/2 + 125);
            startBtn.y = 500;
            player.x = (stage.stageWidth - player.width) / 2;

            player.y = startBtn.y - 10;
            addChild(gameBackground);
            addChild(player);
            addChild(gameLogo);
            addChild(startBtn);
            addEventListener(MouseEvent.MOUSE_OVER, buttonHover);
            addEventListener(MouseEvent.MOUSE_OUT, buttonHoverOff);
            addEventListener(MouseEvent.CLICK, startgame);
            trace("event listener added");
        }

        public function buttonHover(e:Event):void{
            if (e.target == startBtn)
            {
                startBtn.x = (stage.stageWidth/2 + 128);
                startBtn.y = 504;
                startBtn.scaleX = 0.395;
                startBtn.scaleY = 0.395;
                mouseClick.play();
            }
        }

        public function buttonHoverOff(e:Event):void{
            if (e.target == startBtn)
            {
                startBtn.x = (stage.stageWidth/2 + 125);
                startBtn.y = 500;
                startBtn.scaleX = 0.4;
                startBtn.scaleY = 0.4;
            }
        }

        public function btnMovement():void
        {
            startBtn.y += 10;
        }
        //this function removes all objects for the start menu and goes into the game
        public function startgame(e:Event):void
        {
            if (e.target == startBtn)
            {
                removeEventListener(MouseEvent.MOUSE_OUT, buttonHoverOff);
                mouseHover.play();
                startMove = setInterval(startGameAnimation, 16.6);
                planeTakeOff.play();
                var btnMove:uint = setInterval(btnMovement, 16.6);
                if (startBtn.y > stage.stageHeight + 20) {
                    startBtn.y += 0;
                    startBtn.visible = false;
                    clearInterval(btnMove);
                }
                //game();
                //trace("objects removed.  game starting...");
            }
            trace("remove click found");
        }

0 个答案:

没有答案