Archeia

Show Animated Picture (Modern Algebra)

Sep 26th, 2017
139
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. #    Show Animated Picture
  3. #    Version: 1.0
  4. #    Author: modern algebra (rmrk.net)
  5. #    Modified by: Kread-Ex
  6. #    Date: February 20, 2010
  7. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. #  Description:
  9. #    
  10. #    This will allow you to show animated pictures through the regular event
  11. #   commands.
  12. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. #  Instructions:
  14. #
  15. #    Place this script in its own slot in the Script Editor (F11) above Main
  16. #   and below all the other default scripts.
  17. #
  18. #    The format for the animated picture is that each frame of the animation
  19. #   should be placed in the image to the right of the previous frame. Each
  20. #   frame must be equal width. The easiest example is any direction of a
  21. #   character sprite. Once you have created your picture in the correct format,
  22. #   you must identify how you want it to animate in its name. You can name the
  23. #   file whatever you want, but you need to include this code somewhere in the
  24. #   name:
  25. #        %[frame_width, time_interval]
  26. #   where:
  27. #     frame_width : the width of each frame, so this should be an integer of
  28. #       however many pixels wide each frame of the animation is
  29. #     time_interval : this determines how much time each frame is shown for
  30. #       before switching to the next frame. It is also an integer, where
  31. #       60 = 1 second. So, if you want each frame to be shown for only 1/10 of
  32. #       a second, then you should put 6 here. If you do not specify a time
  33. #       interval and leave it as %[frame_width] then it will take the value
  34. #       specified in SAP_DEFAULT_TIME at line 56.
  35. #
  36. #    The animation will go from the first through to the last frame and then
  37. #   repeat until the picture is erased. It will switch between frames at the
  38. #   speed you define by setting time_interval.
  39. #
  40. #    If you do not include this code in the name, then the game will treat it
  41. #   as a normal picture and show the whole thing.
  42. #==============================================================================
  43.  
  44. #==============================================================================
  45. # ** Sprite_Picture
  46. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  47. #  Summary of Changes:
  48. #    new constant - SAP_DEFAULT_FRAMES
  49. #    aliased method - update
  50. #    new method - update_src_rect
  51. #==============================================================================
  52.  
  53. class Sprite_Picture
  54.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55.   # * CONSTANTS
  56.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57.   SAP_DEFAULT_TIME = 12
  58.   Z_VALUE = 200
  59.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60.   # * Frame Update
  61.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62.   alias malbr_anmtepictr_upte_6ys1 update
  63.   def update(*args)
  64.     # Check if picture has changed and, if so, whether it is animated
  65.     if @picture_name != @picture.name
  66.       @sap_animated = @picture.name[/%\[(\d+),?\s*?(\d*?)\]/] != nil
  67.       if @sap_animated
  68.         @sap_frame_width = $1.to_i
  69.         @sap_time_interval = $2.to_i != 0 ? $2.to_i : SAP_DEFAULT_TIME
  70.         self.z = Z_VALUE
  71.       end
  72.       @sap_current_frame = -1
  73.       @sap_frame_count = 0
  74.       @picture_name = @picture.name
  75.     end
  76.     malbr_anmtepictr_upte_6ys1(*args) # Run Original Method
  77.     # If picture is animated
  78.     update_src_rect if @sap_animated
  79.   end
  80.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81.   # * Update Transfer Origin Rectangle
  82.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83.   def update_src_rect
  84.     @sap_frame_count %= @sap_time_interval
  85.     if @sap_frame_count == 0
  86.       @sap_current_frame += 1
  87.       @sap_current_frame = 0 if self.bitmap.width < (@sap_current_frame + 1)*@sap_frame_width
  88.       sx = @sap_current_frame*@sap_frame_width
  89.       self.src_rect.set(sx, 0, @sap_frame_width, self.bitmap.height)
  90.     end
  91.     @sap_frame_count += 1
  92.   end
  93. end
RAW Paste Data