Add ruby bindings for internal structures, allow better controlled localization
This commit is contained in:
+17
-22
@@ -4,33 +4,35 @@ main_scene = Scene.new
|
||||
|
||||
default_font = Font.new "assets/fonts/charybdis.ttf", 24, pixel_art: true
|
||||
|
||||
bg_image1 = Image.new "assets/images/menu_bg.png", alpha: 0.7, pixel_art: true
|
||||
bg_image2 = Image.new "assets/images/game_over_dead_bg.png", alpha: 1, pixel_art: true
|
||||
bg_image1 = Image.new "assets/images/menu_bg.png", pixel_art: true
|
||||
bg_image2 = Image.new "assets/images/game_over_dead_bg.png", pixel_art: true
|
||||
|
||||
bg_animation = Animation.new [bg_image1, bg_image2], fps: 5
|
||||
|
||||
App.language = :en
|
||||
App.localize(:en, :btn_text, "Click me!")
|
||||
App.localize(:en, :btn_text, "Click %{name}!")
|
||||
|
||||
text = ElementText.new :btn_text, default_font, position: {x: 50, y: 50}, z: 1, click_through: true
|
||||
text = ElementText.new :btn_text, default_font, 0xFFFFFF, {name: "Me"}, position: {x: 50, y: 50}, z: 1, click_through: true, alpha: 1
|
||||
|
||||
rect = ElementRect.new({x: 50, y: 50, w: 100, h: 25}, 0xFF0000FF, z: 0)
|
||||
rect = ElementRect.new 100, 25, 0xFF0000, position: {x: 50, y: 50}, z: 0, rotation: 60, scale: { x: 1.5, y: 1 }, alpha: 0.4
|
||||
|
||||
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_through: true
|
||||
image_element = ElementImage.new bg_animation, position: {x: 0, y: 0}, z: -1, click_through: true, alpha: 1
|
||||
|
||||
rect.on_click do
|
||||
rect.color = rect.color == 0xFF0000FF ?
|
||||
0x00FF00FF
|
||||
:
|
||||
0xFF0000FF
|
||||
rect.color = rect.color == 0xFF0000 ?
|
||||
0x00FF00 :
|
||||
0xFF0000
|
||||
text.params[:name] = text.params[:name] == "Me" ?
|
||||
"You" :
|
||||
"Me"
|
||||
text.params!
|
||||
end
|
||||
|
||||
|
||||
=begin
|
||||
|
||||
input handling:
|
||||
|
||||
on_click - exists to simplify on elements, not the standard way.
|
||||
|
||||
App.map_key(:space, :jump) # maps the space key to a :jump action (multiple keys can be mapped to the same action)
|
||||
# all events here are in english ones, (so need to find which english key corresponds to the key in the current language of the keyboard)
|
||||
key can be one of [:a..:z, :0..:9, :space, :enter, :shift, :ctrl, :alt, :tab, :backspace, :escape, :up, :down, :left, :right, :middle]
|
||||
@@ -58,16 +60,9 @@ App.text_input # returns the text typed this frame as a string (useful for text
|
||||
|
||||
App.stop_text_input!
|
||||
|
||||
####
|
||||
|
||||
also in a scene you can use (with click_though semantics):
|
||||
|
||||
main_scene.elements_at(x, y)
|
||||
|
||||
=end
|
||||
|
||||
|
||||
|
||||
main_scene.on_update do |delta_time|
|
||||
# puts "Delta time: #{delta_time}ms"
|
||||
# commented out to avoid spamming the console, but you can uncomment to see the delta time being printed every frame
|
||||
@@ -76,11 +71,11 @@ main_scene.on_update do |delta_time|
|
||||
el = main_scene.elements_at(App.mouse_position)
|
||||
for elem in el
|
||||
if elem == image_element
|
||||
puts "Hovering over image element"
|
||||
#puts "Hovering over image element"
|
||||
elsif elem == rect
|
||||
puts "Hovering over rect element"
|
||||
#puts "Hovering over rect element"
|
||||
elsif elem == text
|
||||
puts "Hovering over text element"
|
||||
#puts "Hovering over text element"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user