Based on the Space Shooter demo app by Belén Albeza González, I've been using a Singleton instance of Gosu::Window. However, I ran into and issue when trying to access the attributes of the window, specifically mouse_x and mouse_y. I can't seem to find a way to access those instance variables while using the Singleton mixin. Has anyone else run into this problem?
I think Ruby's singleton doesn't solve circular dependencies. I used it in one game and had the lockup too. My Window called SomeGameObject.new in its constructor, which in turn called Image.new(MyWindow.instance, ...), and so it ended up being an endless loop. Kind of sad that the singleton lib didn't even check for this very common problem :(
My workaround was to just create the first "state" after the Window was constructed (and accessible via MyWindow.instance). The future, supercool workaround will of course happen in Gosu itself, once Image.new doesn't need the Window arg anymore. The next release might already be very close to that.
Alright, just jumped into the code for a minute, turns out I was calling Game.instance inside a constructor which was getting called inside the constructor for the play state, which was getting initialized by my Gosu::Window. So, my solution was as simple as initializing my variables to zero, then setting them based on the mouse position in the update loop. Hopefully I won't make that mistake again.