Beginners_-_FormatText.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 450;
  8. InitWindow(screenWidth, screenHeight, "raylib example.");
  9. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  10. //--------------------------------------------------------------------------------------
  11. // Main game loop
  12. while (!WindowShouldClose()) // Detect window close button or ESC key
  13. {
  14. // Update
  15. //----------------------------------------------------------------------------------
  16. //----------------------------------------------------------------------------------
  17. // Draw
  18. //----------------------------------------------------------------------------------
  19. BeginDrawing();
  20. ClearBackground(RAYWHITE);
  21. DrawText("FormatText Example",50,180,60,GRAY);
  22. float val1 = 10.3821;
  23. // only draw 2 numbers before and after the .
  24. DrawText(FormatText("val1: %02.02f",val1),100,100,20,BLACK);
  25. int val2 = 12345;
  26. // 10 x 0 before the int is drawn.
  27. DrawText(FormatText("val2: %010i",val2),100,120,20,BLACK);
  28. // We can put multiple things inside the formattext function.
  29. DrawText(FormatText("val1 : %f val2 : %i",val1,val2),100,140,20,BLACK);
  30. EndDrawing();
  31. //----------------------------------------------------------------------------------
  32. }
  33. // De-Initialization
  34. //--------------------------------------------------------------------------------------
  35. CloseWindow(); // Close window and OpenGL context
  36. //--------------------------------------------------------------------------------------
  37. return 0;
  38. }