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.

[RESOLVED] [VX] showing animation fromwithin a script

I wrote the following script to show an animation 'out of thin air', i.e. without having a supporting Event:

Code:
def do_anim( x, y, id)

  e = RPG::Event::new( x, y)                # create a base RPG::Event

  e.id = $game_map.events.size              # set ID > last of the map event list

  c = Game_Event.new( $game_map.map_id, e)  # create the event

  $game_map.events[ e.id] = c               # push the event in the map event list

  c.animation_id = id                       # try and play the animation

  $game_map.events[ e.id].erase             # dispose of the event in the map list

end

Alas, when it is called, nothing happens. But when I exit the scene and te-enter it (by, say, calling the game menu scene), THEN, the animation take effect...

What object do I have to update, or something.

Errr... please... do not answer $scene.update, because the script is called from the $game_player.check_event_trigger_there, and it could cause an infinite loop.

Unless I call it from somewhere else. The idea is to show the animatiion when the action button is pressed and no Event is triggered.

Thanks all...
 
You could do much more simple than that.

Use a sprite. It's the Sprite class that handles animation processing.
You could do is something like that:

[ruby] 
sprite = Sprite.new
sprite.animation($data_animations[ANIMATION_ID], HIT_FLAG)
 
[/ruby]

ANIMATION_ID is obviously the ID of the animation to be played
HIT_FLAG is a boolean to determine whether to play the "hit effects" of the animation or not

if I use your code, it could look something like this:
[ruby] 
def do_anim(x,y,id, hit=true)
  sprite = Sprite.new
  sprite.x = x
  sprite.y = y
  sprite.animation($data_animations[id], hit)
end
 
[/ruby]

you would then need to update and dispose this sprite in other methods but it should do the trick.

Hope it helps!
-Dargor
 
Those Sprite_Base are SOOOOO simple.... Once more, Dargor, you are my savior :thumb:

For those of you who care, here is how it is managed :

Code:
class Game_Map

  attr_reader  :anims

 

  alias bdr_anim_initialize initialize

  def initialize

    bdr_anim_initialize

    reset_anims

  end

 

  alias bdr_anim_setup setup

  def setup(map_id)

    bdr_anim_setup( map_id)

    reset_anims

  end

 

  def reset_anims

    @anims = []

  end

 

  def start_anim( anim_id, x, y)

    @anims.push( [ anim_id, x, y])

  end

end

 

 

class Spriteset_Map

  alias bdr_anim_initialize initialize

  def initialize

    create_anims

    bdr_anim_initialize

  end

  def create_anims

    @anims = []

  end

 

  alias bdr_anim_dispose dispose

  def dispose

    bdr_anim_dispose

    dispose_anims

  end

  def dispose_anims

    for anim in @anims

      anim.dispose

    end

  end

 

  alias bdr_anim_update update

  def update

    bdr_anim_update

    update_anims

  end

  def update_anims

    for spr in @anims

      spr.update

    end

    for anim in $game_map.anims

      a = $data_animations[ anim[ 0]]

      if a != nil

        s = Sprite_Base.new( @viewport1)

        s.x = anim[ 1]

        s.y = anim[ 2]

        s.start_animation( a)

        @anims.push( s)

      end

      $game_map.reset_anims

    end

  end

end

All you have to do is invoke the $game_map.start_anim( anim_id, x, y) method.
 
No problem, I'm glad it worked! :)
Also, if you are using VX or the RMXP SDK, you could add this method in the Scene_Base class. This would allow you to play an animation in any scenes you want; Map, Main Menu, Title Screen, etc.

Take care!
-Dargor
 

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