module Scar::Input
Overview
This module provides simple digital and analogue input bindings.
You can also get creative with your input sources, you could e. g. implement an analogue input that changes with the current time.
Example usage:
input.bind_digital :jump { Scar::Input.sf_key :Space }
input.bind_axis :time { Time.utc.millisecond / 1000 }
input.axis :time # => 0.415 (example)
Extended Modules
Defined in:
scar/input.crInstance Method Summary
-
#active?(which : Symbol)
Returns true if the specified digital input is currently active
-
#axis(which : Symbol)
Returns the value for the specified analogue input
-
#bind_axis(which : Symbol, &block : -> Float32)
Binds a
Symbol
to an analogue input -
#bind_digital(which : Symbol, &block : -> Bool)
Binds a
Symbol
to a digital input
Macro Summary
-
key_pressed?(which)
Shortcut for digital inputs based on keys
Instance Method Detail
def bind_axis(which : Symbol, &block : -> Float32)
#
Binds a Symbol
to an analogue input
Similar to #bind_digital
, but here the check has to return a float instead of a boolean
def bind_digital(which : Symbol, &block : -> Bool)
#
Binds a Symbol
to a digital input
The check should return true if the input is currently active and false if not
Example usage:
input.bind_digital :jump { SF::Keyboard.key_pressed? SF::Keyboard::Space }
Macro Detail
macro key_pressed?(which)
#
Shortcut for digital inputs based on keys
Example usage:
input.bind_digital(:jump) { Scar::Input.key_pressed? :Space }
# This turns into
input.bind_digital(:jump) { SF::Keyboard.key_pressed? SF::Keyboard::{{which.id}} }