actionscript 3-AS3 Flash游戏菜单收割者



我是Flash AS3游戏编程的新手,,我面临一个问题,,我正在尝试创建一个打开界面(带有播放按钮的菜单),,,在游戏过程中玩家给出通过键盘、、和游戏的输入应该跳到第10帧(显示一些对象),然后重置回第1帧。现在,当我的游戏重置回第1帧时开始收割时的菜单,,,,,,下面给出了我的部分代码。。。。要运行代码,只需在第1帧添加一些临时库对象tat,并允许通过as3访问它。也在第10帧添加一个关键帧。

var keyPressed:uint;
var rightkey:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, playshot);
var timer:Timer = new Timer(3700, 1);   //create the timer
timer.addEventListener(TimerEvent.TIMER, initializeGame);
var tmenu:tat = new tat();  //show a start menu with play button
addChild(tmenu);    //added to the stage
tmenu.addEventListener(MouseEvent.CLICK,controlmenu);   
function controlmenu(event:MouseEvent) { 
timer.start();
    removeChild(tmenu); //when the play button is clicked                        //button and   start the game
}
function playshot(event:KeyboardEvent):void {  //detects the keys pressed and shots   accordingly               {
    keyPressed = event.keyCode;
    if(keyPressed == Keyboard.RIGHT)
{
trace("Entering movebat function");
gotoAndStop(10);      //show a show rectangle shape at frame 10;
timer.start();

}
}
function initializeGame(e:TimerEvent):void
{
    gotoAndStop(1);
}
stop();

如果您跳转到一个上面有代码的框架,该代码将再次执行。您很可能将代码放在第一帧,因此当您将代码跳回第一帧时,添加代码的菜单将再次运行。将初始化代码放在只命中一次的框架上,或者更好的是,使用文档类,避免完全跳过时间线。

最新更新