Add renderer.text_scaled() Lua binding

lua_bindings.cpp:
- Added new lua_renderer_text_scaled() function
- Wraps renderer->draw_string_scaled() with proper scale support
- Registered as renderer.text_scaled(x, y, text, on, scale)
- Scale parameter defaults to 1 if omitted

Updated all 4 games to use text_scaled():
- simon_says.lua: All text now uses text_scaled with scale=2
- tic_tac_toe.lua: All text now uses text_scaled with scale=2
- memory_match.lua: All text now uses text_scaled with scale=2
- 2048.lua: All text now uses text_scaled with scale=2

This properly uses the C++ renderer's scaled text rendering instead of
workarounds in Lua, providing better performance and consistency.
This commit is contained in:
Adolfo Reyna
2026-02-12 21:31:15 -05:00
parent fa7d2fd32f
commit f398d62af2
5 changed files with 55 additions and 34 deletions

View File

@@ -122,8 +122,8 @@ function draw()
local start_y = get_grid_start_y()
if state == STATE_MENU then
renderer.text(game.width() / 2 - 15, game.height() / 2 - 30, "2048", true, 2)
renderer.text(game.width() / 2 - 50, game.height() / 2, "Tap to Start", true, 2)
renderer.text_scaled(game.width() / 2 - 15, game.height() / 2 - 30, "2048", true, 2)
renderer.text_scaled(game.width() / 2 - 50, game.height() / 2, "Tap to Start", true, 2)
elseif state == STATE_PLAYING or state == STATE_WIN or state == STATE_GAME_OVER then
-- Draw grid
@@ -143,27 +143,27 @@ function draw()
-- Draw value (simplified)
local text = tostring(value)
if string.len(text) <= 2 then
renderer.text(tile_x + 2, tile_y + 2, text, false, 2)
renderer.text_scaled(tile_x + 2, tile_y + 2, text, false, 2)
else
renderer.text(tile_x + 1, tile_y + 2, text, false, 2)
renderer.text_scaled(tile_x + 1, tile_y + 2, text, false, 2)
end
end
end
end
-- Draw score
renderer.text(10, 10, "Score: " .. tostring(game.vars.score), true, 2)
renderer.text_scaled(10, 10, "Score: " .. tostring(game.vars.score), true, 2)
if state == STATE_WIN then
renderer.text(game.width() / 2 - 30, game.height() / 2 - 20, "YOU WIN!", true, 2)
renderer.text(game.width() / 2 - 60, game.height() / 2, "Tap up: Continue", true, 2)
renderer.text(game.width() / 2 - 50, game.height() / 2 + 15, "Tap down: Menu", true, 2)
renderer.text_scaled(game.width() / 2 - 30, game.height() / 2 - 20, "YOU WIN!", true, 2)
renderer.text_scaled(game.width() / 2 - 60, game.height() / 2, "Tap up: Continue", true, 2)
renderer.text_scaled(game.width() / 2 - 50, game.height() / 2 + 15, "Tap down: Menu", true, 2)
end
if state == STATE_GAME_OVER then
renderer.text(game.width() / 2 - 40, game.height() / 2, "GAME OVER", true, 2)
renderer.text(game.width() / 2 - 30, game.height() / 2 + 15, "Score: " .. tostring(game.vars.score), true, 2)
renderer.text(game.width() / 2 - 60, game.height() / 2 + 30, "Tap to Menu", true, 2)
renderer.text_scaled(game.width() / 2 - 40, game.height() / 2, "GAME OVER", true, 2)
renderer.text_scaled(game.width() / 2 - 30, game.height() / 2 + 15, "Score: " .. tostring(game.vars.score), true, 2)
renderer.text_scaled(game.width() / 2 - 60, game.height() / 2 + 30, "Tap to Menu", true, 2)
end
end
end