summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
Diffstat (limited to 'mrblib')
-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