[英]How to add a Timer in AS3
I was wondering how to add an ingame Timer in AS3, I made a health bar for enemy mobs and once mob is attacked, health bar is visible. 我想知道如何在AS3中添加一个游戏内计时器,我为敌人生物设置了一个健康栏,一旦生物受到攻击,就可以看到健康栏。 I need to add piece of code which if Enemy was not attacked for 5 Seconds,
healthBar.visible = false;
我需要添加一段代码,如果敌人没有受到攻击持续5秒钟,则
healthBar.visible = false;
but I have no idea how to deal with time in AS3 但我不知道如何处理AS3中的时间
any ideas ? 有任何想法吗 ?
My suggestions are as follows: 我的建议如下:
Assumed MouseClick is Ninja attacked hero. 假设MouseClick是忍者袭击的英雄。 If you using a this code you need to create Class or fit type.
如果使用此代码,则需要创建Class或fit type。 I just written skeleton code.
我只是写了框架代码。
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
stage.addEventListener(MouseEvent.CLICK, onAttacked);
var isAttacked:Boolean;
var timer:Timer = new Timer(100,50);
var alphaCount:Number = 1.0;
timer.addEventListener(TimerEvent.TIMER, onTick);
function onAttacked(e:MouseEvent):void
{
isAttacked = true;
timer.start();
}
function onTick(e:TimerEvent):void
{
alphaCount = 1.0 - ( 2 * timer.currentCount ) / 100;
if(!isAttacked)
{
goFadeStatusBar();
}
else
{
restoreStatusBar();
alphaCount = 1.0;
timer.reset();
timer.start();
isAttacked = false;
}
}
function goFade():void
{
bar.alpha = alphaCount;
}
function restore():void
{
bar.alpha = 1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.