Timing Animations within Script

One of the problems I am encountering as I put more animations script side, is the ability to have animations occur one after the other, rather than simultaneously.

Is there a straightforward way of having animations occur one after the other For example I want the following script to fire in sequence, one assignment after the other, but only after the previous one is completed.

document.FOO.style.animateProperty("x","500px",2);
// don't turn off display until animation completes
document.FOO_BUTTON.style.display = "none";

Is wait(time) supported (iHDSim does not like it)   If so is in sync with the application tick or what





Answer this question

Timing Animations within Script

  • ryan101

    It's part of the HDDVD spec: Annex Z.1

  • Iris Stern

    I cannot get this to work. Keeps throwing and HDDVD_E_ARGUMENT Exception (see bold):


    function OnSlideSceneButtonPressed(evt) {
    var id = evt.target.getAttribute("id");
    var currentPosition = sceneSliderPosition;
    if (id == "BTN_TRY_RT_ARW") {
    if (currentPosition == 1 ) {
    document.BTN_TRY_LF_ARW.style.navRight = "BTN_POS_04";
    document.BTN_TRY_RT_ARW.style.navLeft = "BTN_POS_06";
    document.SCN_GRP_1.style.animateProperty("x","0px;-575px",2);
    document.SCN_GRP_2.style.display = "auto";
    document.SCN_GRP_2.style.animateProperty("x","575px;0px",2);
    sceneSliderPosition = 2;

    } else if (currentPosition == 2) {
    document.BTN_TRY_LF_ARW.style.navRight = "BTN_POS_07";
    document.SCN_GRP_2.style.animateProperty("x","0px;-575px",2);
    document.SCN_GRP_3.style.display = "auto";
    document.SCN_GRP_3.style.animateProperty("x","575px;0px",2);
    sceneSliderPosition = 3;

    }

    } else if (id == "BTN_TRY_LF_ARW") {
    if (currentPosition == 2 ) {
    document.BTN_TRY_RT_ARW.style.navLeft = "BTN_POS_03";
    document.SCN_GRP_1.style.animateProperty("x","-575px;0px",2);
    document.SCN_GRP_2.style.display = "auto";
    document.SCN_GRP_2.style.animateProperty("x","0px;575px",2);
    sceneSliderPosition = 1;

    } else if (currentPosition == 3) {
    document.BTN_TRY_LF_ARW.style.navRight = "BTN_POS_07";
    document.BTN_TRY_RT_ARW.style.navLeft = "BTN_POS_03";
    document.SCN_GRP_2.style.animateProperty("x","-575px;0px",2);
    document.SCN_GRP_3.style.display = "auto";
    document.SCN_GRP_3.style.animateProperty("x","0px;575px",2);
    sceneSliderPosition = 2;

    }
    }
    timer = createTimer("00:00:01:00",TIMER_APPLICATION,SetSliderDisplay(id, currentPosition));
    timer.enabled = true;
    timer.autoReset = false;
    }

    function SetSliderDisplay(id, currentPosition) {
    if (id == "BTN_TRY_RT_ARW") {
    if (currentPosition == 1 ) {
    document.SCN_GRP_1.style.display = "none";
    document.BTN_TRY_LF_ARW.style.display = "auto";
    document.BTN_TRY_RT_ARW.style.display = "auto";

    } else if (currentPosition == 2) {
    document.SCN_GRP_2.style.display = "none";
    document.BTN_TRY_LF_ARW.style.display = "auto";
    document.BTN_TRY_RT_ARW.style.display = "none";

    }

    } else if (id == "BTN_TRY_LF_ARW") {
    if (currentPosition == 2 ) {
    document.SCN_GRP_2.style.display = "none";
    document.BTN_TRY_LF_ARW.style.display = "none";
    document.BTN_TRY_RT_ARW.style.display = "auto";

    } else if (currentPosition == 3) {
    document.SCN_GRP_3.style.display = "none";
    document.BTN_TRY_LF_ARW.style.display = "auto";
    document.BTN_TRY_RT_ARW.style.display = "auto";

    }
    }
    }

    var timer = null;
    var sceneSliderPosition = 1;



  • Bobby Dreamer

    The last argument to createTimer() is basically a function pointer. You cannot pass a function with arguments to it, as you are trying to do (b/c at that point, you are invoking the function and the return value from it is being passed as an argument to createTimer(), which it doesn't like very much). The callback from the timer object accepts no arguments, unfortunately, so you need to create your own mechanism for doing this

    To accomplish what you want, you'd need to do something like:

    // These variables are meant to illustrate the need for an outside mechanism

    // for caching the arguments to the callback.

    // I recommend a more robust mechanism for caching these, like a queue,

    // so you can handle multiple calls to OnSlideSceneButtonPressed (if that is

    // possible in your application

    var cachedId = null;

    var cachedCurrentPosition = null;

    function OnSlideSceneButtonPressed(evt) {

    // code removed for simplicity...

    cachedId = id;

    cachedCurrentPosition = currentPosition

    timer = createTimer("00:00:01:00",TIMER_APPLICATION,SetSliderDisplayWrapper);

    timer.enabled = true;

    timer.autoReset = false;

    }

    function SetSliderDisplayWrapper()

    {

    SetSliderDisplay(cachedId, cachedCurrentPosition);

    }



  • Galoleins

    The closest you can get to a sleep or wait function is a timer, which will call back to your app after the specified time:

    var timer = null;

    function someFunc()

    {

    document.FOO.style.animateProperty("x","500px",2);

    // don't turn off display until animation completes

    timer = createTimer("00:00:02:00", TIMER_APPLICATION, waitFunc);

    timer.enabled = true;

    timer.autoReset = false;

    }

    function waitFunc()

    {

    document.FOO_BUTTON.style.display = "none";

    }

    The timer is synced to the application clock. The above is simplified a bit, you may want to try waiting < 2 seconds and then poll the animated property value every few frames after that using a shorter timer, to get closer.



  • itznfb

    Thanks Josh. This pointed me in the right direction.


  • Robert Gregory Garfinkle

    Is timer part of the HD spec or the version of ECMA used by the spec


  • Timing Animations within Script