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.

Questions on pausing when displaying images in the game

Hello everyone. I have scripts to call and display images. For example in the game, you are given a "map" when you press enter on the map in your inventory a png is displayed on the screen. My problem, is when the image is displayed on screen, its gone in a flash. is there a command i can use to have it hold on that image for X number of seconds, or to give the user a prompt, like on messages, so in order for the image to disappear the user needs to press X key

Thanks to any that can advise.
 
If there an object has no references pointing to it it will be disposed with garbage collection. If the sprite/bitmap is stored in a local variable it will be disposed of after a little while, you should store the sprite/bitmap in an instance variable of the class or if the variable is used a lot, you may even store it in a global variable. But I wouldn't.
 

e

Sponsor

Your best bet is to create a new Scene class, which will be instantiated whenever your player presses a certain button in Scene_Map. Then, in that new class, you could simply set the Scene's sprite to be the map image; it'd make sure it's always there. Finally, in its update method, you'd simply wait for the user's "cancel" button input to return to Scene_Map. Here's a quick mock-up, based on the SDK::Scene_Base class :

Code:
class Scene_MapImage
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    main_variable                 # Main Variable Initialization
    main_spriteset                # Main Spriteset Initialization
    main_sprite                   # Main Sprite Initialization
    main_window                   # Main Window Initialization
    main_audio                    # Main Audio Initialization
    main_transition               # Main Transition Initialization
    loop do                       # Scene Loop
      main_loop                   # Main Loop
      break if main_break?        # Break If Breakloop Test 
    end                           # End Scene Loop
    Graphics.freeze               # Prepare for transition
    main_dispose                  # Main Dispose
    main_end                      # Main End
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Variable Initialization
  #--------------------------------------------------------------------------
  def main_variable   ; end
  #--------------------------------------------------------------------------
  # * Main Processing : Spriteset Initialization
  #--------------------------------------------------------------------------
  def main_spriteset  ; end
  #--------------------------------------------------------------------------
  # * Main Processing : Sprite Initialization
  #--------------------------------------------------------------------------
  def main_sprite
    @sprite = Sprite.new
    @sprite.bitmap = RPG::Cache.picture("my_map_image_name.jpg")
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Window Initialization
  #--------------------------------------------------------------------------
  def main_window     ; end
  #--------------------------------------------------------------------------
  # * Main Processing : Audio Initialization
  #--------------------------------------------------------------------------
  def main_audio      ; end
  #--------------------------------------------------------------------------
  # * Main Processing : Transition
  #--------------------------------------------------------------------------
  def main_transition
    Graphics.transition
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Loop
  #--------------------------------------------------------------------------
  def main_loop
    Graphics.update             # Update game screen
    Input.update                # Update input information
    main_update                 # Update scene objects
    update                      # Update Processing
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Break Loop Test
  #--------------------------------------------------------------------------
  def main_break?
    return $scene != self # Abort loop if sceen is changed
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Disposal
  #--------------------------------------------------------------------------
  def main_dispose
    # Passes Through All Instance Variables
    self.instance_variables.each do |object_name|
      # Evaluates Object
      object = eval object_name
      # Pass Object To Auto Dispose
      auto_dispose(object)
    end
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Ending
  #--------------------------------------------------------------------------
  def main_end        ; end
  #--------------------------------------------------------------------------
  # * Main Processing : Update
  #--------------------------------------------------------------------------
  def main_update
    # Passes Through All Instance Variables
    self.instance_variables.each do |object_name|
      # Evaluates Object
      object = eval object_name
      # Pass Object To Auto Update
      auto_update(object)
    end
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Auto Update
  #--------------------------------------------------------------------------
  def auto_update(object)
    # Return If Object isn't a Hash, Array or Respond to Update
    return unless object.is_a?(Hash) || object.is_a?(Array) || 
                  object.respond_to?(:update)
    # If Hash Object
    if object.is_a?(Hash)
      object.each do |key, value|
        # Pass Key & Value to Auto Update
        auto_update(key) ; auto_update(value)
      end
      return
    end
    # If Array Object
    if object.is_a?(Array)
      # Pass All Object to Auto Update
      object.each {|obj| auto_update(obj)}
      return
    end
    # If Responds to Dispose
    if object.respond_to?(:dispose)
      # If Responds to Disposed? && is Disposed or Responds to Disable
      # Dispose and dispose is disabled
      if (object.respond_to?(:disposed?) && object.disposed?) ||
         (object.respond_to?(:disable_dispose?) && object.disable_dispose?)
        # Return
        return
      end
    end
    # If Responds to Update
    if object.respond_to?(:update)
      # If Responds to Disable Update & Update Disabled
      if object.respond_to?(:disable_update?) && object.disable_update?
        # Return
        return
      end
      # Update Object
      object.update
    end
  end
  #--------------------------------------------------------------------------
  # * Main Processing : Auto Dispose
  #--------------------------------------------------------------------------
  def auto_dispose(object)
    # Return If Object isn't a Hash, Array or Respond to Dispose
    return unless object.is_a?(Hash) || object.is_a?(Array) || 
                  object.respond_to?(:dispose)
    # If Hash Object
    if object.is_a?(Hash)
      object.each do |key, value|
        # Pass Key & Value to Auto Dispose
        auto_dispose(key) ; auto_dispose(value)
      end
      return
    end
    # If Array Object
    if object.is_a?(Array)
      # Pass All Object to Auto Dispose
      object.each {|obj| auto_dispose(obj)}
      return
    end
    # If Responds to Dispose
    if object.respond_to?(:dispose)
      # If Responds to Disposed? && is Disposed or Responds to Disable
      # Dispose and dispose is disabled
      if (object.respond_to?(:disposed?) && object.disposed?) ||
         (object.respond_to?(:disable_dispose?) && object.disable_dispose?)
        # Return
        return
      end
      # Dispose Object
      object.dispose
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    if Input.trigger?(Input::B)
      $scene = Scene_Map.new
      $game_system.se_play(RMenu.decision_se)
    end
  end
end

Just make sure that "my_map_image_name.jpg" is a valid file located in the Graphics\Pictures directory of your game project.
 

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