/ HALion Developer Resource / HALion Macro Page / Templates /

Animation Script


On this page:


Animation Script

Description

The Animation Script template can be added to a macro page to run timer-controlled animations. These can be turned on and off by any parameter and the integrated script can be customized to set animation properties, such as the number of frames and the duration of a frame. There are two templates included in the Basic Controls library, the Animation Script template providing only the UI script and the Animation Script Example template, which includes additional components such as a play button, variables, and an example animation to show how the UI script can be connected.

Animation-Script-Template

To explore the functionality and connections:

  1. Load the Init Basic Controls.vstpreset from the Basic Controls library.
  2. Open the Macro Page Designer, go to the GUI Tree and navigate to "Pages > Animation Page".
  3. Select "Animation Script Example" and click Edit Element Edit Element to examine the template.

Template Properties

PopertyDescription
NameThe name of the element. This name will be displayed in the GUI Tree.
Position/SizePosition X, Position Y, Width, Height: Position and size of the element in pixels. Position X/Y defines the position of the upper left corner.
AttachDefines how an element behaves when its parent element is resized. You can set the following parameters:
  • Left: If the parent element is resized, the element remains attached to left edge, with the specified ratio.
  • Right: If the parent element is resized, the element moves relatively to the right edge, with the specified ratio.
  • Top: If the parent element is resized, the element remains attached to top edge, with the specified ratio.
  • Bottom: If the parent element is resized, the element moves relatively to the bottom edge, with the specified ratio.
  • Left + Right: If the parent element is resized, the element is resized horizontally relatively to the left and right edges, with the specified ratio.
TooltipText that appears as a tooltip when the mouse hovers over the element.
TemplateDetermines the template to be referenced.

Components inside the Template

Animation Script Example Template

UI Variables

These variables are needed to allow the communication between the Animation control, the Animation Script Template and the PLay button.

VariableDescriptionTypeRange
FramesA float variable to connect the Out parameter of the Animation Script Template with the Value of the Animation control.float0 - 1.0
OnAn integer variable to connect the On parameter of the Animation Script Template with the Play button.integer0 - 1

Controls and Subtemplates

ItemDescription
AnimationA SVG of a rotating star as an example animation. It is connected to the Animation Script Template by @Frames.
Animation Script TemplateThe template view that contains the UI script for controlling the animation. The template provides the following parameters:
  • On: Starts and stops the animation. Connected to the Play button by @On.
  • Out: The output of the script for controlling the animation. It is connected to the Animation control by @Frames.
  • Frames: The number of frames to be displayed (1 to 1000). The number is best set to the actual number of frames in the referenced animation. You can use a different number, e.g., use 50 for an animation with 100 frames, if you want to display only every second frame of the animation.
  • Frame Duration: Here you can specify the duration for each frame to be displayed. The duration is set in milliseconds (20 to 10.000).
PlayA Switch control to start and stop the animation. It is connected to the Animation Script Template by @On.

UI Script

function animate()
 while on do
  if out + inc <= 1  then
    out = out + inc
  else
	out = 0
  end
  wait(frameDuration)
 end
 
 out = 0
end

inc = 0.1
defineParameter{name = "on", default = false, onChanged = animate}
defineParameter{name = "out", default = 0, min = 0, max = 1}
defineParameter{name = "frames", default = 10, min = 1, max = 1000, type = "integer", onChanged = function() inc = 1 / frames end}
defineParameter{name = "frameDuration", default = 50, min = 20, max = 10000, type = "integer"}