mirror of
https://github.com/Not-Nik/raylib-zig.git
synced 2025-09-08 19:47:28 +00:00
example: add text_writing_anim
This commit is contained in:
parent
9faf4b97a1
commit
5004bb2316
@ -347,6 +347,11 @@ pub fn build(b: *std.Build) !void {
|
||||
.path = "examples/text/text_raylib_fonts.zig",
|
||||
.desc = "Show fonts included with raylib",
|
||||
},
|
||||
.{
|
||||
.name = "text_writing_anim",
|
||||
.path = "examples/text/text_writing_anim.zig",
|
||||
.desc = "Simple text animation",
|
||||
},
|
||||
.{
|
||||
.name = "textures_image_loading",
|
||||
.path = "examples/textures/textures_image_loading.zig",
|
||||
|
46
examples/text/text_writing_anim.zig
Normal file
46
examples/text/text_writing_anim.zig
Normal file
@ -0,0 +1,46 @@
|
||||
const rl = @import("raylib");
|
||||
const Color = rl.Color;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
pub fn main() void {
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const screenWidth = 800;
|
||||
const screenHeight = 450;
|
||||
|
||||
rl.initWindow(screenWidth, screenHeight, "raylib [text] example - text writing anim");
|
||||
defer rl.closeWindow(); // Close window and OpenGL context
|
||||
|
||||
const message = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
|
||||
|
||||
var framesCounter: i32 = 0;
|
||||
|
||||
rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!rl.windowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter += if (rl.isKeyDown(rl.KeyboardKey.space)) 8 else 1;
|
||||
|
||||
if (rl.isKeyPressed(rl.KeyboardKey.enter)) framesCounter = 0;
|
||||
//----------------------------------------------------------------------------------
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl.beginDrawing();
|
||||
|
||||
rl.clearBackground(Color.white);
|
||||
|
||||
rl.drawText(rl.textSubtext(message, 0, @divFloor(framesCounter, 10)), 210, 160, 20, Color.maroon);
|
||||
|
||||
rl.drawText("PRESS [ENTER] to RESTART!", 240, 260, 20, Color.light_gray);
|
||||
rl.drawText("HOLD [SPACE] to SPEED UP!", 239, 300, 20, Color.light_gray);
|
||||
|
||||
rl.endDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user