startAnimation()

The function startAnimation() starts an animation group.

Synopsis

int startAnimation(int id [, string deletionPolicy] [, mapping options]);

Parameters

Parameter Description
id

The ID (> 0) the function createAnimation() returns when creating a parallel or sequential group

Use this ID when calling the function animate() as first argument to fill the group with separate animations and the to start the specific animation. See the example below:

g = createAnimation(); .

startAnimation(g, "keep", makeMapping("direction", "Forward"));

deletionPolicy

The deletionPolicy can be specified as:

"keep": defines that the animation is kept after it stops. When "keep" is used, the animation is only deleted when the panel is closed (when a top level group is deleted, all child groups are deleted as well)

or "delete" (default): deletes itself after it stops (making the group id invalid).

The "keep" animation option, makes it possible to start the same group a second time or even to run it backwards, specifying the option makeMapping("direction", "Backward");

options

The options for an animation group (parallel, sequential) - see chapter createAnimation() can use the options "duration", "loopCount" and "direction"

The group defines the direction. Mixing directions in the single added animations is not supported. The "pause" animation in a sequential group can be used to delay the start of the following animation.

"duration"/int ... duration of animation in msecs, the default value is 600ms

"loopCount"/int ... number of times the animation is run. default=1. (0=don't run; -1=run endlessly.)

"direction"/string ... "Forward" or "Backward" movement. The default is "Forward". The option "Backward" reverses

and runs from endValue to startValue

Three different examples:

startAnimation(g, "keep", makeMapping("duration",500));

startAnimation(g, "keep", makeMapping("loopCount",3));

startAnimation(g, "keep", makeMapping("direction", "Forward"));

If you want to start an animation with several options, you can add several options to a mapping as follows:

startAnimation("sequential", makeMapping("duration", 500, "loopCount", 3, "direction", "Forward"));

Return value

The function returns 0 when it was executed successfully and -1 in case of errors.

Description

The function startAnimation() starts an animation group.

Note that animations need a lot of CPU. When animations run for a longer period of time, this might be noticeable!

Example

Add the example script to the "clicked" event of a graphics object, for example, rectangle or circle. The script moves the graphics object forwards and backwards and changes the background color.

color.

int g;
bool forward = true;
main()
{
  if ( !g )
  {
    g = createAnimation();
/* Creates an animation */
    animate(g, "", "position", this.positionAsDyn, makeDynInt(300, 200));
    animate(g, "", "backCol", "{54,132,15}", "{248,28,120}");

/* backCol changes the background color */
  }
  if ( forward )
    startAnimation(g, "keep", makeMapping("direction", "Forward"));
  else
    startAnimation(g, "keep", makeMapping("direction", "Backward"));

/* Starts an animation and moves the graphics object forwards and backwards */
  forward = !forward;
}

The following example opens a panel via the function RootPanelOnModule() and moves and scales the panel up when it is opened. Note that in order to use this script, you need panels called "empty.pnl" and ""flyIn.pnl". Add the script to the "clicked" event of a button.

int g;
bool isShown = false;
main()
{
  if ( isShown )
  {
    stopAnimation(g);
    RootPanelOnModule("empty", "empty", flyInModule.ModuleName, "");



   /* Opens the panel "empty" in the module "flyInModule.ModuleName */
    startAnimation(g, "keep", makeMapping("direction", "Backward"));



   /* Moves the panel backwards */
    this.fill = "[pattern,[fit,any,arrow_left_modern.png]]";



   /* Loads the image for the button */
    isShown = false;
  }
  else
  {
    if ( !g )
    {
      g = createAnimation();
/* Creates an animation group */
      flyInModule.visible = true;
/* Sets the module visible */
      animate(g, "flyInModule", "sizeAsDyn", makeDynInt(0, 0),makeDynInt(581, 341), makeMapping("duration", 600));
      animate(g, "flyInModule", "positionAsDyn", makeDynInt(809, 100),


      makeDynInt(34, 170), makeMapping("duration", 600));
    }
/* Creates an animation and changes the size and position of the panel "flyInModule" */
      startAnimation(g, "keep", makeMapping("direction", "Forward"));
     /* Moves the animation "g" forwards */
      RootPanelOnModule("flyIn", "flyIn", flyInModule.ModuleName, "");
      this.fill = "[pattern,[fit,any,arrow_right_modern.png]]";



/* Loads the image for the button */


      isShown = true;
  }
}

Assignment

Graphic functions

Availability

UI