RPG Maker Forums

Hey there.


I'm having a bit of trouble figuring out if it's possible / how to keep a Sprite existing in the background while the game menu is open.


For a bit of context, I'm using an ABS (doesn't matter which one) and when an enemy dies I want to create a blood graphic on the ground where it died.


I have written a script (will paste it below), and it WORKS, except that when you open the menu it causes the dreaded GOBJ crash. In order to fix this, it seems I have to dispose the blood sprites when the menu call happens, however this makes the blood graphic disappear before the menu opens and reappear afterwards, a very noticeable problem in my opinion.


This can't be only solution, though, considering things like the floating damage text from the ABS doesn't disappear when the menu opens (it remains graphically frozen in the background, like the rest of the game), and only disappears when the menu is closed (this is fine). I would be happy if the blood graphic had a short flicker when the menu closes or something, but having it fully disappear while the menu remains open and then pop back into existence when it closes is not acceptable.


Anyone have any idea how to make this work?


Thanks in advance for any help you can provide.


-eldorno


Script in the spoiler below.


Should be able to call `$blood_system.add_blood(x,y)` to add a blood graphic at the x,y coordinates (tile/event coords, not pixel).


BLOOD_CHARACTER_SPRITES should be located inside the Graphics/System/ directory..

Code:
BLOOD_CHARACTER_SPRITES = [
  "Blood/Blood1",
  "Blood/Blood2",
  "Blood/Blood3",
  "Blood/Blood4"
]


#-----------------------------------------------------------------------------#
# Maintains a list of blood objects and controls updating and disposal        #
#-----------------------------------------------------------------------------#
class Blood_System
  def initialize
    @bloods = []
  end
  
  def update
    for blood in @bloods
      blood.update
    end
  end
  
  def dispose_blood_sprites
    for blood in @bloods
      blood.dispose_sprite
    end
  end
  
  def clear_blood_sprites
    dispose_blood_sprites
    @bloods = []
  end
  
  def add_blood(x, y)
    @bloods.push(Requiem_Blood.new(x, y))
  end
end


#-----------------------------------------------------------------------------#
# Holds xy coordinates, a bitmap, and manages a sprite                        #
#-----------------------------------------------------------------------------#
class Requiem_Blood
  def initialize(x, y)
    @x = x
    @y = y
    @bmp = BLOOD_CHARACTER_SPRITES[rand(4)]
  end
    
  def update
    create_sprite if @sprite.nil? or @sprite.disposed?
    @sprite.update
  end
   
  def create_sprite
    @sprite = Sprite_Blood.new($scene.get_viewport, @x, @y, @bmp)
  end
  
  def dispose_sprite
    @sprite.bitmap.dispose
    @sprite.dispose
  end
end


#-----------------------------------------------------------------------------#
# Blood sprite objects, drawn at x,y coordinates in the game world            #
#-----------------------------------------------------------------------------#
class Sprite_Blood < Sprite
  # extend existing method
  alias requiem_blood_sprite_initialize initialize
  def initialize(viewport, x, y, bmp)
    requiem_blood_sprite_initialize(viewport)
    @char_x = x * 32
    @char_y = y * 32
    self.bitmap = Cache.system(bmp)
    self.x = x
    self.y = y
  end
  
  # extend existing method
  alias requiem_blood_sprite_update update
  def update
    requiem_blood_sprite_update
    self.x = @char_x - 8
    self.y = @char_y - 8
    self.x -= ($game_map.display_x / 8)
    self.y -= ($game_map.display_y / 8)
  end
end


#-----------------------------------------------------------------------------#
# Update the blood system object every frame                                  #
#-----------------------------------------------------------------------------#
class Game_Map
  alias requiem_blood_game_map_update update
  def update
    requiem_blood_game_map_update
    $blood_system.update
  end
end


#-----------------------------------------------------------------------------#
# Get the viewport that draws sprites "Below Character"                       #
#-----------------------------------------------------------------------------#
class Scene_Map < Scene_Base
  # new method
  def get_viewport
    return @spriteset.get_viewport
  end
end

class Spriteset_Map
  # new method
  def get_viewport
    return @viewport1
  end
end


#-----------------------------------------------------------------------------#
# Dispose blood sprites on menu call                                          #
#-----------------------------------------------------------------------------#
class Scene_Map < Scene_Base
  # extend existing method
  alias requiem_blood_scene_map_call_menu call_menu
  def call_menu
    $blood_system.dispose_blood_sprites
    requiem_blood_scene_map_call_menu
  end
end


#-----------------------------------------------------------------------------#
# Fully dispose and clear blood objects on transfer                           #
#-----------------------------------------------------------------------------#
class Game_Player < Game_Character
  # extend existing method
  alias requiem_blood_game_player_perform_transfer perform_transfer
  def perform_transfer
    $blood_system.clear_blood_sprites
    requiem_blood_game_player_perform_transfer
  end
end


#-----------------------------------------------------------------------------#
# Create a global $blood_system object on startup                             #
#-----------------------------------------------------------------------------#
class Scene_Title < Scene_Base
  alias requiem_blood_scene_title_cgo create_game_objects
  def create_game_objects
    requiem_blood_scene_title_cgo
    $blood_system = Blood_System.new
  end
end

Latest Threads

Latest Posts

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,047
Messages
1,018,540
Members
137,834
Latest member
EverNoir
Top