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.cr

Instance Method Summary

Macro Summary

Instance Method Detail

def active?(which : Symbol) #

Returns true if the specified digital input is currently active


[View source]
def axis(which : Symbol) #

Returns the value for the specified analogue input


[View source]
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


[View source]
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 }

[View source]

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}} }

[View source]