Class: Ray::Input

Inherits:
Object
  • Object
show all
Defined in:
ext/input.c,
ext/input.c

Overview

An input object is used to keep track of pressed keys and the position of the mouse. Methods are also provided to affect the state of the input, possibly useful in tests.

Instance Method Summary collapse

Instance Method Details

#holding?(key) ⇒ true, false

Checks if a key is being held

Parameters:

  • key (Integer)

    A key

Returns:

  • (true, false)

    True if the given key is being held



86
87
88
89
90
# File 'ext/input.c', line 86

static
VALUE ray_input_holding(VALUE self, VALUE key) {
  return say_input_is_holding(ray_rb2input(self), NUM2INT(key)) ?
    Qtrue : Qfalse;
}

#mouse_posRay::Vector2

Returns The position of the mouse.

Returns:



93
94
95
96
# File 'ext/input.c', line 93

static
VALUE ray_input_mouse_pos(VALUE self) {
  return ray_vector2_to_rb(say_input_get_mouse_pos(ray_rb2input(self)));
}

#mouse_pos=(pos) ⇒ Object

Changes the known position of the mouse

Notice this only affects the input object’s state, it won’t actually move the mouse.

Parameters:



73
74
75
76
77
# File 'ext/input.c', line 73

static
VALUE ray_input_set_mouse_pos(VALUE self, VALUE pos) {
  say_input_set_mouse_pos(ray_rb2input(self), ray_convert_to_vector2(pos));
  return pos;
}

#press(key) ⇒ Object

Marks a key as pressed

Parameters:

  • key (Integer)

    A key



47
48
49
50
51
# File 'ext/input.c', line 47

static
VALUE ray_input_press(VALUE self, VALUE key) {
  say_input_press(ray_rb2input(self), NUM2INT(key));
  return Qnil;
}

#release(key) ⇒ Object

Marks a key as released

Parameters:

  • key (Integer)

    A key



58
59
60
61
62
# File 'ext/input.c', line 58

static
VALUE ray_input_release(VALUE self, VALUE key) {
  say_input_release(ray_rb2input(self), NUM2INT(key));
  return Qnil;
}

#resetObject

Resets the input

After a reset, all the keys are marked released and the mouse position is set to (0, 0).



36
37
38
39
40
# File 'ext/input.c', line 36

static
VALUE ray_input_reset(VALUE self) {
  say_input_reset(ray_rb2input(self));
  return self;
}