Module: SFML::InputQueries
Overview
Instance-side helpers — included into App and Scene so user code
can call action_pressed? / axis from #update etc.
Instance Method Summary collapse
-
#action_pressed?(action_name) ⇒ Boolean
trueif any input bound toaction_nameis currently held. -
#axis(negative:, positive:) ⇒ Object
Synthetic digital axis from two opposing actions.
Instance Method Details
#action_pressed?(action_name) ⇒ Boolean
true if any input bound to action_name is currently held.
Looks up bindings on self.class.action_bindings (App-style)
or falls back to the host App when called from a Scene.
74 75 76 77 78 79 80 81 82 |
# File 'lib/sfml/input_actions.rb', line 74 def action_pressed?(action_name) bindings = _resolve_action_bindings[action_name.to_sym] return false unless bindings bindings[:keys].any? { |k| Keyboard.key_pressed?(k) } || bindings[:scancodes].any? { |s| Keyboard.scancode_pressed?(s) } || bindings[:mouse_buttons].any? { |b| Mouse.(b) } || bindings[:joy_buttons].any? { |(j, b)| Joystick.(j, b) } end |
#axis(negative:, positive:) ⇒ Object
Synthetic digital axis from two opposing actions. Returns -1.0, 0.0, or +1.0 — never both 1 and -1 (positive wins if both held).
86 87 88 89 90 |
# File 'lib/sfml/input_actions.rb', line 86 def axis(negative:, positive:) pos = action_pressed?(positive) ? 1.0 : 0.0 neg = action_pressed?(negative) ? 1.0 : 0.0 pos - neg end |