Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Trying to use animation in scripting

Bogurd

Member

Hi, I am trying to figure out how to use animation in scripting. I know the
Code:
sprite_instance.animation($data_animations[ANIMATION_ID], HIT_FLAG)
syntax, but that only plays the first frame of the animation. How does one update the animation to run the next frame? What is the syntax for that?

Any help is appreciated!
 

EOG

Member

You have to update sprite(each frame) you are currently animating

example:
Code:
 

class Animation_Point < RPG::Sprite

  def initialize(x, y, animation_id)

    super(Viewport.new(0,0,640,480))

    self.ox = -x

    self.oy = -y

    animation($data_animations[animation_id],true)

    while self.effect?

      Graphics.update

      Input.update

      self.update

    end

    self.dispose

  end

end

 
Usage:
Code:
 

Animation_Point.new(100,100,4)

 


It's for you to learn how to use animations. All seret is in update.
 
@EOG: That's a good trick, nut Input.update probably insn't needed. Also, updating the graphics could cause frame count to go up.

Might I make a suggestion? Take a look at this:
Code:
module Damages

  @damages = []

  def self.damage(x, y, w, h, damage, critical = false)

    @sprite = RPG::Sprite.new(Viewport.new(x, y, w, h))

    @sprite.damage(damage, critical)

    @damages << @sprite

  end

  def self.update

    @damages.each {|s| s.update}

  end

  def self.dispose

    @damages.each {|s| s.dispose}

  end

end

 

class << Graphics

  alias_method :seph_damages_graphics_update, :update

  def update

    Damages.update

    seph_damages_graphics_update

  end

end

Now this may be for damages, but the same principals apply. If you need any help, let me know. :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top