Make pools with generations and bind mouse position logic

This commit is contained in:
2026-05-06 16:40:36 +01:00
parent 08a642e07a
commit 3894b90398
8 changed files with 221 additions and 125 deletions
+11 -9
View File
@@ -16,7 +16,7 @@ text = ElementText.new :btn_text, default_font, position: {x: 50, y: 50}, z: 1,
rect = ElementRect.new({x: 50, y: 50, w: 100, h: 25}, 0xFF0000FF, z: 0)
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_through: true
rect.on_click do
rect.color = rect.color == 0xFF0000FF ?
@@ -73,15 +73,17 @@ 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
# simple logic to handle hover
pos = App.mouse_position
next if pos.nil? # mouse position can be nil if the window is not focused, so we skip the hover logic in that case
elements = main_scene.elements_at(*pos.values)
if elements.include?(rect)
rect.color = 0x0000FFFF
else # also handles nil case, if the mouse is not over any element, we reset the color
rect.color = 0xFF0000FF
el = main_scene.elements_at(App.mouse_position)
for elem in el
if elem == image_element
puts "Hovering over image element"
elsif elem == rect
puts "Hovering over rect element"
elsif elem == text
puts "Hovering over text element"
end
end
end
main_scene << text