【问题标题】:How to decrement Timer variable - AS3如何减少 Timer 变量 - AS3
【发布时间】:2015-01-22 16:30:27
【问题描述】:

好吧,我的代码 AS3 中有两个 TIMER 类型的变量,但其中有一部分 我的游戏,我必须降低它们的价值。

var tempo1:Timer = new Timer(4000);
var tParada:Timer = new Timer(2000, 1);

我想知道如何从外部类开始减少这些值...

谢谢你。

【问题讨论】:

  • 这些变量定义在什么范围内?它们是实例变量吗?他们在时间线上吗?如果您可以访问该计时器实例,您始终可以使用它的 .delay 属性更改计时器实例的时间。
  • 朋友,她在舞台上...我可以通过外部课程访问它...你能举个例子说明她的时间是如何减少的吗?
  • 如果您可以访问它们,您只需像这样减少计时器: tempo1.delay = 100; //100 毫秒。与 tParada 相同。苏尔特。
  • 你可以补间它,如果这就是你的意思。 TweenLite.to(tempo1, 2, {delay: tempo1.delay - 100, ease: Quad.easeOut}) 这将在 2 秒内将延迟降低 100。 TweenLite 是 greensock 的一个外部库,如果您不为您的应用程序收费,它是免费的*使用。还有一个内置的 Tween 类也可以做同样的事情
  • 延迟属性是get/set。所以我假设你可以像 tempo1.delay -= 100 一样使用它

标签: actionscript-3 flash timer decrement


【解决方案1】:

只需在每次计时器触发时减少延迟。

var tempo1:Timer = new Timer(4000);
tempo1.addEventListener(TimerEvent.TIMER, tick);
var minValue:int = 1000;

tempo1.start();

function tick(e:TimerEvent):void {
    if(tempo1.delay - 100 >= minValue){
        tempo1.delay -= 100;
    }
}

或者,如果想让它更流畅,你可以这样做:

import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var tempo1:Timer = new Timer(33); //30 times a seconds or so
    tempo1.addEventListener(TimerEvent.TIMER, tick);
    var curTickTime:int = 4000;

    tempo1.start();

    function tick(e:TimerEvent):void {
        if(tempo1.delay * tempo1.currentCount >= curTickTime){
            trace("tick"); //this should effectively be a tick
            tempo1.reset();
            tempo1.start();

            //do whatever you do on a tick
        }
    }

//tween the tick delay from the starting value to 100ms over a period of 5 seconds
var tween:Tween = new Tween(this, "curTickTime", Strong.easeOut, curTickTime, 100, 5, true);

【讨论】:

    猜你喜欢
    • 2017-08-18
    • 2021-03-19
    • 2014-02-15
    • 1970-01-01
    • 2022-12-09
    • 2022-01-06
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    相关资源
    最近更新 更多