Actionscript 3 压缩AS3定时器
好的,我有一个电影剪辑的网格,总共有25个,我试图在不停止计时的情况下复制cornTimer多次。如果一个玩家激活了所有的25个牌,他们将需要25个玉米定时器。我想知道是否可以添加一些东西,比如cornTimer+count:timer=new timer; 诸如此类的事。还有其他建议吗?游戏的这一部分是在等轴测地图上创建一个小农场Actionscript 3 压缩AS3定时器,actionscript-3,flash,timer,Actionscript 3,Flash,Timer,好的,我有一个电影剪辑的网格,总共有25个,我试图在不停止计时的情况下复制cornTimer多次。如果一个玩家激活了所有的25个牌,他们将需要25个玉米定时器。我想知道是否可以添加一些东西,比如cornTimer+count:timer=new timer; 诸如此类的事。还有其他建议吗?游戏的这一部分是在等轴测地图上创建一个小农场 var menu:menuBG = new menuBG(); var farmSlots:Array = ["empty","empty","empty","em
var menu:menuBG = new menuBG();
var farmSlots:Array = ["empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty","empty"];
var farmSelected = "none";
var cornTimer:Timer = new Timer(100,150);//100 = 10 secs//
farmSlot1.addEventListener(MouseEvent.CLICK, farmClick1);
farmSlot2.addEventListener(MouseEvent.CLICK, farmClick2);
cornTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
function farmClick1(e:MouseEvent):void {
addChild(menu);
menu.x = 400;
menu.y = 90;
menu.buyCornBtn.addEventListener(MouseEvent.CLICK, buyCorn);
farmSelected = farmSlot1;
}
function buyCorn(e:MouseEvent):void {
menu.buyCornBtn.addEventListener(Event.ENTER_FRAME, cornloading);
cornTimer.start();
farmSelected.progressB.visible = true;
removeChild(menu);
}
function cornloading(e:Event):void {
var total:Number = 150;
var loaded:Number = cornTimer.currentCount;
farmSelected.progressB.bar.scaleX = loaded / total;
farmSelected.loader_txt.text = Math.round((loaded/total)*100)+ "%";
}
function onComplete(e:Event):void {
farmSelected.gotoAndStop("corn");
removeEventListener(Event.ENTER_FRAME, cornloading);
}
function farmClick2(e:MouseEvent):void {
addChild(menu);
menu.x = 400;
menu.y = 90;
menu.buyCornBtn.addEventListener(MouseEvent.CLICK, buyCorn);
farmSelected = farmSlot2;
}
您可以在stage上添加ENTER_FRAME事件处理程序,并将notify函数保存在数组中。因此,notify函数将在处理程序中调用,您不需要创建多个计时器 当互动程序变为活动状态时,在通知上添加通知。notify函数将接受一个参数,该参数指示两帧之间经过的时间。您可以计算平铺中经过的总时间,并在总时间等于所需值时执行某些操作 下面是一个简单的类,您可以添加notify
import flash.display.Stage;
import flash.events.Event;
import flash.utils.getTimer;
public class NotifyUtil {
private static var _instance:NotifyUtil;
public static function getInstance():NotifyUtil
{
if (_instance == null)
{
_instance = new NotifyUtil();
}
return _instance;
}
public function init(stage:Stage):void
{
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private var lastTime:int = 0;
private function onEnterFrame(e:Event):void
{
if (lastTime == 0)
{
lastTime = getTimer();
return;
}
var now:int = getTimer();
var passedTime:int = now - lastTime;
for each (var f:Function in notifies)
{
f.apply(null, [passedTime]);
}
lastTime = now;
}
private var notifies:Array = [];
public function addNotify(handler:Function):void {
if (handler == null)
{
return;
}
if (notifies.indexOf(handler) == -1)
{
notifies.push(handler);
}
}
public function removeNotify(handler:Function):void
{
if (handler == null)
{
return;
}
var index:int = notifies.indexOf(handler);
if (index != -1)
{
notifies.splice(index, 1);
}
}
}