Helps you develop Gosu games more quickly.
Hot code loading
Normally, when you change the code for a Gosu game, you have to close and restart the game for the code to take affect. With Hasu, modified source files will be reloaded each time through the game loop.
When an exception bubbles up out of your game loop, Gosu will crash. When an exception occurs in a Hasu game, Hasu pauses your game, prints the exception details into your window, and resumes your game once the code that fixes it is loaded.
Hot code loading unfortunately is worthless for your
initialize method since your window will only be initialized once,
Instead of putting your game's setup code in
initialize, place it in
reset and press R whenever you want to re-initialize your game state.
The above features only work on Ruby 2+, though Hasu will still load on earlier versions (in case you want to pack up your game with Releasy).
0: Install Hasu
Add this line to your application's Gemfile:
Or install it yourself as:
$ gem install hasu
Hasu::Window (or prepend
Instead of subclassing
class Game < Hasu::Window def initialize super(640, 480, false) end def reset # ... end def update # ... end def draw # ... end end
If you're using Chingu (or another library which has its own window subclass), you can prepend
Hasu::Guard onto your window for the same effect:
class Game < Chingu::Window prepend Hasu::Guard def initialize super(640, 480, false) end def reset # ... end def update # ... end def draw # ... end end
Hasu.load to require your game's files.
For the files you want to be hot loaded, use
Hasu.load instead of
3: Run your game with
Game.new.show, run your Hasu game with