Class: MyStateObj
- Inherits:
-
GGLib::StateObject
- Object
- GGLib::StateObject
- MyStateObj
- Defined in:
- lib/examples/BasicExample.rb
Overview
Now for our state object:
Instance Method Summary collapse
-
#initialize ⇒ MyStateObj
constructor
We can override the constructor as normal, but be careful not to mess around with the window here! The window does not belong to this state object yet: another state object is using it.
-
#onEnd ⇒ Object
This method is called right after our state object looses ownership of the window.
-
#onStart ⇒ Object
This method is called right after our state object gains ownership over the window.
Methods inherited from GGLib::StateObject
#button_down, #button_up, #draw, #end, #onTerminate, #start, #update, #window
Constructor Details
#initialize ⇒ MyStateObj
We can override the constructor as normal, but be careful not to mess around with the window here! The window does not belong to this state object yet: another state object is using it.
36 37 38 39 |
# File 'lib/examples/BasicExample.rb', line 36 def initialize super @myvar = 42 end |
Instance Method Details
#onEnd ⇒ Object
This method is called right after our state object looses ownership of the window. The window is automatically reset, but if you modified anything other than the window, this is where you should clean it up.
59 60 61 |
# File 'lib/examples/BasicExample.rb', line 59 def onEnd puts "MyStateObj terminated." end |
#onStart ⇒ Object
This method is called right after our state object gains ownership over the window. Now we can perform operations that modify the window.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/examples/BasicExample.rb', line 43 def onStart puts "MyStateObj activated." #Since Gosu only allows one window instance at a time, the current #window is automatically sotred in the global $window. $window.setBackground("img/bggray.png") #Whats a GUI Library without widgets? #A textbox: $textbox = GGLib::TextBox.new("textbox1", 242, 100, 12, GGLib::Themes::Windows) #Some buttons: GGLib::Button.new("button1", "Click Me", 270, 50, Proc.new{ || $textbox.text = "Thank you" }, GGLib::Themes::Windows) GGLib::Button.new("button2", "Exit", 270, 200, Proc.new{ || $window.close; exit }, GGLib::Themes::Windows) end |