summaryrefslogtreecommitdiffhomepage
path: root/mrblib/raylib.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-01-20 05:33:05 -0500
committerrealtradam <[email protected]>2022-01-20 05:33:05 -0500
commit07779824f6c6535c9d45aa2384475ca75fc1895e (patch)
tree4971a26b0143e932bb524935aed304b1c847d75c /mrblib/raylib.rb
parentced40dd6205b6c74101dc97d3f932870e7cb231b (diff)
downloadmruby-raylib-07779824f6c6535c9d45aa2384475ca75fc1895e.tar.gz
mruby-raylib-07779824f6c6535c9d45aa2384475ca75fc1895e.zip
input functions
Diffstat (limited to 'mrblib/raylib.rb')
-rw-r--r--mrblib/raylib.rb25
1 files changed, 22 insertions, 3 deletions
diff --git a/mrblib/raylib.rb b/mrblib/raylib.rb
index 7c8f6c2..67d1b9e 100644
--- a/mrblib/raylib.rb
+++ b/mrblib/raylib.rb
@@ -2,19 +2,25 @@ Rl = Raylib
module Raylib
class << self
- attr_accessor :main_loop
+ attr_accessor :defined_loop
+ attr_accessor :data_keys_pressed
def while_window_open(&block)
- self.main_loop = block
+ self.defined_loop = block
if Raylib.platform == 'desktop'
while !Raylib.window_should_close? do
- self.main_loop.call
+ self.main_loop
end
elsif Raylib.platform == 'web'
Raylib.emscripten_set_main_loop
end
end
+ def main_loop
+ self.data_keys_pressed = nil
+ self.defined_loop.call
+ end
+
def draw_text(text:, x:, y:, font_size:, color:)
self._draw_text(text, x, y, font_size, color)
@@ -23,5 +29,18 @@ module Raylib
def draw_texture(texture:, x:, y:, tint: Rl::Color.new(255,255,255,255))
self._draw_texture(texture, x, y, tint)
end
+
+ def keys_pressed
+ if self.data_keys_pressed
+ return self.data_keys_pressed
+ end
+ self.data_keys_pressed = []
+ key = self._key_pressed
+ while key != 0
+ self.data_keys_pressed.push key
+ key = self._key_pressed
+ end
+ self.data_keys_pressed
+ end
end
end