AS 3 Flash倒数计时器,用于游戏画面显示 [英] AS 3 Flash Countdown Timer For Game Over Screen

查看:84
本文介绍了AS 3 Flash倒数计时器,用于游戏画面显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用动作脚本3参加Flash游戏编程课程,似乎无法找到倒计时然后执行动作的任何地方的时钟.我一直在使用Lynda教程,但并没有帮助,我也对Google进行了很多搜索,但没有运气.我有一个倒计时时钟,已经尝试过"if"语句,但是没有运气.

I am currently in a Flash game programming class with action script 3 and can't seem to find a clock anywhere that counts down and then does an action. I've been using Lynda tutorials and that hasn't been helpful and I have also Google searched quite a bit, but no luck. I have a Countdown clock and have been try "if" statements, but no luck.

有人可以在正确的方向上指导我做错什么吗?

Can someone guide me in the right direction on what I am doing wrong?

 //game timer

 var count:Number = 60; // amount of time 

 var myTimer:Timer = new Timer(1000,count); // time in ms, count is calling from line above

 myTimer.addEventListener(TimerEvent.TIMER, countdown);

 myTimer.start();

 function countdown(event:TimerEvent):void
 {
     myText_txt.text = String((count)-myTimer.currentCount); //dynamic txt box shows current count 
 }


 //if and else if statements

 if (((count)-myTimer.currentCount) == 58)
 {
     gotoAndStop(2);
 }

推荐答案

这应该有所帮助;)没有任何魔幻数字.

This should help ;) Without any magic numbers.

var myTimer:Timer = new Timer(1000,60); // every second for 60 seconds
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
myTimer.start();

function onTimer(e: TimerEvent):void {
    myText_txt.text = String(myTimer.repeatCount - myTimer.currentCount);
}

function onComplete(e: TimerEvent):void{
    gotoAndStop(2);
}

这篇关于AS 3 Flash倒数计时器,用于游戏画面显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆