Advertisement
LiTTleDRAgo

[RGSS/2] Animated Picture

Nov 11th, 2011
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.73 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # [Xp/Vx] Animated Picture
  3. # Version: 1.00
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. #
  7. # Name your pictures with "anime_01-001","anime_01-002","anime_01-003" and so on
  8. # You can use more than 1 animated picture
  9. #
  10. #    Just name it like "anime_02-001", "anime_02-002", etc
  11. #                      "anime_03-001", "anime_03-002", etc
  12. #
  13. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  14.  
  15. #==============================================================================
  16. # ** Game_Picture
  17. #------------------------------------------------------------------------------
  18. #  This class handles the picture. It's used within the Game_Screen class
  19. #  ($game_screen).
  20. #==============================================================================
  21.  
  22. class Game_Picture
  23.   #--------------------------------------------------------------------------
  24.   # * Script Configuration
  25.   #--------------------------------------------------------------------------
  26.   DELAY = 3 # delay after each image (frames)
  27.  
  28.   LAST_FRAME_VAR    = 1
  29.   CURRENT_FRAME_VAR = 2
  30.   #--------------------------------------------------------------------------
  31.   # * Alias Listing
  32.   #--------------------------------------------------------------------------
  33.   alias update_animated_pict update
  34.   #--------------------------------------------------------------------------
  35.   # * Frame Update
  36.   #--------------------------------------------------------------------------
  37.   def update
  38.     if @name =~ /anime_..-(\d+)/i
  39.       @animated = true
  40.     else
  41.       @animated = false
  42.     end
  43.     if @animated
  44.       @counter.nil? ? @counter = 0 : @counter += 1
  45.       if @counter == DELAY
  46.         @counter = 0
  47.         if $game_variables[CURRENT_FRAME_VAR] < $game_variables[LAST_FRAME_VAR]
  48.           $game_variables[CURRENT_FRAME_VAR] += 1
  49.           @frame = $game_variables[CURRENT_FRAME_VAR]
  50.           @temp  = @name.scan(/anime_../)
  51.           case @frame
  52.           when  0..9  then @frame = "00#{@frame}"
  53.           when 10..99 then @frame = "0#{@frame}"
  54.           end
  55.           name = "#{@temp}-#{@frame}"
  56.           @name = name if picture_exist?(name)
  57.         end
  58.       end
  59.     end
  60.     update_animated_pict
  61.   end
  62.   #--------------------------------------------------------------------------
  63.   # * Picture Exist
  64.   #--------------------------------------------------------------------------
  65.   def picture_exist?(filename)
  66.     if defined?(Window_ActorCommand)
  67.       return Cache.picture(filename) rescue return false
  68.     else
  69.       return RPG::Cache.picture(filename) rescue return false
  70.     end
  71.   end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement