Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Support for multiple windows [from wiki]
- By jlnr (dev) Date 2009-01-07 10:20
(This thread of discussion originated on the wiki but has since been moved to the forums.)

Comment by tmcdowell, Apr 30, 2008
Hey, I am just going through the first ruby tutorial thing, and adding onto it as I go, so I've made a separate class called 'PopUp?' which inherits from the normal Gosu::Window class. I'll explain the problem after this bit of code:

class PopUp? < Gosu::Window

  def initialize
    super(240, 240, false) @font = Gosu::Font.new(self, Gosu::default_font_name, 10)
  end
  def update
    if button_down? Gosu::Button::Kb then
      close
    end
  end
  def draw
    @font.draw("You have opened up the WIP menu!", 10, 10, 0xffffff00)
  end
end
pu = PopUp.new
w = GameWindow.new(pu)
w.show


Thats the PopUp? bit, and the window bit:

class GameWindow < Gosu::Window

  def initialize(popup)
    @pu = popup super(640, 480, false)
    self.caption = "Gosu Tutorial Game"
    @background_image = Gosu::Image.new(self, "/Users/kidz/Desktop/dynamite.png", true)
    @player = Player.new(self)
    @player.warp(320, 240)
  end
  def update
    if button_down? Gosu::Button::KbLeft then
      @player.turn_left
    end
    if button_down? Gosu::Button::KbRight then
      @player.turn_right
    end
    if button_down? Gosu::Button::KbUp then
      @player.accelerate
    end
    if button_down? Gosu::Button::KbDown then
      @player.reversebackup
    end
    if button_down? Gosu::Button::KbSpace then
      @pu.show
    end
    @player.move
  end
  def draw
    @player.draw
    @background_image.draw(0, 0, 0)
  end
  def button_down(id)
    if id == Gosu::Button::KbEscape
      close
    end
  end
end

The problem is this: I hit space in the program to open the popup, and the entire thing just closes down... any ideas? Also, can I get a little example on how to use 'visible'?

Comment by tmcdowell, Apr 30, 2008
Hrm, in the popup class I changed it to KbReturn to close it, and now when I hit space it freezes up, and there is a weird, crazy screwed up window BEHIND the main, but I still can close it via the close button in top left corner of the window, then the main window starts working for about a second, and then closes. I am on an iMac 10.4

Comment by julianraschke, Apr 30, 2008

tmcdowell: The disappointing bottom line is that you shouldn't use more than one window at a time. I'll add that as a note to the RubyReference to make this more clear because it often seems to cause confusion. I will try to improve on this in Gosu 0.8.x, i.e. either throw an explanative error the moment a second Window is created, or extend Window so multiple windows actually make sense. With the current interface, you couldn't place the popup or make it always in front of the main one.

Comment by tmcdowell, Jun 09, 2008
Has their been any update to the ability to create multiple windows?

Comment by julianraschke, Jun 10, 2008
No; actually, at the moment it seems that it will rather be explicitly forbidden because a) there's a LOT that is missing for multiple windows to make sense in any use case (I think), and b) with only one window, all the window arguments could be omitted from the constructors.

But since nothing of that has been made into code yet, what are you trying to build? :)

Comment by rabbitblue, Jun 21, 2008
@tmcdowell

For the record, I agree with Julian's stance on not having multiple windows. Name one modern game that uses multiple windows. I'm talking about real OS-level windows, not faux/graphical windows.

I think the only game I've ever played that had multiple windows was called Dungeons of Mordor. Screenshot available here about 1/3 way down:

http://www.vintagecomputing.com/index.php/archives/180

I've forgotten the terminology but those are child windows to a parent. That feels like a feature of Windows specifically because I've never seen a Cocoa app that does that.

Anywho, what you probably need are states. I have a simple state machine you can use over at github:

http://github.com/angryrabbit/retris/tree/master

HTH.
Up Topic Gosu / Gosu Exchange / Support for multiple windows [from wiki]

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill