-
Notifications
You must be signed in to change notification settings - Fork 0
animation
content/animation defines pplaf.animation - Animation framework.
Examples: assets/animations/
pewpew has basic features, that allow you to create 30/60fps animations. PPLAF automates this process and adds a lot of flexible features.
To define PPLAF animation, first we have to create file that returns table with animation's type. Some things are optional. If they won't be presented, they will be automatically set to certain values that shouldn't affect your animation if everything else is correct. Basic PPLAF animation looks like:
local frame_amount = 90
return {
template = 0,
frames_per_tick = 2,
frame_offset = 0,
variation_amount = 10,
frame_amount = frame_amount,
path = '/dynamic/pplaf/assets/meshes/flamethrower.lua',
actions = {
{'wait', frame_amount},
},
}
template- index, which defines how animation is stored and will be processed.frames_per_tick- if1, every tick, meshAis applied to entity, 30fps animation. If2, every tick, meshesAandA + 1are applied to entity, 60fps animation.frame_offset- additional offset, which allows you to store additional frames after ones, used in animation. If isn't presented, it is automatically set to 0.variation_amount- amount of variations, animation has. If not presented, it is automatically set to 1.frame_amount- amount of frames one animation's variation has.path- path to file, containing animation or folder, containing animation files, named from1.luatoN.lua.actions- table, containing actions, tables with parameters, that tellPPLAF, how it should animate entity in that moment.
The best practice would be defining animation type, loading it and requiring it by mesh/animation/animation generator. This way you can change parameters once and they will be changed both in animation settings and in mesh itself.
More information about how animation framework requires you to store meshes is available at Storing Frames.
We defined animation type and created entity, containing corresponding animation. Let's see, what stored in this animation:
type- table, containinganimation type.frame- current frame. Frame is incremented depending onframes_per_tickandframe_offset.action- index of current action.action_param- table, containing copy of current action fromanimation.type.actions. Parameters in this table will be changed over time, they're used to process action.variation_index- index of variation[0; N - 1], that will be used by this animation. It is set to 0, but you can also callentity:set_animation_variation(index)to change this value and corresponding offset.variation_offset- automatically calculated, depending onvariation_indexandframe_amount. It is used to calculate current frame.
animation.templates contains templates, which define how animation is stored and will be processed:
sf= 0 - animation is stored in single file,Avariations are stored in this file, every variation containsBframes.mf_variation= 1 - animation is stored in multiple files, every file represents 1 variation of animation and containsBframes.mf_frame= 2 - animation is stored in multiple files, every file represents 1 frame of animation and containsAvariations.mf_variated_frame= 3 - animation is stored in multiple files, every file represents 1 variation of 1 frame.
PPLAF animations require you to store frames in certain way. Templates can change these requirements, but overall idea is same. You store B frames for single variation. These frames are divided by ticks, so there are C frames per tick. In C frames first or first 2 frames(depending on frames_per_tick value) are used by animation framework to animate entity. Next frames aren't used, but can be allocated for manual use by changing value of frame_offset. The most common use for this additional frame is damaged variation of entity mesh. Same can be achieved by modifying color of the mesh, if it's simple enough or by creating another mesh, containing only frames with damaged entity. So, you have plenty options. So, C = frames_per_tick + frame_offset and you alternate C frames for every tick.
PPLAF animations require you to determine, how entity will be animated. Actions system allows you to create order of animations, loops, etc. Action is filled like:
{'wait', 10}
{100, 10}First parameter is action type or corresponding index. Names are automatically replaced with corresponding indexes when animation is loaded. Next parameters are defined by action type itself. Action types are stored in animation.actions:
wait- {100, N} - mesh isn't set, waiting forNticks; frames aren't incremented; afterNframes go to next actionwait_and_increment- {101, N} - mesh isn't set, waiting forNticks; frames are incremented; afterNframes go to next actionwait_and_decrement- {102, N} - mesh isn't set, waiting forNticks; frames are decremented; afterNframes go to next actionanimate- {200, A} - mesh is set to current frame while frame is in less thanA; frames are incremented; after frame is equal toAgo to next actionanimate_back- {201, A} - mesh is set to current frame while frame is in more thanA; frames are decremented; after frame is equal toAgo to next actionloop- {300, A, B} - mesh is set to current frame, after frame is equal toB, frame is set toA; frames are incrementedloopW- {301, A, B, Q} - mesh is set to current frame, after frame is equal toB, frame is set toA; frames are incremented; afterQloops go to next action(last frame is kept instead of being reset toA)loop_back- {302, A, B} - mesh is set to current frame, after frame is equal toA, frame is set toB; frames are decrementedloop_backW- {303, A, B, Q} - mesh is set to current frame, after frame is equal toA, frame is set toB; frames are decremented; afterQloops go to next action(last frame is kept instead of being reset toB)loop_back_forth- {304, A, B} - mesh is set to current frame; mesh is incremented/decremented after reaching corresponding frameloop_back_forthW- {305, A, B, Q} - mesh is set to current frame; mesh is incremented/decremented after reaching corresponding frame; afterQloops(forth-back loops, double for full loops) go to next action(last frame is kept instead of being reset toA/B)set_frame- {400, N} - frame is set toN; go to next action
types - table, containing loaded types with type names as their keys.
template - table, containing indexes, which determine how animation is stored and will be processed.
actions - table, containing indexes, which determine how animation will be processed while certain action is active.
Loads animations from folder. Folder must contain folders, named by names, presented in ..., and those must contain file with animation type, named as animation.lua.
pplaf.animation.load_by_typed_dir('/dynamic/assets/entities/',
'rotating_triangle',
'strange_triangle'
)Loads animations from folder. Folder must contain files, named as presented in ....
pplaf.animation.load_by_typed_files('/dynamic/assets/animations/',
'rotating_triangle',
'strange_triangle'
)Loads all animations to avoid lag and/or delay while accessing mesh for the first time.
pplaf.animation.preload_all()