【问题标题】:Making The Seconds Hand On A Countdown Timer Spin Rather Than Tick让秒针在倒数计时器上旋转而不是滴答作响
【发布时间】:2019-02-19 02:46:59
【问题描述】:

我是一名教师,一直在寻找可在课程中使用的可自定义倒数计时器(我还希望能够将其嵌入 Powerpoint)。

我找到了下面的代码,但我想更新图形并可能使秒针平稳旋转而不是滴答声。

图形方面不是问题,但我正在努力处理代码。我可以通过改变让手以更小的增量移动

hand.rotation +=6;  
// to  
hand.rotation +=1; 

但它仍然仅以每秒 1 个增量移动。谁能指出我正确的方向?

代码:

// "Countdown Timer" by Lemmyz

//variables
var count:int;
var timer:Timer = new Timer(1000);

//Sound objects
var alertSnd:Sound = new Alert();
var endSnd:Sound = new AlertEnd();
var startSnd:Sound = new AlertStart();

//Button event listeners
btnStart.addEventListener(MouseEvent.MOUSE_UP, timerStart);
btnStop.addEventListener(MouseEvent.MOUSE_UP, timerStop);
btnReset.addEventListener(MouseEvent.MOUSE_UP, timerReset);
btnOK.addEventListener(MouseEvent.MOUSE_UP, setCount);

//timer object
timer.addEventListener(TimerEvent.TIMER, rot);

//init
txt.text = "Set countdown seconds";
btnStart.enabled = false;
btnReset.enabled = false;
btnStop.enabled = false;

//Functions
function setCount(evt:MouseEvent):void
{
    count = parseInt(inputNum.text);
    btnStart.enabled = true;
    txt.text = "Press START.\n" + count + " secs remaining";
}

function timerStart(evt:MouseEvent):void
{
    endSnd.play();
    timer.start();
    btnStart.enabled = false;
    btnReset.enabled = false;
    btnOK.enabled = false;
    btnStop.enabled = true;

}

function timerStop(evt:MouseEvent):void
{
    timer.stop();
    btnStop.enabled = false;
    btnReset.enabled = true;
    btnStart.enabled = true;
    btnStart.label = "RESUME";
}

function timerReset(evt:MouseEvent):void
{
    timer.stop();
    hand.rotation = 0;
    count = parseInt(inputNum.text);
    btnStop.enabled = false;
    btnReset.enabled = false;
    btnOK.enabled = true;
    btnStart.label = "START";
    txt.text = "Timer reset to " + count + " secs. " + count + " secs remaining";
}

function rot(evt:TimerEvent):void
{
    if (count==0)
    {
        timer.stop();
        hand.rotation = 0;
        count = 60;
        btnReset.enabled = false;
        btnStop.enabled = false;
        btnStart.label = "START";
        btnStart.enabled = true;
        btnOK.enabled = true;
    }
    else
    {
        if (count==31||count==16)
        {
            alertSnd.play();
            count--;
            hand.rotation +=  6;
        }
        else

    {
        count--;
        hand.rotation +=  6;
    }
    if (count==0)
    {
        txt.text = "Time's up! Timer is reset. Press START again.\n" + count + " secs remaining.";
        startSnd.play();
    }
    else
    {
        txt.text = count + " secs remaining";
    }
}
}

提前谢谢你。

【问题讨论】:

    标签: actionscript-3 flash animate-cc


    【解决方案1】:

    这行代码表示定时器每隔一秒(1000毫秒)触发一次:

    //variables
    var timer:Timer = new Timer(1000);
    

    如果将其更改为较小的数字,例如 100,它将每 100 毫秒调用一次 rot 函数。但我可以看到你的代码中有依赖于 1000 个数字,所以你的计时器可能不起作用。

    我认为在您的情况下,最佳做法是“补间”手,而不是更改计时器间隔。而不是hand.rotation += 6; 试试这个函数:

    import fl.transitions.Tween;
    ...
    // wherever you start the timer call tweenHand function
    timer.start();
    tweenHand();
    ...
    // also instead of every hand.rotation += 6; call tweenHand function
    tweenHand();
    ...
    function tweenHand(): void {
        var currRotation: Number = hand.rotation;
        var myTween: Tween = new Tween(hand, "rotation", null, currRotation, currRotation + 6, 1, true);
        myTween.start();
    }
    

    【讨论】:

    • 谢谢,感谢您的帮助,并会尝试您建议的代码
    • 不客气@lukep1984,请随时将您的 .fla 文件发送给我,以便我仔细查看它,也许我可以修复它。
    • 那太好了。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多