Skip to content

Commit

Permalink
Add text format example
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonsilva committed Oct 23, 2023
1 parent 188857c commit 962c4e6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ Examples using raylib text functionality, including sprite fonts loading/generat
| 70 | [text_font_spritefont](text/text_font_spritefont.rb) | <img src="text/text_font_spritefont.png" alt="text_font_spritefont" width="80"> | ⭐️☆☆☆ | 1.0 | 1.0 | [Ray](https://github.com/raysan5) |
| 71 | [text_font_filters](text/text_font_filters.rb) | <img src="text/text_font_filters.png" alt="text_font_filters" width="80"> | ⭐️⭐️☆☆ | 1.3 | **4.2** | [Ray](https://github.com/raysan5) |
| 72 | [text_font_loading](text/text_font_loading.rb) | <img src="text/text_font_loading.png" alt="text_font_loading" width="80"> | ⭐️☆☆☆ | 1.4 | 3.0 | [Ray](https://github.com/raysan5) |
| 74 | [text_format_text](text/text_format_text.rb) | <img src="text/text_format_text.png" alt="text_format_text" width="80"> | ⭐️☆☆☆ | 1.1 | 3.0 | [Ray](https://github.com/raysan5) |
Binary file added examples/text/text_format_text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions examples/text/text_format_text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# ******************************************************************************************
#
# raylib [text] example - Text formatting
#
# Example originally created with raylib 1.1, last time updated with raylib 3.0
#
# Example ported to Ruby by Wilson Silva (@wilsonsilva). Works with Raylib 4.5
#
# Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
# BSD-like license that allows static linking with closed source software
#
# Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
#
# ******************************************************************************************

require 'bundler/setup'
require 'raylib'

# Initialization
# --------------------------------------------------------------------------------------
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450

Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [text] example - text formatting")

score = 100020
hiscore = 200450
lives = 5

Raylib.set_target_fps(60) # Set our game to run at 60 frames-per-second
# --------------------------------------------------------------------------------------

# Main game loop
until Raylib.window_should_close # Detect window close button or ESC key
# Draw
# ----------------------------------------------------------------------------------
Raylib.begin_drawing
Raylib.clear_background(Raylib::RAYWHITE)
Raylib.draw_text(Raylib.text_format("Score: %08i", :int, score), 200, 80, 20, Raylib::RED)
Raylib.draw_text(Raylib.text_format("HiScore: %08i", :int, hiscore), 200, 120, 20, Raylib::GREEN)
Raylib.draw_text(Raylib.text_format("Lives: %02i", :int, lives), 200, 160, 40, Raylib::BLUE)
Raylib.draw_text(Raylib.text_format("Elapsed Time: %02.02f ms", :float, Raylib.get_frame_time * 1000), 200, 220, 20, Raylib::BLACK)
Raylib.end_drawing
# ----------------------------------------------------------------------------------
end

# De-Initialization
# --------------------------------------------------------------------------------------
Raylib.close_window # Close window and OpenGL context
# --------------------------------------------------------------------------------------

0 comments on commit 962c4e6

Please sign in to comment.