Resolve macros and cleanup
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user