module SFML::InputActions

Class-level action DSL β€” named bindings over multiple physical inputs. Shared by SFML::App and SFML::Scene. Pairs with the Keybindings mixin: keybindings fire events (one-shot, on press), actions are polled state (β€œis the user holding this right now?”).

class MyGame < SFML::App action :jump, keys: [:space, :w] action :fire, mouse_buttons: [:left] action :left, keys: [:a, :left], scancodes: [:scan_a] action :right, keys: [:d, :right] action :crouch, joy_buttons: [[0, 0]] # joystick 0, button 0

def update(dt)
  speed = 200 * dt.as_seconds
  @x += speed if action_pressed?(:right)
  @x -= speed if action_pressed?(:left)
  @ball.jump if action_pressed?(:jump)
end

end

Keys are mapped via SFML::Keyboard.key_pressed? β€” the logical key under the current OS layout. Scancodes are mapped via SFML::Keyboard.scancode_pressed? β€” the physical position (recommended for WASD-style movement so the keys stay under the same fingers across layouts).

axis(:name) is a convenience for digital pairs: pass negative: and positive: actions and you get a Float in [-1, 1].

class Player < SFML::App action :go_left, keys: [:a, :left] action :go_right, keys: [:d, :right]

def update(dt)
  move = axis(negative: :go_left, positive: :go_right)
  @x += move * 200 * dt.as_seconds
end

end