ezmash

Looping Animations (VX Ace)

Aug 23rd, 2016
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.27 KB | None | 0 0
  1. #========================================================================
  2. # LOOPING ANIMATIONS
  3. # Version 1.0
  4. # Author: Shaz
  5. #------------------------------------------------------------------------
  6. # DESCRIPTION
  7. # Allows you to set an animation (from the Animation database) on an
  8. # event to loop endlessly, optionally starting on a specific frame.
  9. #------------------------------------------------------------------------
  10. # TO INSTALL
  11. # Copy and paste into a new slot in Materials.
  12. # This script overwrites Sprite_Character.setup_new_effect and
  13. # Sprite_Character.end_animation and should be placed above any
  14. # other scripts that alias those methods.
  15. # No customization necessary.
  16. #------------------------------------------------------------------------
  17. # TO USE
  18. # Call the method start_anim_loop(anim_id[, start_frame]) on the character
  19. # (which could be the player, a follower, a vehicle or an event) to start
  20. # a looping animation.
  21. # When starting at a frame other than 1, only the first play will start at
  22. # that frame - when it finishes, it will go back to frame 1 to play again.
  23. # Call the method end_anim_loop on the character to stop it repeating after
  24. # the current loop is finished.
  25. #------------------------------------------------------------------------
  26. # EXAMPLES
  27. # $game_player.start_anim_loop(15) - to loop animation 15 on the player
  28. # $game_map.events[5].start_anim_loop(8, 20) - to play animation 15 on
  29. #   event 5, starting at frame 20 for the first pass
  30. # Set Move Route (EV015): start_anim_loop(3, 10) - to use a move route to play
  31. #   animation 3 on event 15, starting at frame 10 for the first pass
  32. # $game_player.end_anim_loop - to stop looping animation on player
  33. # Set Move Route (EV015): end_anim_loop - to stop the animation looping
  34. #   on event 15
  35. #------------------------------------------------------------------------
  36. # VERSIONS
  37. # 20 July 2013  1.0   Initial Release
  38. #  7 Feb  2014  1.1   Fixed slight delay between ending/restarting
  39. #========================================================================
  40.  
  41. class Game_CharacterBase
  42.   attr_reader   :loop_animation           # animation loops
  43.   attr_accessor :start_frame              # animation start frame
  44.  
  45.   alias shaz_ra_init_public_members init_public_members
  46.  
  47.   def init_public_members
  48.     shaz_ra_init_public_members
  49.     @loop_animation = false
  50.     @start_frame = 1
  51.   end
  52.  
  53.   def start_anim_loop(anim_id, start_frame = 1)
  54.     @loop_animation = true
  55.     @animation_id = anim_id
  56.     @start_frame = start_frame
  57.   end
  58.  
  59.   def end_anim_loop
  60.     @loop_animation = false
  61.   end
  62. end
  63.  
  64. class Sprite_Character < Sprite_Base
  65.   def setup_new_effect
  66.     if !animation? && @character.animation_id > 0
  67.       animation = $data_animations[@character.animation_id]
  68.       start_animation(animation)
  69.       if @character.start_frame != 1
  70.         @ani_duration = (animation.frame_max - @character.start_frame) * @ani_rate + 1
  71.         @character.start_frame = 1
  72.       end
  73.     end
  74.        
  75.     if !@balloon_sprite && @character.balloon_id > 0
  76.       @balloon_id = @character.balloon_id
  77.       start_balloon
  78.     end
  79.   end
  80.  
  81.   def end_animation
  82.     if @character.loop_animation
  83.       @ani_duration = @animation.frame_max * @ani_rate + 1
  84.     else
  85.       super
  86.       @character.animation_id = 0
  87.     end
  88.   end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment