Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Loops through a series of images at the specified intervals.
- * asName - The name of the [name]_0.ent part of the files.
- * asArea - The script area in the level to play the animation at.
- * frameAmount - Total number of frames to play.
- * fps = The frames per second (speed) of the animation. Only 1-60 valid.
- */
- void StartImageAnimation(string asName, string asArea, int frameAmount, int fps) {
- /* Setup unique variables to store the data. */
- SetLocalVarString("_anim_area_"+asName, asArea);
- SetLocalVarInt("_anim_fps_"+asName, fps>60?60:(fps<1?1:fps));
- SetLocalVarInt("_anim_frames_"+asName, frameAmount);
- /* Used to count which frame is currently played. */
- SetLocalVarInt("_anim_currentframe_"+asName, 0);
- /* Call the timer which will render the frames. */
- _anim_DisplayFrame(asName);
- }
- void _anim_DisplayFrame(string &in asTimer) {
- /* Check if animation still has remaining frames to play. */
- if(GetLocalVarInt("_anim_currentframe_"+asTimer)
- < GetLocalVarInt("_anim_frames_"+asTimer)) {
- /* If first loop, create a new frame entity. */
- if(GetLocalVarInt("_anim_currentframe_"+asTimer) == 0) {
- CreateEntityAtArea(
- "_anim_ent_"+asTimer+"_"+GetLocalVarInt("_anim_currentframe_"+asTimer),
- asTimer+GetLocalVarInt("_anim_currentframe_"+asTimer)+".ent",
- GetLocalVarString("_anim_area_"+asTimer),
- false
- );
- } else {
- /* If consecutive loop, replace previous frame entity. */
- ReplaceEntity(
- "_anim_ent_"+asTimer+"_"+(GetLocalVarInt("_anim_currentframe_"+asTimer)-1),
- "",
- "_anim_ent_"+asTimer+"_"+GetLocalVarInt("_anim_currentframe_"+asTimer),
- asTimer+GetLocalVarInt("_anim_currentframe_"+asTimer)+".ent",
- false
- );
- }
- /* Increment the counter. */
- AddLocalVarInt("_anim_currentframe_"+asTimer, 1);
- } else {
- /* If counter has reached the end. */
- SetEntityActive(
- "_anim_ent_"+asTimer+"_"+(GetLocalVarInt("_anim_currentframe_"+asTimer)-1),
- false
- );
- /* Stop creating new timers after last frame is removed. */
- return;
- }
- /* Add the timer for the next frame. */
- AddTimer(
- asTimer,
- 1.0f/GetLocalVarInt("_anim_fps_"+asTimer),
- "_anim_DisplayFrame"
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement