Add text animation

master
John Montagu, the 4th Earl of Sandvich 2026-02-01 17:50:10 -08:00
parent 16f18d24fd
commit bac2941490
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
1 changed files with 14 additions and 10 deletions

View File

@ -6,14 +6,14 @@ int main() {
raylib::Window window(800, 600, "CS381 - Assignment 0"); raylib::Window window(800, 600, "CS381 - Assignment 0");
window.SetState(FLAG_WINDOW_RESIZABLE); window.SetState(FLAG_WINDOW_RESIZABLE);
while (!window.ShouldClose()) { const std::string msg = "I LOVE CS 381 AND RAYLIB!!!!";
raylib::Text text; const char *msgCstr = msg.c_str();
int fontHeight = 20; const float fontSize = 20;
text.SetText("Hello World"); const float spacing = 2.0f;
text.SetFontSize(fontHeight);
text.SetSpacing(2);
text.SetColor(raylib::Color::Gray());
window.SetTargetFPS(60); // save cpu cycles
while (!window.ShouldClose()) {
window.BeginDrawing(); window.BeginDrawing();
window.ClearBackground(raylib::Color::RayWhite()); window.ClearBackground(raylib::Color::RayWhite());
@ -21,10 +21,14 @@ int main() {
int width = window.GetWidth(); int width = window.GetWidth();
int height = window.GetHeight(); int height = window.GetHeight();
int middleX = (width - text.Measure()) / 2; Font font = GetFontDefault();
int middleY = (height - fontHeight) / 2; 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(); window.EndDrawing();
} }