From 07779824f6c6535c9d45aa2384475ca75fc1895e Mon Sep 17 00:00:00 2001 From: realtradam Date: Thu, 20 Jan 2022 05:33:05 -0500 Subject: input functions --- mrblib/raylib.rb | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'mrblib') 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 -- cgit v1.2.3