Add text animation
parent
16f18d24fd
commit
bac2941490
24
as0/as0.cpp
24
as0/as0.cpp
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue