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.

Battle Script triggers (Battle_main_phase)

I've been messing around with the battle system in RPG Maker XP, and what I've noticed was this (based on the default system):

-Once you have selected each of your characters' actions, then the $Game_Temp.battle_main_phase trigger will become true and begin since the battle switches to the actual fighting and such. However, what I've noticed was that the system seems to already know whether or not an enemy's HP is going to be <= 0 before the actor actaully attacks it. So basically, what it's doing is configuring all of the damage on the enemies as soon as the player finishes selecting what action to make on them for each of the actors, but it's not doing this after the actor actually attacks an enemy.

I understand the reason for doing it this way, but I've been trying to make a sprite image disappear as soon as an Enemy sprite disappears/fades out once it's killed.
What is happening now is that once you finish selecting what your actors want to do in battle (fight, defend, magic, etc.), then the sprite image disappears before the actual fighting begins because the system has already configured that: "Enemy X is going to be dead because it's going to receive y damage based on my pre-calculations."

I hope this makes sense. Any help on this?
 
it's not a system keyword, just a method of the RPG::Sprite class.
Yes, that is the method that fades out the battler.

In this case, I just meant that section, with # Collapse as a comment.

You should be able to dispose of your other sprite right after:
          $game_system.se_play($data_system.enemy_collapse_se)

In fact, if it's a sprite, you should be able to call  my_sprite.collapse to make it fade out along with the enemy sprite.

Be Well
 
How did you create it?  (did you inherit from  RPG::Sprite)?

I just noticed your post at Amaranthia, your sprite is from "Sprite", not "RPG::Sprite"

Try:

@sprite_pic1 = RPG::Sprite.new
@sprite_pic1.bitmap = Bitmap.new("/pictures/death_image.jpg")
 
The code on Amaranthia was written from memory. Now that I'm at my computer again, I can paste the actual code I have:

    @hp_ap_bar_enemy1 = Sprite.new
    @hp_ap_bar_enemy1.bitmap = RPG::Cache.picture('enemy_hp_bar.PNG')
    @hp_ap_bar_enemy1.opacity = 255
    @hp_ap_bar_enemy1.visible = true


    for i in 0...$game_troop.enemies.size
        @enemy = $game_troop.enemies
        if i == 0
          if @battler.is_a?(Game_Enemy)
          if @enemy.hp <=0
                @hp_ap_bar_enemy1.visible = false
            end
          end
        end
       
        end 
 
I'm still having problems with this. I have no idea wha'ts going on. I define the image in the "initialize" area like this:

Code:
class Sprite_Battler < RPG::Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :battler                  # battler
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     viewport : viewport
  #     battler  : battler (Game_Battler)
  #--------------------------------------------------------------------------
  def initialize(viewport, battler = nil)
    super(viewport)
    @battler = battler
    @battler_visible = false
  
 @hp_ap_bar_enemy1 = RPG::Sprite.new
 @hp_ap_bar_enemy1.bitmap = Bitmap.new("Graphics/Pictures/enemy_hp_bar.PNG")
 @hp_ap_bar_enemy1.visible = true

  end

I then go to this section of the code where the enemy sprites "collapse" when they die and do this:

Code:
      # Collapse
      if @battler.damage == nil and @battler.dead?
        if @battler.is_a?(Game_Enemy)
          $game_system.se_play($data_system.enemy_collapse_se)
                
             @hp_ap_bar_enemy1.visible = false

        else
          $game_system.se_play($data_system.actor_collapse_se)
       end
        collapse
        @battler_visible = false
          end           
    end

...and yet the @hp_ap_bar_enemy1 image doesn't disappear when the enemy dies. I've tried everything I can think of, but the image just stays on the screen regardless... Can anyone help?
 
Yep. The sprite doesn't change opacity.
I did a test where if the enemy died, then the image would move to a different part of the screen. What it ended up doing was creating a duplicate sprite image and placing it on the different part of the screen when the enemy died instead. So I suspect there are actually 2 of the same sprites on the screen, even though I only defined it once. I don't know how that's possible, unless "initialize" is being called more than once, but I didn't see any other place in the script where it was calling initialize more than once.
 
change your initialize to:
Code:
  def initialize(viewport, battler = nil)
    super(viewport)
    @battler = battler
    @battler_visible = false
    if @battler.is_a?(Game_Enemy)
      @hp_ap_bar_enemy1 = RPG::Sprite.new
      @hp_ap_bar_enemy1.bitmap = Bitmap.new("Graphics/Pictures/enemy_hp_bar.PNG")
      @hp_ap_bar_enemy1.visible = true
      @hp_ap_bar_enemy1.ox = 45
      @hp_ap_bar_enemy1.x = battler.screen_x
      @hp_ap_bar_enemy1.y = 80
    end
  end
make 'ox' half the width of your hp_bar image
 
use the x & y parameters, and put them wherever you want.
x is across the screen from left to right, y is from top to bottom.
If you want them starting at 0,0, then you could use...

Code:
  def initialize(viewport, battler = nil)
    super(viewport)
    @battler = battler
    @battler_visible = false
    if @battler.is_a?(Game_Enemy)
      @hp_ap_bar_enemy1 = RPG::Sprite.new
      @hp_ap_bar_enemy1.bitmap = Bitmap.new("Graphics/Pictures/enemy_hp_bar.PNG")
      @hp_ap_bar_enemy1.visible = true
      @hp_ap_bar_enemy1.y = @battler.index * 30
    end
  end

Where 30 is a little bigger than the height of your hp_bar image
 

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