Play Database Animation 1.2
What does this script do?
RMXP has a great system to create animations in the database, but it forces you to use them on a sprite /event.
This script lets you play those animations anywhere you want: in the Title screen, in the menu, in custom scenes, or just on the map on a certain spot.
It can play several animations at once, and should be compatible with anything.
Instructions:
use
Animation.new(id, x, y)
* Optional values: z, freeze. Read the instructions in the code.
code
older versions
What does this script do?
RMXP has a great system to create animations in the database, but it forces you to use them on a sprite /event.
This script lets you play those animations anywhere you want: in the Title screen, in the menu, in custom scenes, or just on the map on a certain spot.
It can play several animations at once, and should be compatible with anything.
Instructions:
use
Animation.new(id, x, y)
* Optional values: z, freeze. Read the instructions in the code.
code
- #---------------------------------------------------------------------
- # ** Animation
- #---------------------------------------------------------------------
- #
- # V.1.2
- # Made by: silverwind & ForeverZer0
- #
- # * This class enables playing a database animation
- # in every scene, including costum ones.
- #
- # * Instructions:
- # put the following code in a script / an event's script call:
- # Animation.new(id,x,y)
- # where id= the number of the animation in the database
- # x= screen x
- # y= screen y
- # * Notes:
- # - If the animation shows below something else on the screen, use:
- # Animation.new(id,x,y,z)
- # Experiment with z's value. The default value is 9000,
- # so try higher numbers.
- # - freeze
- # Animation.new(id,x,y,z,true)
- # ^ use this code to freeze the game until the animation is done.
- # useful when you want to play an animation during a scene change.
- # (ie, going from the menu screen to the map screen)
- #---------------------------------------------------------------------
- class Animation < RPG::Sprite
- attr_accessor :frames # frame count (from frame_max down to 0)
- def initialize(id, x, y, z = 9000, freeze=false)
- viewport = Viewport.new(0, 0, 640, 480)
- viewport.z = z
- super(viewport)
- self.x, self.y = x, y
- @frames = $data_animations[id].frame_max
- hit = true
- self.animation($data_animations[id], hit)
- Graphics.play_animation(self, freeze)
- end
- def dispose
- self.viewport.dispose
- super
- end
- end
- module Graphics
- class << self
- def freeze_play_animation(frames)
- if @animations != nil && @animations.size > 0
- for i in 0..frames : update end
- end
- end
- def clear_animations_on_scene_change
- return if @last_scene.nil?
- if @last_scene != $scene.class.name
- @animations.each_index {|i|
- @animations[i].dispose
- }
- @animations = []
- end
- end
- def play_animation(animation, freeze)
- @animations = [] if @animations == nil
- @animations.push(animation)
- if freeze
- freeze_play_animation(animation.frames)
- end
- end
- alias animation_update update
- def update
- if @animations != nil && @animations.size > 0
- @animations.compact!
- @animations.each_index {|i|
- @animations[i].update
- @animations[i].frames -= 1
- if @animations[i].frames < 0
- @animations[i] = @animations[i].dispose
- end
- }
- end
- animation_update
- clear_animations_on_scene_change
- @last_scene = $scene.class.name
- end
- end
- end
Expand to see the code.
older versions
- #---------------------------------------------------------------------
- # ** Animation
- #---------------------------------------------------------------------
- #
- # V.1.1
- # Made by: silverwind & ForeverZer0
- #
- # * This class enables playing a database animation
- # in every scene, including costum ones.
- #
- # * Instructions:
- # put the following code in a script / an event's script call:
- # Animation.new(id,x,y)
- # where id= the number of the animation in the database
- # x= screen x
- # y= screen y
- # * Notes:
- # - If the animation shows below something else on the screen, use:
- # Animation.new(id,x,y,z)
- # Experiment with z's value. The default value is 9000,
- # so try higher numbers.
- # - 'hit' is a true/false value, related to the database animation
- # I'm not sure what it does, but in case you need to change it, use:
- # Animation.new(id,x,y,z,hit)
- #---------------------------------------------------------------------
- class Animation < RPG::Sprite
- attr_accessor :frames # frame count (from frame_max down to 0)
- def initialize(id, x, y, z = 9000, hit = true)
- viewport = Viewport.new(0, 0, 640, 480)
- viewport.z = z
- super(viewport)
- self.x, self.y = x, y
- @frames = $data_animations[id].frame_max
- self.animation($data_animations[id], hit)
- Graphics.play_animation(self)
- end
- def dispose
- self.viewport.dispose
- super
- end
- end
- module Graphics
- class << self
- def play_animation(animation)
- @animations = [] if @animations == nil
- @animations.push(animation)
- end
- alias animation_update update
- def update
- if @animations != nil && @animations.size > 0
- @animations.compact!
- @animations.each_index {|i|
- @animations[i].update
- @animations[i].frames -= 1
- if @animations[i].frames < 0
- @animations[i] = @animations[i].dispose
- end
- }
- end
- animation_update
- end
- end
- end
Expand to see the code.
- #==============================================================================
- # ** Animation
- #------------------------------------------------------------------------------
- # This class shows a database animation on the screen.
- # should work outside scene_map /battle.
- #
- # Instructions:
- # put the following code in a script / an event's script call:
- # Animation.new(id,x,y)
- # where id= the number of the animation in the database
- # x= screen x
- # y= screen y
- # Notes:
- # if the animation shows below something else on the screen, use:
- # Animation.new(id,x,y,z)
- # experiment with z's value. it's 9000 by default, so try higher numbers.
- #
- #==============================================================================
- class Animation
- def initialize(anim_id, x, y, z=9000, hit=true)
- view = Viewport.new(0, 0, 640, 480)
- view.z = z
- @sprite = RPG::Sprite.new(view)
- @sprite.x = x
- @sprite.y = y
- @sprite.z = z
- @anim_file = $data_animations[anim_id]
- run_it(x, y, hit)
- @sprite.viewport.dispose
- dispose
- end
- def dispose()
- @sprite.dispose()
- end
- def run_it(x, y, hit)
- @sprite.animation(@anim_file, hit)
- size = @anim_file.frame_max
- for i in 0...size
- @sprite.update()
- Graphics.update()
- $game_screen.update
- end
- end
- end
Expand to see the code.