Add global update loop, and cleanup
This commit is contained in:
+19
-8
@@ -12,19 +12,32 @@ bg_animation = Animation.new [bg_image1, bg_image2], fps: 5
|
||||
App.language = :en
|
||||
App.localize(:en, :btn_text, "Click %{name}!")
|
||||
|
||||
text = ElementText.new :btn_text, default_font, 0xFFFF00, {name: "Me"}, position: {x: 50, y: 50}, z: 1, click_mode: :pass, alpha: 1
|
||||
text = ElementText.new :btn_text, default_font, 0xFFFF00, {name: "Me"}, position: {x: 50, y: 50}, z: 1, click_mode: :block, alpha: 1
|
||||
|
||||
rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotation: 60, scale: { x: 1, y: 1 }, alpha: 0.4
|
||||
rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotation: 60, scale: { x: 1, y: 1 }, alpha: 0.8, click_mode: :block
|
||||
|
||||
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_mode: :ignore, alpha: 1
|
||||
|
||||
pp text, rect, image_element
|
||||
|
||||
rect.on_click do
|
||||
end_scene = Scene.new
|
||||
end_scene << rect
|
||||
|
||||
text.click do
|
||||
App.switch_to end_scene
|
||||
end
|
||||
|
||||
image_element.click do
|
||||
pp "Image clicked"
|
||||
end
|
||||
|
||||
rect.click do
|
||||
pp "Rect clicked", rect.color.to_s(16)
|
||||
|
||||
rect.color = rect.color == 0xFF0000 ?
|
||||
0x00FF00 :
|
||||
0xFF0000
|
||||
main_scene << text unless main_scene.elements.include?(text)
|
||||
|
||||
text.params[:name] = text.params[:name] == "Me" ?
|
||||
"You" :
|
||||
"Me"
|
||||
@@ -37,7 +50,7 @@ start = Time.now
|
||||
c_ = 0.0
|
||||
c_c = 0
|
||||
|
||||
main_scene.on_update do |delta_time|
|
||||
App.update do |delta_time|
|
||||
c_ += delta_time
|
||||
c_c += 1
|
||||
|
||||
@@ -45,7 +58,7 @@ main_scene.on_update do |delta_time|
|
||||
# commented out to avoid spamming the console, but you can uncomment to see the delta time being printed every frame
|
||||
# runs at 60fps, so you should see around 16-17ms being printed
|
||||
|
||||
el = main_scene.elements_at(App.mouse_position)
|
||||
el = App.scene.elements_at(App.mouse_position)
|
||||
|
||||
pp App.text_input if App.text_input != ""
|
||||
|
||||
@@ -68,8 +81,6 @@ main_scene << text
|
||||
main_scene << rect
|
||||
main_scene << image_element
|
||||
|
||||
main_scene.delete(text)
|
||||
|
||||
App.start main_scene
|
||||
|
||||
time = Time.now - start
|
||||
|
||||
Reference in New Issue
Block a user