From bac2941490164a097d59a75bf4533ee737614c1d Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sun, 1 Feb 2026 17:50:10 -0800 Subject: [PATCH] Add text animation --- as0/as0.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/as0/as0.cpp b/as0/as0.cpp index a29694a..e8a14cf 100644 --- a/as0/as0.cpp +++ b/as0/as0.cpp @@ -6,14 +6,14 @@ int main() { raylib::Window window(800, 600, "CS381 - Assignment 0"); window.SetState(FLAG_WINDOW_RESIZABLE); - while (!window.ShouldClose()) { - raylib::Text text; - int fontHeight = 20; - text.SetText("Hello World"); - text.SetFontSize(fontHeight); - text.SetSpacing(2); - text.SetColor(raylib::Color::Gray()); + const std::string msg = "I LOVE CS 381 AND RAYLIB!!!!"; + const char *msgCstr = msg.c_str(); + const float fontSize = 20; + const float spacing = 2.0f; + window.SetTargetFPS(60); // save cpu cycles + + while (!window.ShouldClose()) { window.BeginDrawing(); window.ClearBackground(raylib::Color::RayWhite()); @@ -21,10 +21,14 @@ int main() { int width = window.GetWidth(); int height = window.GetHeight(); - int middleX = (width - text.Measure()) / 2; - int middleY = (height - fontHeight) / 2; + Font font = GetFontDefault(); + int textWidth = MeasureText(msgCstr, fontSize); + Vector2 origin = Vector2(textWidth / 2.0f, fontSize / 2.0f); + Vector2 position = Vector2(width / 2.0f, height / 2.0f); + float rotation = GetTime() * 22.5f; // 22.5 deg/s + Color color = raylib::Color::Gray(); - text.Draw(middleX, middleY); + DrawTextPro(font, msgCstr, position, origin, rotation, fontSize, spacing, color); window.EndDrawing(); }