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.

Screen Tone Trouble

Hello!! i'm having a problem, and i need help...

(It's RMXP RGSS)

My game has a Map Hud, so when the screen color tone fades to black, the Hud is still visible. I need the hud to have the same tone as the screen, so here is what i did:
Code:
bitmap = RPG::Cache.picture("Name")
    self.contents.blt(0, 0, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height))
    bitmap.tone = $game_screen.tone

But i get an error saying that "tone" is an undefined method for bitmap.
I really don't know what to do... please help.

Ohh BTW, i tried using this code on Scene_Map update:

Code:
@hud = Window_HUD.new
def update
@hud.update
@hud.tone = $game_screen.tone

but i get the same error. what should i do?
 

khmp

Sponsor

Bitmap and Window objects do not have a tone attribute. Only Sprite and Viewport objects have the tone attribute. When the Game_Screen's tone changes only viewport1 of a Spriteset_Map instance is affected. The good news is that Window's can be assigned to a Viewport. If we tie your HUD to viewport1 of the Spriteset_Map object we can get the window to change tone with the rest of the screen. To do this in code is pretty simple. First we need to alter Window_Base so it takes in an extra parameter which will be the Viewport we need to assign the Window to. So let's override Window_Base's initialize:
Code:
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Object Initialization                                        !OVERRIDE!
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height, viewport = nil)
    viewport.nil? ? super() : super(viewport)
    @windowskin_name = $game_system.windowskin_name
    self.windowskin = RPG::Cache.windowskin(@windowskin_name)
    self.x = x
    self.y = y
    self.width = width
    self.height = height
    self.z = 100
  end
end

This will not break any existing code it only allows for the specification of an additional parameter. If the viewport is given, great the window will use it. If not the window will function like it always did. Next we need access to the viewport1 object inside Spriteset_Map. As that is the Viewport affected by $game_screen.tone.
Code:
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
#  This class brings together map screen sprites, tilemaps, etc.
#  It's used within the Scene_Map class.
#==============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :viewport1
end

Next you will need to change the way you initialize Window_HUD. We need it to take in one single argument. That being a Viewport object. I don't know your code so forgive me on this next part. Change the method definition line from:
Code:
def initialize
to:
Code:
def initialize(viewport = nil)
Then change the call from something like this:
Code:
super(x, y, width, height)
to:
Code:
super(x, y, width, height, viewport)

The final result of modifying your HUD's initialize will resemble something like this:
Code:
class Window_HUD < Window_Base
  def initialize(viewport = nil)
    super(x, y, width, height, viewport)
    ... # Other code
  end
end

Finally we need to make sure the HUD object when its created uses the viewport. Sadly we need to override Scene_Map's main. There's no other way around it. If we alias main like I assume is how you are doing it currently the Spriteset_Map object doesn't exist when we need it. Thus its viewport won't exist. So now we need to create our HUD after the Spriteset_Map object is created.
Code:
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map
  #--------------------------------------------------------------------------
  # * Main Processing                                              !OVERRIDE!
  #--------------------------------------------------------------------------
  def main
    # Make sprite set
    @spriteset = Spriteset_Map.new
    # Create our HUD object
    @hud = Window_HUD.new(@spriteset.viewport1)
    # Make message window
    @message_window = Window_Message.new
    # Transition run
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of sprite set
    @spriteset.dispose
    # Dispose of message window
    @message_window.dispose
    # Dispose of the HUD.
    @hud.dispose
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
  end
end

Hope that helps. If you need further assistance just let me know.

Good luck with it Fallen! :thumb:
 
Oh Great, thank you sooovery much. It's kinda hard, and i'm getting some "Disposed Window" Errors, but i'll figure them out, anyways, thank you very much, =D

Edit:
But i'll figure them out
....Or not
When i change the map (transfer player), i get a "Disposed Window" Error. the problem is that i have too many Map mods on some scripts. so i don't know what the problem is...Am i totally screwd up?
 

khmp

Sponsor

Could you create a demo? I'm not able to think of what is going wrong based on that. If you are worried about privacy feel free to PM me the link of the demo.
 
ummm...actually the game containing the script is about half way, so it's kinda TOO big, but...i'll try, thank you =D

i'll put the scripts in a new game, so expect a PM soon =D
 

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