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.

[FILLED] Looping (show) animations

[polite mode]
Hey, sup? How was your day?

I'm requesting a script to loop shown animations. Pretty much you know how you can "show animation"? Yeah something like that. I'd like to throw in a call script that would loop an animation (over either event (ID) or player) indefinitely, until another call script is entered to stop it.

So I could, let's say, start an animation over an event. And it won't stop. I can simply put one call script (or one call script, followed by a 'show animation' if that would be easier?) and it would continually loop without stopping the action.

Then, with a 2nd call script, the animation would either:
a) finish up it's animation (a 24 frame animation on the 4th frame when stopped, would continue for 20 frames till end)
or
2) simply stop.
I'd prefer it if I could have the option to do either or, however if only once is possible I'll gladly take it.

Any help would naturally earn you a big thank you, and full credit whenever I use said script.

Thank you, and enjoy your day.
[/polite mode]
 
Give me a few minutes to re-read the RPG::Sprite class and come up with something clever...

Edit: Here you are:

Code:
class Game_Character
  attr_accessor :loop_animation_id
  attr_accessor :loop_animation_stop
  attr_accessor :loop_animation_finish
  alias_method :seph_loopanimation_gmchr_init, :initialize
  def initialize
    seph_loopanimation_gmchr_init
    clear_loop_animation
  end
  def clear_loop_animation
    @loop_animation_id = 0
    @loop_animation_stop = false
    @loop_animation_finish = false
  end
end

class Sprite_Character
  alias_method :seph_loopanimation_gmchr_update, :update
  def update
    seph_loopanimation_gmchr_update
    if @character != nil && @character.loop_animation_id != 0
      animation = $data_animations[@character.loop_animation_id]
      loop_animation(animation)
      @character.clear_loop_animation
      return
    end
    if @character != nil && @character.loop_animation_stop
      loop_animation(nil)
      @character.clear_loop_animation
      return
    end
    if @character != nil && @character.loop_animation_finish
      finish_loop_animation
      @character.clear_loop_animation
      return
    end
  end
end

class RPG::Sprite
  alias_method :seph_loopanimation_rpgsprite_ula, :update
  def finish_loop_animation
    @_finish_loop_animation = true
  end
  def update
    seph_loopanimation_rpgsprite_ula
    if @_finish_loop_animation && 
       @_loop_animation_index == @_loop_animation.frame_max - 1
      @_finish_loop_animation = false
      loop_animation(nil)
      return
    end
  end
end

Usage:
Code:
# Setting Event Loop Animation
e = $game_map.events[event_id]
e.loop_animation_id = animation_id

# Setting Player Loop Animation
e = $game_player
e.loop_animation_id = animation_id

# Stopping Event Loop Animation
e = $game_map.events[event_id]
e.loop_animation_stop = true

# Stopping Player Loop Animation
e = $game_player
e.loop_animation_stop = true

# Finishing Event Loop Animation
e = $game_map.events[event_id]
e.loop_animation_finish = true

# Finishing Player Loop Animation
e = $game_player
e.loop_animation_finish = true

All of those are just call scripts you would make.

Enjoy!
 
Nicely done Seph,
I tested it and it all works. Would've said thanks earlier, but I've always thought it in bad taste to say thanks - only to try it out later then ask questions about it (just in case).

Works perfectly, everything - which I'm sure you already knew.

That's twice you've helped me,
Thanks.
 
can you please help me to edit that script to use loop animation on the screen? use animation to show degree on x, y of the screen. and when you stop animation, that script will stop all animation which you are showing...so you can help me to edit become it only stop one animation which you chose id...as you show it by id...thank
 

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