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] My window comes up, then goes away.

Status
Not open for further replies.
This is the script I'm using:
Code:
class Itachi_One < Window_Base
  
  def to_s
    $game_variables[15].to_s
  end
  
  def initialize
    super(0, 0, 70, 70)
    self.contents = Bitmap.new(width-32, height-32)
    @windowskin_name = $game_system.windowskin_name
    self.contents.font.name = "Arial"  
    self.contents.font.size = 24
    self.contents.draw_text(0, 0, 100, 32, to_s + "%")   
    refresh
  end
  
  def refresh
    Graphics.update
    self.contents.clear
    self.contents.font.color = text_color(2)
    self.contents.draw_text(0, 0, 100, 32, to_s + "%")    
  end  
  
  def update
    refresh
  end
end

The problem is, once I use Itachi_One.new to bring the window up, it disappears after a while. With my crappy scripting knowledge, I have no idea how to fix this. So how do I fix it so it stays forever?
 

khmp

Sponsor

Don't call Graphics.update in the refresh. And although the update will work as it should you should limit calls to draw_text if possible. So make a check to see if the variable has changed from the last time you drew the text. You just need to save the variable in a class instance variable.

Example:
Code:
class Itachi_One < Window_Base
  def initialize
    super(0, 0, 70, 70)
    self.contents = Bitmap.new(width-32, height-32)
    self.contents.font.name = 'Arial'
    self.contents.font.size = 24
    self.contents.font.color = text_color(2)
    @var = nil
    refresh
  end

  def to_s
    $game_variables[15].to_s
  end

  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 100, 32, to_s + "%")
  end

  def update
    return if @var == $game_variables[15]
    @var = $game_variables[15]
    refresh
  end
end
 

khmp

Sponsor

Alright:

Code:
class Scene_Map
  # Aliased methods
  alias_method :old_main, :main
  alias_method :old_update, :update
  
  def main
    @window = Itachi_One.new
    old_main
    @window.dispose
  end

  def update
    @window.update
    if Input.trigger?(Input::R)
      @window.visible = !@window.visible
    end
    old_update
  end
end

Just insert that code above main and while in Scene_Map whenever you press the 'W' key on the keyboard. The window will appear or disappear.
 
This topic has been resolved. If Itachi62 or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

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