text_writing_anim.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*******************************************************************************************
  2. *
  3. * raylib [text] example - writing anim
  4. *
  5. * Example complexity rating: [★★☆☆] 2/4
  6. *
  7. * Example originally created with raylib 1.4, last time updated with raylib 1.4
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2016-2025 Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. //------------------------------------------------------------------------------------
  17. // Program main entry point
  18. //------------------------------------------------------------------------------------
  19. int main(void)
  20. {
  21. // Initialization
  22. //--------------------------------------------------------------------------------------
  23. const int screenWidth = 800;
  24. const int screenHeight = 450;
  25. InitWindow(screenWidth, screenHeight, "raylib [text] example - writing anim");
  26. const char message[128] = "This sample illustrates a text writing\nanimation effect! Check it out! ;)";
  27. int framesCounter = 0;
  28. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  29. //--------------------------------------------------------------------------------------
  30. // Main game loop
  31. while (!WindowShouldClose()) // Detect window close button or ESC key
  32. {
  33. // Update
  34. //----------------------------------------------------------------------------------
  35. if (IsKeyDown(KEY_SPACE)) framesCounter += 8;
  36. else framesCounter++;
  37. if (IsKeyPressed(KEY_ENTER)) framesCounter = 0;
  38. //----------------------------------------------------------------------------------
  39. // Draw
  40. //----------------------------------------------------------------------------------
  41. BeginDrawing();
  42. ClearBackground(RAYWHITE);
  43. DrawText(TextSubtext(message, 0, framesCounter/10), 210, 160, 20, MAROON);
  44. DrawText("PRESS [ENTER] to RESTART!", 240, 260, 20, LIGHTGRAY);
  45. DrawText("HOLD [SPACE] to SPEED UP!", 239, 300, 20, LIGHTGRAY);
  46. EndDrawing();
  47. //----------------------------------------------------------------------------------
  48. }
  49. // De-Initialization
  50. //--------------------------------------------------------------------------------------
  51. CloseWindow(); // Close window and OpenGL context
  52. //--------------------------------------------------------------------------------------
  53. return 0;
  54. }