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");
|
||||
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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue