The "Scene" style workings of RPG maker are even easier to implement into Gosu.
First you need a scene:
- class Scene_Start
- def update
-
- end
- end
Expand to see the code.
We don't need to update Graphics like in RPG Maker; nor do we need to run a loop (see below).
We need our game window:
- class Game < Window
- def initialize
- super(640, 480, false)
- self.caption = "Scene Changing Demo"
- $scene = Scene_Start.new
- end
- def update
- $scene.update
- end
- end
Expand to see the code.
The method
initialize is called when the game is first opened. As such this can be used to call our initial scene (here, Scene_Start).
The method
update is ran once per frame, automatically. Therefore, we can call our scene update methods here for convenience.
From before you'll note that super(x, y, fullscreen?) here makes the window 640x480, with no fullscreen mode.
Now all that remains is to call the script:
-
- $game = Game.new
- $game.show
Expand to see the code.
Demo
- require 'rubygems'
- require 'gosu'
- include Gosu
-
- class Scene_End
- def update
- $game.draw_text('Scene_End (Press Down to close)', 0, 0, 0)
- if $game.button_down?(Button::KbDown)
- exit
- end
- end
- end
-
- class Scene_Start
- def update
- $game.draw_text('Scene_Start (Press Up to continue)', 0, 0, 0)
- if $game.button_down?(Button::KbUp)
- $scene = Scene_End.new
- end
- end
- end
-
- class Game < Window
- def initialize
- super(640, 480, false)
- self.caption = "Scene Changing Demo"
- $scene = Scene_Start.new
- @font = Font.new(self, "Times New Roman", 24)
- end
- def update
- $scene.update
- end
- def draw_text(text, x, y, z)
- @font.draw(text, x, y, z, 1, 1)
- end
- end
-
- $game = Game.new
- $game.show
Expand to see the code.
You'll noticed I added a draw_text method; this was just for ease and probably wasn't needed. Nonetheless, play around with the "demo" some and yeah.
This probably didn't need a tutorial; nonetheless if you have any problems with this post here.