Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animations. A cool script indeed!!!
#1
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


I obtained this script a while back and its great.
It was made by a guy named "Baskinein" from RMXP.net.
I have posted this problem there a few times and I have recieved NO help.
SO I thought that I should share it with the nice people here at CA.
So here it is.

A brief explanation:

Want to build a great menu with animations in it?
Want to create a new battle system with animations?
Or do you just want to have animations on the map?
Well, if answered yes to any of those questions or you are just thinking about saying yes then this script is just what you need.
First I'll go over things you need to add into pre-existing scripts.

Ok insert this into game screen at line 18
Code:
attr_reader    :animations
At line 37 add this:
Code:
@animations = [nil]
   for i in 1..20
     @animations.push(Game_Animation.new(i))#Creates Animation objects
   end

then add this to Spriteset_Map line 17:
Code:
@viewport4 = Viewport.new(0, 0, 640, 480)
   @viewport4.z = 300

then add this at line 51:
Code:
@animated_sprites = []
   for i in 1..20
     @animated_sprites.push(Sprite_Animation.new(@viewport4, $game_screen.animations[i]))
   end
now this at line 84:
Code:
for sprite in @animated_sprites
     sprite.dispose
   end

also add this with the rest of the .dispose lines:
line 92 I think.
Code:
@viewport4.dispose
line 155 add this:
Code:
for sprite in @animated_sprites
     sprite.update
   end
Line 168 this:
(with the other few dipose methods)
Code:
@viewport4.update

Ok now all thats done add this above main:
(NOTE: these scripts were made by 100% Baskinein ok)
Code:
#==============================================================================
# ¦ Game Animation                                      Written by Baskinein
#------------------------------------------------------------------------------
#  This script keeps all of the info on the animation that is to be played. It is very similar to Game Picture...
#==============================================================================
class Game_Animation
attr_reader   :number         #animation number
attr_reader   :name            #name of animation
attr_reader   :width            #width of frame(pixels)
attr_reader   :height           #height of frame(pixels)
attr_reader   :frames          #number of frames in animation
attr_reader   :frame_width  #width(by frames)
attr_reader   :frame_height #height(by frames)
attr_accessor :x                 #x of animation
attr_accessor :y                 #y of animation
attr_reader   :target_x        #x destination of animation
attr_reader   :target_y        #y destination of animation
attr_reader   :delay            #Delay(in frames) between frames
attr_reader   :loop             #Repeat animation or not
attr_writer    :playing         #if animation is active
attr_writer    :moving         #if animation is moving
attr_reader   :move_speed  #animation moving speed
attr_reader   :rotate_speed #animation rotating speed
attr_reader   :zoom_x
attr_reader   :zoom_y
attr_reader   :opacity
attr_reader   :blend_type
attr_accessor :tone
attr_reader   :tone_target
attr_accessor :tone_duration
attr_accessor :angle
#---------------------------------------------------------------
# ? Initialize
#---------------------------------------------------------------
def initialize(number = 0)
   @number = number
   @name = ""
   @width = 0
   @height = 0
   @frames = 0
   @frame_width = 0
   @frame_height = 0
   @x = 0.0
   @y = 0.0
   @zoom_x = 100.0
   @zoom_y = 100.0
   @opacity = 255.0
   @blend_type = 0
   @duration = 0
   @target_x = @x
   @target_y = @y
   @target_zoom_x = @zoom_x
   @target_zoom_y = @zoom_y
   @target_opacity = @opacity
   @tone = Tone.new(0, 0, 0, 0)
   @tone_target = Tone.new(0, 0, 0, 0)
   @tone_duration = 0
   @angle = 0
   @rotate_speed = 0
   @playing = true
   @loop = true
   @delay = 0
end
#---------------------------------------------------------------
# ? Display
#---------------------------------------------------------------
def display(name, x = 0, y = 0, delay = 5, loop = true,  zoom_x = 100.0, zoom_y = 100.0, opacity = 255, blend_type = 0)
   self.name = name
   @frames = @frame_width * @frame_height
   if x != 0
     @x = x.to_f
   end
   if y != 0
     @y = y.to_f
   end
   @delay = delay
   @loop = loop
   @zoom_x = zoom_x.to_f
   @zoom_y = zoom_y.to_f
   @opacity = opacity.to_f
   @blend_type = blend_type
   @duration = 0
   @target_x = @x
   @target_y = @y
   @target_zoom_x = @zoom_x
   @target_zoom_y = @zoom_y
   @target_opacity = @opacity
   @tone = Tone.new(0, 0, 0, 0)
   @tone_target = Tone.new(0, 0, 0, 0)
   @tone_duration = 0
   @angle = 0
   @rotate_speed = 0
end
#---------------------------------------------------------------
# ? Move
#---------------------------------------------------------------
def move(x, y, speed = 1)
   @target_x = x
   @target_y = y
   @move_speed = speed
   @moving = true
end
#---------------------------------------------------------------
# ? Animation Dimensions
#---------------------------------------------------------------
def animation_dimensions(name)
   @frame_width, @frame_height = 0
   for y in 1..9
     for x in 1..9
       if File.exists?("Graphics/Animations/" + name + " w_" + x.to_s + " h_" + y.to_s + ".png")
         @frame_width, @frame_height = x, y
         return true
       end
       break if File.exists?("Graphics/Animations/" + name + " w_" + x.to_s + " h_" + y.to_s + ".png")
     end
     break if File.exists?("Graphics/Animations/" + name + " w_" + x.to_s + " h_" + y.to_s + ".png")
   end
   return false
end
#---------------------------------------------------------------
# ? Name=
#---------------------------------------------------------------
def name=(name)
   exist = self.animation_dimensions(name)
   if exist
     @name = name + " w_" + @frame_width.to_s + " h_" + @frame_height.to_s
     bitmap = RPG::Cache.animation(@name, 0)
     @width = bitmap.width / @frame_width
     @height = bitmap.height / @frame_height
   else
     print "Animation file \"" + name + "\" does not exist!"
     @name = ""
   end
end
#---------------------------------------------------------------
# ? Rotate
#---------------------------------------------------------------
def rotate(speed)
   @rotate_speed = speed
   if speed > 0
     @rotating = true
   else
     @rotating = false
   end
end
#---------------------------------------------------------------
# ? Start Tone Change
#---------------------------------------------------------------
def start_tone_change(tone, duration)
   @tone_target = tone.clone
   @tone_duration = duration
   if @tone_duration == 0
     @tone = @tone_target.clone
   end
end
#---------------------------------------------------------------
# ? Dispose
#---------------------------------------------------------------
def dispose
   @name = ""
end
#---------------------------------------------------------------
# ? Playing?
#---------------------------------------------------------------
def playing?
   return @playing
end
#---------------------------------------------------------------
# ? Moving?
#---------------------------------------------------------------
def moving?
   return @moving
end
def rotating?
   return @rotating
end
end
then below that in aseperate script above main add this.
Code:
#==============================================================================
# ¦ Sprite Animation                                      Written by Baskinein
#------------------------------------------------------------------------------
#  Pulls info from a Game_Animation object and displays it on the screen.
#==============================================================================
class Sprite_Animation < RPG::Sprite
#---------------------------------------------------------------
# ? Initialize
#---------------------------------------------------------------
def initialize(viewport, animation)
   super(viewport)
   @animation = animation
   @frame_count = Graphics.frame_count
   @move_count = Graphics.frame_count
   @frame_current = 0
   update
end
#---------------------------------------------------------------
# ? Dispose
#---------------------------------------------------------------
def dispose
   if self.bitmap != nil
     self.bitmap.dispose
   end
   self.visible = false
   super
end
#---------------------------------------------------------------
# ? Update
#---------------------------------------------------------------
def update
   super
   if @animation_name != @animation.name
     @animation_name = @animation.name
     if @animation_name != ""
       self.bitmap = RPG::Cache.animation(@animation_name, 0)
     end
   end
   if @animation_name == ""
     self.visible = false
     return
   end
   update_move
   update_rotate
   update_tone
   if self.bitmap != nil and @animation.playing? and refresh?
     y = @animation.height * (@frame_current / @animation.frame_width)
     x = @animation.width * (@frame_current - ((@frame_current / @animation.frame_width) * @animation.frame_width))
     self.src_rect = Rect.new(x, y, @animation.width, @animation.height)
     @frame_current += 1
     if @frame_current == (@animation.frames - 1) and !@animation.loop
       @animation.playing = false
       @animation.dispose
     end
     @frame_current %= @animation.frames
   end
   if self.src_rect.width != @animation.width
     self.visible = false
   else
     self.visible = true
   end
   self.x = @animation.x
   self.y = @animation.y
   self.ox = @animation.width / 2
   self.oy = @animation.height / 2
   self.z = @animation.number
   self.zoom_x = @animation.zoom_x / 100.0
   self.zoom_y = @animation.zoom_y / 100.0
   self.opacity = @animation.opacity
   self.blend_type = @animation.blend_type
   self.angle = @animation.angle
   self.tone = @animation.tone
end
#---------------------------------------------------------------
# ? Update Move
#---------------------------------------------------------------
def update_move
   return if !@animation.moving?
   if @animation.move_speed == 0
     distance = 1
   else
     distance = @animation.move_speed
   end
   if @animation.x > @animation.target_x
     @animation.x -= distance
   end
   if @animation.x < @animation.target_x
     @animation.x += distance
   end
   if @animation.y > @animation.target_y
     @animation.y -= distance
   end
   if @animation.y < @animation.target_y
     @animation.y += distance
   end
   if @animation.move_speed > 1
     if (@animation.target_x - @animation.x).abs <= @animation.move_speed and ((@animation.target_x - @animation.x).abs % @animation.move_speed) != 0
       @animation.x = @animation.target_x
     end
     if (@animation.target_y - @animation.y).abs <= @animation.move_speed and ((@animation.target_y - @animation.y).abs % @animation.move_speed) != 0
       @animation.y = @animation.target_y
     end
   end
   if @animation.x == @animation.target_x and @animation.y == @animation.target_y
     @animation.moving = false
   end
end
#---------------------------------------------------------------
# ? Update Rotate
#---------------------------------------------------------------
def update_rotate
   if @animation.rotate_speed != 0
     @animation.angle += @animation.rotate_speed / 2.0
     while @animation.angle < 0
       @animation.angle += 360
     end
     @animation.angle %= 360
   end
end
#---------------------------------------------------------------
# ? Update Tone
#---------------------------------------------------------------
def update_tone
   if @animation.tone_duration >= 1
     d = @animation.tone_duration
     @animation.tone.red = (@animation.tone.red * (d - 1) + @animation.tone_target.red) / d
     @animation.tone.green = (@animation.tone.green * (d - 1) + @animation.tone_target.green) / d
     @animation.tone.blue = (@animation.tone.blue * (d - 1) + @animation.tone_target.blue) / d
     @animation.tone.gray = (@animation.tone.gray * (d - 1) + @animation.tone_target.gray) / d
     @animation.tone_duration -= 1
   end
end
#---------------------------------------------------------------
# ? Refresh?
#---------------------------------------------------------------
def refresh?
   if (Graphics.frame_count - @frame_count >= @animation.delay)
     @frame_count = Graphics.frame_count
     return true
   end
   return false
end
end

Ok now all thats finally done.

File names are to be something like this, "Fire w_6 h_4". The w_? h_? party should be the number of frames there in width and are in height. So this animation would have 6 animations in a row and 4 of those rows....so 24 animations all together. You can have up to 9x9...and that can be changed in the script...although I dont suggest doing it unless you really need to...but who needs more than 81 animations?
To create an animation in an event you simply need to use this line...
Code:
$game_screen.animations[i].display("Fire",
480, 240)

change "Fire" to whatever animation it is.
change i to any number(1..20). If you want more animations than that playing at once you can change that easily too. Just go through the pieces of the scripts(not the two whole ones) and chnage all of the 1..20 to 1.. to whatever you want.

If you want an animation in a menu or some type of other scene you can use this in the initialize method of the class...
Code:
viewport = Viewport.new(0, 0, 640, 480)
   viewport.z = 300#this can be whatever you want obviously
   @animation = Sprite_Animation.new(viewport, Game_Animation.new.display("Aera", 480, 240))
Once again replace"Aera" with the file you wish to show.

and just make sure you have a @animation.update in the update method and also a @animation.dispose with all of the other .dispose.
If you are going to use an animation in battle you can use any either method...but if you use the $game_screen...method of displaying the animation you are going to need to make sure you have all of the updates that I had you do to Spriteset_Map you do to Spriteset_Battle(there is already a viewport4 in Spriteset_Battle so change the new one to 5).
==========================================================================================================
Ok now thats the WHOLE script done!!!
the animations will play in a loop on the map you are on.
I have tried this many times and never found any lag whatsoever.

For showing the map animations in a massive loop this is great.
But I cant seem to make it play an animation in a menu or a scene of any sort.

Other than that the script works fine.
But if someone could PLEASE help me with this.
I get an error all the time when I go to enter the menu screen that says:

??????'SpriteAnimation'?33??NoMethodError????????

Undefined method 'name' for 0:Fixnum
I cnat seemt o sort this out even when I change the code in that line around.
Please can someone figure out the problem.
This is a great script and I have a little bit of trouble ith it.
If i can't make this work then I doubt others will be able to either (unless they can script well of course).
So anyone who can shed light on this problem will be greatly thanked and will help many more than just me ok.
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change character script jaigai 0 2,721 11-19-2006, 01:00 PM
Last Post: jaigai
  Just a modification of Abyssos' facs script lumina... 0 2,574 11-01-2006, 01:00 PM
Last Post: lumina...
  Credit Script 1.1 acoole 0 2,401 10-24-2006, 01:00 PM
Last Post: acoole
  Script Dev Kit Nick 0 2,776 10-15-2006, 01:00 PM
Last Post: Nick
  Opening Image script sasuke89 0 2,013 07-24-2006, 01:00 PM
Last Post: sasuke89
  Change Color of The diferent Status Script MASTERLOKI 0 2,260 07-18-2006, 01:00 PM
Last Post: MASTERLOKI
  Event Name and ID Search Script Hadriel 0 2,019 06-21-2006, 01:00 PM
Last Post: Hadriel
  Currency Script Split 0 2,264 05-18-2006, 01:00 PM
Last Post: Split
  Book Script and Utility Bruth 0 2,203 05-07-2006, 01:00 PM
Last Post: Bruth
  Individuality Script DrakoShade 0 2,165 03-12-2006, 01:00 PM
Last Post: DrakoShade



Users browsing this thread: