Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Passing around window 2: Electric Bugaloo
- - By Zaxser Date 2015-10-26 10:58 Edited 2015-10-26 14:47
Every tutorial I've seen for Gosu has you take a window object for all your external classes, and then take self when initialized inside the window. This is super clunky and unruby like. Some posts here:

seem to imply it's unnecessary, but I don't quite understand how.

This also seems like the sort of thing that you could work around with just a touch of metaprogramming, but I'm not exactly sure how.

EDIT: Changed the link, jlnr was right about it being the wrong link.
Parent - - By jlnr (dev) Date 2015-10-26 11:25
Did you perhaps copy the wrong link there?

I think you are referring to the interface changes in Gosu 0.9+. Previously, you had to pass a Window reference to etc. (for 10 years!) - that has changed in Gosu 0.9, half a year ago.

The old overloads are documented in Gosu's rdoc, and are not likely to go away anytime soon:

I would guess that at least 95% of all Gosu code ever written still uses the old interface.

If you see a tutorial that uses the old interface, maybe you can help the author migrate it to the new one? I've been meaning to to ping the authors of the various Gosu Tutorial translations, but I haven't found the time yet.
Parent - - By Zaxser Date 2015-10-26 13:00
I mean something like:

class Game < Gosu::Window
  def initialize, self)

class Player
  def initialize(var1, var2, ..., window)

When you start to a lot of objects, the code starts to look stupid. There's got to be a workaround.
Parent - - By jlnr (dev) Date 2015-10-26 15:58
Yes, that was usually necessary because the Player class wanted to load images, and required a window reference. That is not the case in Gosu 0.9+.

In any case, the easiest workaround was to use a global variable called $window throughout your app, and set it in YourWindowClass#initialize (right after the super call). You could also use the Singleton module from the Ruby standard library, but I am not sure if it has any practical advantage over a global variable.
Parent - By Zaxser Date 2015-10-26 17:13
Oh man, I looked at the documentation, and you're totally right. I haven't used gosu since umm... maybe March? That makes everything WAY less clunky.
Up Topic Gosu / Gosu Exchange / Passing around window 2: Electric Bugaloo

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill