Skip to main content

iRidi API. Animation

Native methods for animating iRidi Studio objects.

Documentation updated 01.01.2024

Tip

Example: Animation

Description​

The new native animation methods create the same animations as the animation library, but projects using native methods require fewer device resources.

Methods​

Methods for creating, editing, and deleting animations:

IR.AddAnimation()​

Creates an animation.

Syntax:

IR.AddAnimation( 

[ in_oAnimation1, in_oAnimation2, … , in_oAnimationN ]

[ in_rItem1, in_rItem2, … , in_rItemN ]

in_nDuration,

in_nDelay,

in_bRepeat,

in_bAutostart,

in_rStartCallBack,

in_rEndCallBack,

in_oContext

);

InputValueDescription
[ in_oAnimation1, in_oAnimation2, … , in_oAnimationN ]Type: IR.ANIMATION_MOVE_HORIZONTAL,
Tween: IR.LINEAR,
Duration: 1000,
From: 421,
To: 300,
Return: true,
Repeat: true
type: Object
Array of animations or a single JSON object
Type: animation type from the list
Tween: tweener type from the list (optional)
Delay: animation start delay (optional)
Duration: animation duration (optional)
Repeat: animation repetition (optional)
Return: reverse the animation after it finishes (optional)
Parameter1: Value1
…
ParameterN: ValueN
[ in_rItem1, in_rItem2, … , in_rItemN ]["UI.Page 2.Item 21"],
IR.GetPage("Page 2").GetItem("Item 1")
type: Object
Array of items, or a single reference to a graphic item
in_nDuration1000type: Number
Duration of the animation (animation array) (ms)
in_nDelay0type: Number
Start delay of the animation (animation array) (ms)
in_bRepeatfalsetype: Boolean
Loop the animation (animation array)
in_bAutostartfalsetype: Boolean
Flag for automatically starting the animation when created
in_rStartCallBackfunction onStart()
IR.Log(this.OnStart)
type: Object
Start callback: invokes a function when the animation starts
in_rEndCallBackfunction onEnd()
IR.Log(this.OnEnd)
type: Object
End callback: invokes a function when the animation finishes
in_oContextOnStart: "Animation started",
OnEnd: "Animation ended"
type: Object
Callback context: the function (this) that can be called by the animation's start or end callback
Output
in_oAnimationanimationtype: Object
Animation object
Note

Animation parameters depend on animation type; the complete parameter list is available here.

The item's X and Y coordinates are shown on General and on the dynamic toolbar in iRidi Studio. The coordinate origin is at the upper-left corner.

Example

//Пример 1 (перемещение элемента по горизонтали из координаты X = 421 в координату X = 300 и обратно 
// в течении 1 секунды):

var animation;
//создаём объект анимации:
animation = IR.AddAnimation({
Type: IR.ANIMATION_MOVE_HORIZONTAL, // тип анимации: перемещение по горизонтали
Tween: IR.LINEAR, // линейная функция
Duration : 1000, //длительность анимации 1 сек.
From : 421, // начальная точка X=421
To: 300, // конечная точка Х = 300
Return: true, // повтор анимации в обратном порядке после окончания
Repeat: false // не зацикливать анимацию
},
IR.GetPage("Page 2").GetItem("Item 1"), // привязываем анимацию к элементу
1000, // длительность анимации (массива анимаций)
0, // задержка анимации = 0 (массива анимаций)
false, // анимация (массив анимаций) не зациклина
false, // анимация не начинается по запуску приложения
)

//Пример 2 (перемещение элемента по горизонтали из координаты X = 421 в координату X = 300 и обратно
// в течении 1 секунды с вызовом функций начала и конца анимации):

//создаём объект анимации:
var animation = IR.AddAnimation({
Type: IR.ANIMATION_MOVE_HORIZONTAL, // тип анимации: перемещение по горизонтали
Tween: IR.LINEAR, // линейная функция
Duration : 1000, //длительность анимации 1 сек.
From : 421, // начальная точка X=421
To: 300, // конечная точка Х = 300
Return: true, // повтор анимации в обратном порядке после окончания
Repeat: false // не зацикливать анимацию
},
IR.GetPage("Page 2").GetItem("Item 1"), // привязываем анимацию к элементу
1000, // длительность анимации (массива анимаций)
0, // задержка анимации = 0 (массива анимаций)
false, // анимация (массив анимаций) не зациклина
false, // анимация не начинается по запуску приложения
function() { // активация функции по старту анимации (колбек начала)
IR.Log(this.OnStart);
},
function() { // активация функции по окончанию анимации (колбек окончания)
IR.Log(this.OnEnd);
},
{ OnStart : "Анимация стартовала", OnEnd : "Анимация закончилась" } // описание функций (вызываемый контекст колбеков)
)

IR.RemoveAnimation()​

Deletes an animation.

Syntax:

IR.RemoveAnimation(in_oAnimation);

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.

Example

animation = IR.AddAnimation({
Type: IR.ANIMATION_SIZE_HORIZONTAL,
Tween: IR.TWEEN_SINE_IN,
Duration : 1000,
From: 96,
To: 189,
Return: true,
Repeat: true
},
["UI.Page 2.Item 21"],
1000,
0,
true,
false,
)

IR.RemoveAnimation(animation)

IR.StartAllAnimations()​

Starts all animations.

Syntax:

IR.StartAllAnimations();

InputValueDescription
---------

Example

function doStartAll() 
{
IR.StartAllAnimations();
}

IR.StopAllAnimations()​

Stops all animations.

Syntax:

IR.StopAllAnimations();

InputValueDescription
--------

Example

function doStopAll() {
IR.StopAllAnimations();
}

.Start()​

Starts an animation.

Syntax:

in_oAnimation.Start();

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.

Example

function doStart() {
animation.Start();
}

.Stop()​

Stops an animation.

Syntax:

in_oAnimation.Stop();

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.

Example

function doStop() {
animation.Stop();
}

.AddItem()​

Adds a graphic item to the animation

Syntax:

in_oAnimation.AddItem(Item)

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
ItemIR.GetPage("Page 2").GetItem("Item 21")type: Object
Graphic item object.

Example

function doAddItem() {
animation.AddItem(IR.GetPage("Page 2").GetItem("Item 21"));
}

.RemoveItem()​

Removes a graphic item from the animation.

Syntax:

in_oAnimation.RemoveItem(Item)

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
ItemIR.GetPage("Page 2").GetItem("Item 21")type: Object
Graphic item object.

Example

function doRemoveItem() {
animation.RemoveItem(IR.GetPage("Page 2").GetItem("Item 21"));
}

.AddParameter()​

Add a parameter to the animation.

Syntax:

in_oAnimation.AddParameter(Parameter)

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
ParameterType: IR.ANIMATION_SIZE_HORIZONTAL
Tween: IR.TWEEN_SINE_IN
Duration: 1000
From: 96
To: 189
Return: true
Repeat: true
type: Object
Animation parameter.

Example

animation.AddParameter({
Type: IR.ANIMATION_SIZE_HORIZONTAL,
Tween: IR.TWEEN_SINE_IN,
Duration : 1000,
From: 96,
To: 189,
Return: true,
Repeat: true
})

.GetParameter()​

Get a parameter by index.

Syntax:

in_oAnimation.GetParameter(Index)

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
Index0-ntype: Number
Sequential parameter number.
Output
ParameterType: IR.ANIMATION_SIZE_HORIZONTAL
Tween: IR.TWEEN_SINE_IN
Duration: 1000
From: 96
To: 189
Return: true
Repeat: true
type: Object
Animation parameter.

Example animation.GetParameter(0);

.GetParametersCount()​

Get the number of parameters.

Syntax:

in_oAnimation.GetParametersCount()

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
Output
num4type: Number
Number of parameters.

Example animation.GetParametersCount() //4

.RemoveParameter()​

Remove a parameter by index.

Syntax:

in_oAnimation.RemoveParameter(Index)

InputValueDescription
in_oAnimationanimationtype: Object
Animation object.
Index0-ntype: Number
Sequential parameter number.

Example animation.RemoveParameter(0)

Animation type​

Animation type specifies the movement direction, rotation, hiding, or other item-animation behavior.

  • IR.ANIMATION_MOVE_HORIZONTAL - move an item horizontally between points;
  • IR.ANIMATION_MOVE_VERTICAL - move an item vertically between points;
  • IR.ANIMATION_MOVE - move an item diagonally between points;
  • IR.ANIMATION_SHIFT_HORIZONTAL - shift an item horizontally by a specified number of pixels;
  • IR.ANIMATION_SHIFT_VERTICAL - shift an item vertically by a specified number of pixels;
  • IR.ANIMATION_SHIFT - shift an item diagonally by a proportional pixel displacement;
  • IR.ANIMATION_SIZE_HORIZONTAL - resize an item horizontally;
  • IR.ANIMATION_SIZE_VERTICAL - resize an item vertically;
  • IR.ANIMATION_SIZE - resize an item diagonally and proportionally;
  • IR.ANIMATION_SCALE_HORIZONTAL - scale an item horizontally;
  • IR.ANIMATION_SCALE_VERTICAL - scale an item vertically;
  • IR.ANIMATION_SCALE - scale an item diagonally and proportionally;
  • IR.ANIMATION_ROTATE - rotate an item;
  • IR.ANIMATION_OPACITY - show or hide an item;
  • IR.ANIMATION_VALUE - change an item's Value.

Animation parameters​

Each animation type has its own parameters:

IR.ANIMATION_MOVE_HORIZONTAL​

  • From - starting X position (default = current position);
  • To - final X position (default = current position).

IR.ANIMATION_MOVE_VERTICAL​

  • From - starting Y position (default = current position);
  • To - final Y position (default = current position).

IR.ANIMATION_MOVE​

  • From - starting X and Y position (default = current position);
  • To - final X and Y position (default = current position);
  • FromX - X coordinate of the starting position (default = current position);
  • FromY - Y coordinate of the starting position (default = current position);
  • ToX - X coordinate of the final position (default = current position);
  • ToY - Y coordinate of the final position (default = current position).
Note

If FromX, FromY, ToX, and ToY are present, they are used; otherwise, From and To are used respectively.

IR.ANIMATION_SHIFT_HORIZONTAL​

  • From - initial horizontal displacement in pixels (0 - current position, -100 - left by 100px, 200 - right by 200px, etc.) (default = 0);
  • To - horizontal pixel displacement (default = 0).

IR.ANIMATION_SHIFT_VERTICAL​

  • From - initial vertical displacement in pixels (0 - current position, -100 - left by 100px, 200 - right by 200px, etc.) (default = 0);
  • To - vertical pixel displacement (default = 0).

IR.ANIMATION_SHIFT​

  • From - initial diagonal displacement in pixels (0 - current position, -100 - left and up by 100px, 200 - right and down by 200px, etc.) (default = 0);
  • To - diagonal pixel displacement (default = 0);
  • FromHorizontal - initial horizontal displacement in pixels (0 - current position, -100 - left by 100px, 200 - right by 200px, etc.) (default = 0);
  • FromVertical - initial vertical displacement in pixels (0 - current position, -100 - left by 100px, 200 - right by 200px, etc.) (default = 0);
  • ToHorizontal - horizontal pixel displacement (default = 0);
  • ToVertical - vertical pixel displacement (default = 0).
Note

If FromHorizontal, FromVertical, ToHorizontal, and ToVertical are present, they are used; otherwise, From and To are used respectively.

IR.ANIMATION_SIZE_HORIZONTAL​

  • From - initial item width (default = current width);
  • To - final item width (default = current width).

IR.ANIMATION_SIZE_VERTICAL​

  • From - initial item height (default = current height);
  • To - final item height (default = current height).

IR.ANIMATION_SIZE​

  • From - initial item width and height (default = current values);
  • To - final item width and height (default = current values);
  • FromWidth - initial item width (default = current width);
  • FromHeight - initial item height (default = current height);
  • ToWidth - final item width (default = current width);
  • ToHeight - final item height (default = current height).
Note

If FromWidth, FromHeight, ToWidth, and ToHeight are present, they are used; otherwise, From and To are used respectively.

IR.ANIMATION_SCALE_HORIZONTAL​

  • From - initial width factor (1 if omitted);
  • To - final width factor (1 if omitted).

IR.ANIMATION_SCALE_VERTICAL​

  • From - initial height factor (1 if omitted);
  • To - final height factor (1 if omitted).

IR.ANIMATION_SCALE​

  • From - initial size factor (1 if omitted);
  • To - final size factor (1 if omitted);
  • FromHorizontal - initial width factor (1 if omitted);
  • FromVertical - initial height factor (1 if omitted);
  • ToHorizontal - final width factor (1 if omitted);
  • ToVertical - final height factor (1 if omitted).
Note

If FromHorizontal, FromVertical, ToHorizontal, and ToVertical are present, they are used; otherwise, From and To are used respectively.

IR.ANIMATION_ROTATE​

  • From - starting rotation angle (if omitted, rotates from the current angle);
  • To - final rotation angle.

IR.ANIMATION_OPACITY​

  • From - starting item opacity (default = current opacity);
  • To - final item opacity (default = current opacity).

IR.ANIMATION_VALUE​

  • From - initial value (default = current value);
  • To - final value (default = current value).

Tweener type​

The tweener specifies how animation is calculated. Its formula determines intermediate values over the selected interval. Each formula has a number to pass to the function when creating the animation.

TypeOfTween.png

Formula names and numbers:

  • IR.TWEEN_LINEAR = 0;
  • IR.TWEEN_SINE_IN = 1;
  • IR.TWEEN_SINE_OUT = 2;
  • IR.TWEEN_SINE_IN_OUT = 3;
  • IR.TWEEN_QUINT_IN = 4;
  • IR.TWEEN_QUINT_OUT = 5;
  • IR.TWEEN_QUINT_IN_OUT = 6;
  • IR.TWEEN_QUART_IN = 7;
  • IR.TWEEN_QUART_OUT = 8;
  • IR.TWEEN_QUART_IN_OUT = 9;
  • IR.TWEEN_QUAD_IN = 10;
  • IR.TWEEN_QUAD_OUT = 11;
  • IR.TWEEN_QUAD_IN_OUT = 12;
  • IR.TWEEN_EXPO_IN = 13;
  • IR.TWEEN_EXPO_OUT = 14;
  • IR.TWEEN_EXPO_IN_OUT = 15;
  • IR.TWEEN_ELASTIC_IN = 16;
  • IR.TWEEN_ELASTIC_OUT = 17;
  • IR.TWEEN_ELASTIC_IN_OUT = 18;
  • IR.TWEEN_CUBIC_IN = 19;
  • IR.TWEEN_CUBIC_OUT = 20;
  • IR.TWEEN_CUBIC_IN_OUT = 21;
  • IR.TWEEN_CIRC_IN = 22;
  • IR.TWEEN_CIRC_OUT = 23;
  • IR.TWEEN_CIRC_IN_OUT = 24;
  • IR.TWEEN_BOUNCE_IN = 25;
  • IR.TWEEN_BOUNCE_OUT = 26;
  • IR.TWEEN_BOUNCE_IN_OUT = 27;
  • IR.TWEEN_BACK_IN = 28;
  • IR.TWEEN_BACK_OUT = 29;
  • IR.TWEEN_BACK_IN_OUT = 30.