Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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 游戏AS3的连续计时器和对象_Actionscript 3_Timer_Character - Fatal编程技术网

Actionscript 3 游戏AS3的连续计时器和对象

Actionscript 3 游戏AS3的连续计时器和对象,actionscript-3,timer,character,Actionscript 3,Timer,Character,我目前正在做一个游戏,在游戏中,你需要尽可能长时间地生存,同时回避你遇到的问题。(均带有AS3) 此时,我正在从一个场景切换到游戏区域和问题区域之间的另一个场景,但每次我进入问题场景时,游戏场景中的计时器都会自动重置。我想知道在提问场景中是否可以继续计时? 另外,我在菜单之间有一个可移动的角色,顺便说一句,这些角色也在不同的场景中制作,玩家可以移动他,我非常希望他保持在下一个屏幕中的最后一个位置,就像我把他移到主菜单的右上角一样,当我进入选项菜单时,我希望他仍然在右上角,而不是初始位置 至于我的

我目前正在做一个游戏,在游戏中,你需要尽可能长时间地生存,同时回避你遇到的问题。(均带有AS3)
此时,我正在从一个场景切换到游戏区域和问题区域之间的另一个场景,但每次我进入问题场景时,游戏场景中的计时器都会自动重置。我想知道在提问场景中是否可以继续计时?
另外,我在菜单之间有一个可移动的角色,顺便说一句,这些角色也在不同的场景中制作,玩家可以移动他,我非常希望他保持在下一个屏幕中的最后一个位置,就像我把他移到主菜单的右上角一样,当我进入选项菜单时,我希望他仍然在右上角,而不是初始位置

至于我的计时器,这是我目前使用的代码:

    import flash.utils.Timer;    
    import flash.events.Event;    
    import flash.events.TimerEvent;    
    import flash.globalization.DateTimeFormatter;    


    var timer:Timer = new Timer(100);    
            timer.start();    
    timer.addEventListener(TimerEvent.TIMER, timerTickHandler);    
    var timerCount:int = 0;    

    function timerTickHandler(Event:TimerEvent):void    
    {
        timerCount += 100;
        toTimeCode(timerCount);
    }

    function toTimeCode(milliseconds:int) : void {
//create a date object using the elapsed milliseconds
var time:Date = new Date(milliseconds);

//define minutes/seconds/mseconds
var minutes:String = String(time.minutes);
var seconds:String = String(time.seconds);
var miliseconds:String = String(Math.round(time.milliseconds)/100);

//add zero if neccecary, for example: 2:3.5 becomes 02:03.5
minutes = (minutes.length != 2) ? '0'+minutes : minutes;
seconds = (seconds.length != 2) ? '0'+seconds : seconds;

//display elapsed time on in a textfield on stage
timer_txt.text = minutes + ":" + seconds+"." + miliseconds;

    }
我的角色正在使用以下代码:

    /* Move with Keyboard Arrows
    Allows the specified symbol instance to be moved with the keyboard arrows.

    Instructions:
    1. To increase or decrease the amount of movement, replace the number 5 below with                the number of pixels you want the symbol instance to move with each key press.
    Note the number 5 appears four times in the code below.
    */

    var upPressed:Boolean = false;    
    var downPressed:Boolean = false;    
    var leftPressed:Boolean = false;    
    var rightPressed:Boolean = false;    

    rutte.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);    
    stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);    
    stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);    

    function fl_MoveInDirectionOfKey(event:Event)    
    {    
        if (upPressed)    
        {    
            rutte.y -= 5;    
        }    
        if (downPressed)    
        {    
            rutte.y += 5;    
        }    
        if (leftPressed)    
        {    
    rutte.x -= 5;    
    rutte.scaleX = 1; // face left    
}    
if (rightPressed)    
{    
    rutte.x += 5;    
    rutte.scaleX = -1; // face right    
}    
    }    

    function fl_SetKeyPressed(event:KeyboardEvent):void    
    {    
switch (event.keyCode)    
{    
    case Keyboard.UP:    
    {    
        upPressed = true;    
        break;    
    }    
    case Keyboard.DOWN:    
    {
        downPressed = true;    
        break;    
    }    
    case Keyboard.LEFT:    
    {    
        leftPressed = true;    
        break;    
    }    
    case Keyboard.RIGHT:    
    {    
        rightPressed = true;    
        break;    
    }    
}    
    }    

    function fl_UnsetKeyPressed(event:KeyboardEvent):void    
    {    
switch (event.keyCode)    
{    
    case Keyboard.UP:    
    {    
        upPressed = false;    
        break;    
    }    
    case Keyboard.DOWN:    
    {    
        downPressed = false;    
        break;    
    }    
    case Keyboard.LEFT:    
    {    
        leftPressed = false;     
        break;    
    }    
    case Keyboard.RIGHT:    
    {    
        rightPressed = false;    
        break;    
    }    
事先谢谢你能给我的一切帮助


问候。

在flash中,时间线和场景的工作原理有一个基本方面。从一个帧移到另一个帧后,该帧的内容及其属性/状态/操作将消失并重置

就我个人而言,我建议您使用一个场景,将时间线划分为带标签的帧,在那里您可以为动作和全局变量指定一个层,一个用于用户界面,另一个用于每个帧的特定动作。例如:

因此,您永远不会丢失变量的引用,因为帧不会不断地重新创建,所有重要的操作,包括计时器,都应该在第一帧中


我正在测试,在这里您可以看到一个工作示例:。在这里,您可以下载FLA文件,用作项目的基础:

是否使用场景,如gotoAndPlay(1,“场景2”);-如果是这样的话,您可能希望将内容放在单个场景中,并管理代码中的项目,而不是依赖场景。