Resolve macros and cleanup

This commit is contained in:
2026-05-05 23:10:14 +01:00
parent 7e9a5a7c4f
commit 08a642e07a
3 changed files with 445 additions and 252 deletions
+53
View File
@@ -25,10 +25,63 @@ rect.on_click do
0xFF0000FF
end
=begin
input handling:
on_click - exists to simplify on elements, not the standard way.
App.map_key(:space, :jump) # maps the space key to a :jump action (multiple keys can be mapped to the same action)
# all events here are in english ones, (so need to find which english key corresponds to the key in the current language of the keyboard)
key can be one of [:a..:z, :0..:9, :space, :enter, :shift, :ctrl, :alt, :tab, :backspace, :escape, :up, :down, :left, :right, :middle]
this can be checked anywhere using:
App.down?(:jump) # returns true if the jump action is currently being pressed
App.pressed?(:jump) # returns true if the jump action was just pressed this frame
App.released?(:jump) # returns true if the jump action was just released this frame
for wheel, you can use:
App.wheel # returns a hash with :x and :y values representing the wheel movement since the last frame (can be used for zooming, scrolling, etc.)
mouse position can be accessed with:
App.mouse_position # returns a hash with :x and :y values representing the current mouse position in the window
For localized input, you can use:
App.start_text_input!
App.text_input # returns the text typed this frame as a string (useful for text input fields, chat, etc.)
# can be multiple characters if the user types fast, so you should append it to a string variable to get the full input
App.stop_text_input!
####
also in a scene you can use (with click_though semantics):
main_scene.elements_at(x, y)
=end
main_scene.on_update do |delta_time|
# puts "Delta time: #{delta_time}ms"
# 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
end
end
main_scene << text