我目前正在制作一款游戏,您需要尽可能长时间地生存,同时避开您遇到的问题。 (全部带AS3)
目前我在游戏区域和问题区域之间从1个场景到另一个场景,但每次我进入问题场景时,游戏场景中的计时器都会重置。我想知道在问题场景中是否有可能让计时器继续?
此外,我在菜单之间有一个可移动的角色,偶然也可以在不同的场景中制作,玩家可以移动他,我非常希望他留在他在下一个屏幕的最后位置,如我将他移到主菜单的右上方,当我进入选项菜单时,我希望他仍然在右上角,而不是在他的初始位置。
至于我的计时器,这是我目前正在使用的代码:
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;
}
提前感谢您提供给我的所有帮助。
亲切的问候。
答案 0 :(得分:0)
我个人建议你使用一个时间轴划分为标记帧的单个场景,在那里你可以为动作和全局变量指定一个层,一个用于用户界面,另一个用于每个帧的特定动作。例如:
所以你永远不会丢失变量的引用,因为不会不断重新创建框架,所有重要的操作,包括你的计时器,都应该在你的第一帧中。
我正在测试,在这里你可以看到一个有效的例子:http://db.tt/FZuQVvt3。在这里,您可以下载FLA文件作为项目的基础:http://db.tt/RHG9G5lo