Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animated Icons
#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.


Hello Guys! It's Me, Samo, the thief, and i need some help.

Did you got knowing of Animated Sprites script by Slipknot?. If no one's remembers it, i will post it here.


You only need, to paste this before Main:

Code:
#============================================================
#  ¦ Animated Sprites ¦
#------------------------------------------------------------
#   by Slipknot
#============================================================

class Animated_Sprite < Sprite
  #--------------------------------------------------------------------------
  # Attributes
  #--------------------------------------------------------------------------
  attr_accessor :frame, :delay
  attr_reader :bitmaps, :freeze
  #--------------------------------------------------------------------------
  #  bitmaps: are the names of the bitmaps used for each frame
  #  delay: time between frame changes, 10 = 1 sec
  #  type: icon, picture, character, battler, ...
  #--------------------------------------------------------------------------
  def initialize bitmaps, delay=10, type="picture"
    super()
    @method = RPG::Cache.method type
    self.bitmap = @method.call bitmaps[0]
    @bitmaps = bitmaps
    @delay = delay
    @frame = @count = 0
    @freeze = false
    Animation.push self
  end
  #--------------------------------------------------------------------------
  # Self dispose and delete
  #--------------------------------------------------------------------------
  def dispose
    Animation.delete self
    super
    bitmap.dispose
  end
  #--------------------------------------------------------------------------
  # Hides and freeze, or show and defreeze
  #--------------------------------------------------------------------------
  def visible=(val)
    super(val)
    @freeze = (not val)
  end
  #--------------------------------------------------------------------------
  # Defreeze, play animation
  #--------------------------------------------------------------------------
  def defreeze
    @freeze = false
  end
  #--------------------------------------------------------------------------
  # Freeze, stop animation
  #--------------------------------------------------------------------------
  def freeze
    @freeze = true
  end
  #--------------------------------------------------------------------------
  # Return the number of frames
  #--------------------------------------------------------------------------
  def size
    @bitmaps.size
  end
  #--------------------------------------------------------------------------
  # Frame update
  #--------------------------------------------------------------------------
  def update
    return if @freeze or bitmaps.empty? or bitmaps.size == 1
    @count = (@count+1) % @delay
    return unless @count == 0
    @frame = (@frame+1) % bitmaps.size
    self.bitmap = @method.call bitmaps[@frame]
  end
end

module Animation
  #--------------------------------------------------------------------------
  # Data initialization
  #--------------------------------------------------------------------------
  @data = []
  #--------------------------------------------------------------------------
  # Update all animations
  #--------------------------------------------------------------------------
  def self.update
    return if @data.empty?
    @data.each do |o|
      o.update
    end
  end
  #--------------------------------------------------------------------------
  # Delete an animation
  #--------------------------------------------------------------------------
  def self.delete object
    @data.delete object
  end
  #--------------------------------------------------------------------------
  # Delete all the animations
  #--------------------------------------------------------------------------
  def self.clear
    return if @data.empty?
    @data.each do |o|
      o.dispose if not o.disposed?
    end
    @data.clear
  end
  #--------------------------------------------------------------------------
  # Freeze all the animations
  #--------------------------------------------------------------------------
  def self.freeze
    return if @data.empty?
    @data.each do |o|
      o.freeze
    end
  end
  #--------------------------------------------------------------------------
  # Defreeze all the animations
  #--------------------------------------------------------------------------
  def self.defreeze
    return if @data.empty?
    @data.each do |o|
      o.defreeze
    end
  end
  #--------------------------------------------------------------------------
  # Adds an animation
  #--------------------------------------------------------------------------
  def self.push object
    @data.push object
  end
end




Now, the commands:

Make a new animation:

Code:
object = Animated_Sprite.new(bitmaps, delay, type)


Bitmaps are strings, that will be the name of each frame of the animation.
Delay are the frames of waiting between each frame
Type is the type of image, for example, picture, windowskin, icon, etc.

For example

Code:
@anim1 = Animated_Sprite.new("C1", "C2", 5, picture)




Coordinates X and Y:

Code:
object.x = X
object.y = X



X is obviously the number XD.

For example:

Code:
@anim1.x = 60
   @anim1.y = 90




Really needing of this:
Code:
Animation.update


It will update all the animations. If you don't put it, it won't work.

Freeze command:

Code:
#for one animation
object.freeze



For all the animations

Code:
Animation.freeze



Example:

Code:
@anim1.freeze



Now, for returning to normal states:

Code:
#for one
object.defreeze
#for all
Animation.defreeze




Now, clearing the animations.

Slipknot says that using
Code:
animation.clear

is the best way to eliminate all the animations, but i will teach another way because the other one doesn't function for me.
what i did is to dispose (it means, clear the animation) each animation, one by one. This is what i used:


Code:
object.dispose


for example:

Code:
@anim1.dispose
@anim2.dispose
@anim3.dispose
@anim4.dispose
@anim5.dispose


Note: If you do a great number of animations and you have to put this dispose in severalcommands, you can do a def dispose_animations in the script, that dispose all of this pictures, and then only put dispose_animations

Really simple.

Now, this is what i need, but first, let's post another script. Icon command window by mewsterus. Instructions in script.



Code:
#====================================================================
# * Icon Command Window script by mewsterus
# * To install, just insert this in a descriptive code slot right above Main
# *
# * Icons for the command windows should be the same name as the command and PNG
# *  format.  Every command in the game must have a graphic (including title,
# *  menu, and battle command windows).  This applies only to fixed length
# *  vertical command windows.  Place icons in the Graphics/Icons directory.
#====================================================================
# ¦ Window_Command
#---------------------------------------------------------------------------
#   Edited by mewsterus
#====================================================================

class Window_Command < Window_Selectable
  #-------------------------------------------------------------------------
  # @ Draw choice
  #-------------------------------------------------------------------------
  def draw_item(index, color)
   bitmap = RPG::Cache.icon(@commands[index] + ".png")
   opacity = color == normal_color ? 255 : 128
   self.contents.blt(4, 32*index+4, bitmap, Rect.new(0, 0, 24, 24), opacity)
   self.contents.font.color = color
   rect = Rect.new(32, 32 * index, self.contents.width - 32, 32)
   self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
   self.contents.draw_text(rect, @commands[index])
  end
end


What the heck is that this have to do? Really simple. If you run your proyect normally, with this script, it is possible that it says that it needs some icons. Do the icons with the same name like the commands. And when you run the proyect, you will see that icons in the commands, great!.

Ok, but i have a great idea but, i can't do it well. Actually, i did a engine that puts in some commands, when you put the curson upon them, they do an animation. For example, the exit command, when you put the cursor upon the command, this will do an animation of a door opening (what is really cool;) ).
But i will like that this animated sprites, and icon command window applies together to do the following:

Let's imagine that we are in battle, and we put abilities, and put the cursor upon one, for example, heal. when we put the cursor, the heal icon does an animation, such as move something. NOw we put it upon boost, the heal animation freezes and boost icon does another animation.

why i say icon command window will be useful? for the following:
-It applies to evey command of the game, excluding command messages, debug, and many other things.

-It puts an empty space in the command, that will give the possibility to put the animation there.

-It's function of name's command will give the possibility if someone helps, to name the command or ability, and recognize it in the moment, so the animation won't need of any scripting to say what are the frames to reproduce.
Something like this, if exit command, play all frames that have the name and a number: Command-name + # where # is the number and command name will be the name of the animation.

for example, EXIT1, EXIT2, EXIT3, etc.


a bit confusing what i want? i know its complicated to do, but it will be a great feauture, because the commands of the game will do animations.

Ok, thanks for spending time on reading, and please, if you're a scripter, help me on this proyect, i know it will be wonderful.

So bye!

NOTE: PLEASE, NO SDK SCRIPTS!
}


Possibly Related Threads…
Thread Author Replies Views Last Post
  Animated Sprites Sheol 0 2,073 01-29-2006, 01:00 PM
Last Post: Sheol
  Vertical or Horizontal Menu with or without Icons Tsunokiette 0 2,076 12-11-2005, 01:00 PM
Last Post: Tsunokiette
  Animated Message Script dragonslayer 0 2,136 05-04-2005, 01:00 PM
Last Post: dragonslayer



Users browsing this thread: