Active Animations Table includes:
- All cursor animations (regardless of their status, i.e. currently playing or not).
- All animations that have started.
- Animations for the inventory items currently visible in the inventory panel.
You can check whether an animation is playing with:
Note: you can’t access active animations by id, you must iterate over them. Example for checking if a specific animation is currently playing:
function animPlaying(anim) for i = 1, #ActiveAnimations do if ActiveAnimations[i]:getName() == anim then return true -- anim already playing end end startAnimation(Animations[anim]) -- anim not playing, start it end
Random Loop Pauses
For animations that play in random intervals and they are hidden when not playing you can use Random Loop Pauses. Such animations could be for example cars or birds going from one screen edge to the other. By enabling the relevant option in animation’s properties, a Random Loop Pause between 5 and 20 seconds will be added between each animation play; during this pause the animation won’t be shown.
You can control the maximum possible Random Loop Pause with Lua:
ActiveAnimations["car"].WaitingTime = 30
Many times we need to have animations that play at random intervals but they have to be visible on screen at all times. E.g. a bird that is standing on a branch and flaps its wings at random intervals. For this we just need to add some code in the first two frames of the animation by adding the relevant ‘Execute Script’ action part.
Animations["bird_flap"].Pause = math.random(3000,6000) -- The bird will be shown idle for this random amount of time
Animations["bird_flap"].Pause = 100 -- the animation speed resumes back to the default value and the animation plays
Tip: to make things 100% random every time a game is started, it is advisable to run this code at every game start action:
math.randomseed( os.time() )
Sometimes we need to have an animation play forward and then backwards (or the opposite). You just need to set the first and last frame of the animation as follows:
ActiveAnimations[“labefana_hand”].PlayOppositeDirection = false
ActiveAnimations[“labefana_hand”].PlayOppositeDirection = true
Mirror / Flip Object Images and Animations
obj.ObjectScale = -1 -- (along both X and Y axis) obj.ObjectScaleX = -1 -- (along X axis) obj.ObjectScaleY = -1 -- (along Y axis)
Get the index of the currently active frame
Get the amount of frames of an animation
#activeanimation.SavedObject.Sprites -- # returns the length of the table
For cursor animations you need to define if you need the active or inactive cursor as follows:
ActiveAnimations[“cursor_look (inactive)”].LastFrame = 2 -- adjusting the inactive cursor ActiveAnimations[“cursor_look (active)”].FirstFrame = 1 -- adjusting the active cursor