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.

How should I create a window?

Hi!

I would like to ask anyone for help. Could anyone please tell me how do I open and close an in-game window in RMXP?

I mean, what should def initialize include? What should I add to the script code so I can dispose of all the graphics? I know I should include Graphics.dispose followed by a list of windows to be disposed, e.g. @a_window.dispose.

Could anyone show me an example? It would be one that would explain to me how you can make sure that the new window won't make the game crash saying that the window was disposed.

Thanks in advance for reading this post!!!

You can close this thread now.
 
Well, I already took a look at the default scripts. I know I should either initialize an index (actor_index) or I can open a window with super (x, y, width, height), but after the game opens several new windows included in def main I still can see a small window (the one I defined in def initialize...).
If I choose not to open a window in def initialize, the game will crash for sure...
What should I do then?
Ah... I posted the script on "another forum"...
 
It's all inheritance.

All windows come from Window_Base, which comes from the hidden class Window.

Let's look at Window_Base
Code:
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x      : window x-coordinate
  #     y      : window y-coordinate
  #     width  : window width
  #     height : window height
  #--------------------------------------------------------------------------
  def initialize(x, y, width, height)
    super()
    @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

Now, just for kicks, let's look at Window_Steps
Code:
#==============================================================================
# ** Window_Steps
#------------------------------------------------------------------------------
#  This window displays step count on the menu screen.
#==============================================================================

class Window_Steps < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  # ...
end

Now, the super keyword means, call the parent class method, with the same name. So when we create our step window, it calls the initialize method in Window_Base (Window_Gold < Window_Base), and sends 4 arguments to that method.

Back in Window_Base, we see that those four arguments set the x and y position, and the window width and height.


So, creating a new window class, we use:
Code:
class Window_Example < Window_Base
  def initialize
    super(x, y, width, height)
    # code
  end
  # code
end

Just change your x - height variables.

Personal suggestion: RMXP uses basic intervals of 32, 16, 8 and 4. I would try to make most of your numbers divisible by 32 in tabbing conditions, and 16, 8 or 4 in positioning conditions. Avoid to numbers like 33, 17, 75, etc. Your game will just look better if everything lines up all neat. :thumb:
 
Well, this is what I coded. I'm still having 2 issues here.

On the one hand is that I can see a window with a higher value for window opacity (I think it's just two windows overlapping which means that one of those 2 windows isn't actually needed at all).

On the other hand I believe I included a way to dispose the windows, but it never worked and I'm still unable to go back to the menu or the current map.

You can close this thread now. Thanks.
 

Zeriab

Sponsor

SephirothSpawn;327211 said:
Personal suggestion: RMXP uses basic intervals of 32, 16, 8 and 4. I would try to make most of your numbers divisible by 32 in tabbing conditions, and 16, 8 or 4 in positioning conditions. Avoid numbers like >>>32<<<, 17, 75, etc. Your game will just look better if everything lines up all neat. :thumb:

A little typo ^_^
You should not avoid 32. :p
 

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