Difference between revisions of "SetAnimFrames (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
m
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| setAnimFrames("ani", n1, n2) || Definition || AFRLme
+
| setAnimFrames("anim", f, t) || Definition || AFRLme
 
|}
 
|}
  
This small function allows you to quickly set the first & last frame of an active animation.
+
This small function allows you to quickly set the frame range of an animation.
 +
 
  
 
== Instructions ==
 
== Instructions ==
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
2. To use this function you should create an ''execute a script'' action containing...
+
2a. Example #1: forcing an animation to loop a single animation frame, in this case animation frame #1.
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
setAnimFrames("animation_name", 1, 1) -- set active animation animation_name's first frame to 1 & last frame to 1
+
setAnimFrames("example", 1)
 +
</syntaxhighlight>
 +
2b. Example #2: forcing an animation to loop a range of animation frames, in this case between animation frames #3 to #7.
 +
<syntaxhighlight lang="lua">
 +
setAnimFrames("example", 3, 7)
 +
</syntaxhighlight>
 +
2c. Example #3: force animation to loop between the 3rd frame & the total amount of animation frames belonging to the animation.
 +
<syntaxhighlight lang="lua">
 +
setAnimFrames("example", 3, #Animations["example"].Sprites)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
 
== Main Script ==
 
== Main Script ==
<syntaxhighlight>
+
<syntaxhighlight lang="lua">
function setAnimFrames(ani, n1, n2)
+
function setAnimFrames(anim, f, t)
getObject("ActiveAnimations[" .. ani .. "]"):setValue(VAnimationFirstFrame, n1)
+
  t = t or f -- fallback in case t equals nil
getObject("ActiveAnimations[" .. ani .. "]"):setValue(VAnimationLastFrame, n2)
+
  if f > t then f = t end -- fallback in case f is greater than t
end
+
  ActiveAnimations[anim].FirstFrame = f -- update from animation frame range
</syntaxhighlight>
+
  ActiveAnimations[anim].LastFrame = t -- update to animation frame range
 
 
=== Shorthand Version ===
 
<syntaxhighlight>
 
function setFrames(ani, n1, n2)
 
n2 = n2 or n1 -- fall-back in case n2 = nil (will use same value as n1)
 
ActiveAnimations[ani].AnimationFirstFrame = n1
 
ActiveAnimations[ani].AnimationLastFrame = n2
 
 
end
 
end
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 38: Line 41:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:70%" | Description
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left;width:70%" | Description
 
|-
 
|-
| ani || "string" || This should be a "string" value containing the name of the animation you want to affect.
+
| anim || "string" || This should be a "string" value containing the name of the animation you want to affect.
 
|-
 
|-
| n1 || integer || This should be an integer (number) value which will determine which frame will be the initial (from) frame of the linked animation (ani).
+
| f || integer || This should be an integer (number) value which will determine which frame will be the initial (from) frame of the linked animation (anim).
 
|-
 
|-
| n2 || integer || This should be an integer (number) value which will determine which frame will be the final (to) frame of the linked animation (ani).
+
| t || integer || This should be an integer (number) value which will determine which frame will be the final (to) frame of the linked animation (anim).
 
|}{{toc}}
 
|}{{toc}}

Latest revision as of 21:33, 21 August 2022

Name Type By
setAnimFrames("anim", f, t) Definition AFRLme

This small function allows you to quickly set the frame range of an animation.


Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2a. Example #1: forcing an animation to loop a single animation frame, in this case animation frame #1.

setAnimFrames("example", 1)

2b. Example #2: forcing an animation to loop a range of animation frames, in this case between animation frames #3 to #7.

setAnimFrames("example", 3, 7)

2c. Example #3: force animation to loop between the 3rd frame & the total amount of animation frames belonging to the animation.

setAnimFrames("example", 3, #Animations["example"].Sprites)


Main Script

function setAnimFrames(anim, f, t)
  t = t or f -- fallback in case t equals nil
  if f > t then f = t end -- fallback in case f is greater than t
  ActiveAnimations[anim].FirstFrame = f -- update from animation frame range
  ActiveAnimations[anim].LastFrame =  t -- update to animation frame range
end


Syntax Breakdown

Name Type Description
anim "string" This should be a "string" value containing the name of the animation you want to affect.
f integer This should be an integer (number) value which will determine which frame will be the initial (from) frame of the linked animation (anim).
t integer This should be an integer (number) value which will determine which frame will be the final (to) frame of the linked animation (anim).