Beginners_-_Mouse_Position_and_DrawText.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. Vector2 mousePos = GetMousePosition();
  18. // Draw
  19. //----------------------------------------------------------------------------------
  20. BeginDrawing();
  21. ClearBackground(RAYWHITE);
  22. DrawText("Getting the mouse and y position!",10,10,40,BLUE);
  23. DrawText(FormatText("x. %03f",mousePos.x), 100, 180, 40, LIGHTGRAY); // Mouse x and y are floats!!
  24. DrawText(FormatText("x. %03f",mousePos.y), 100, 220, 40, LIGHTGRAY); // Mouse x and y are floats!!
  25. EndDrawing();
  26. //----------------------------------------------------------------------------------
  27. }
  28. // De-Initialization
  29. //--------------------------------------------------------------------------------------
  30. CloseWindow(); // Close window and OpenGL context
  31. //--------------------------------------------------------------------------------------
  32. return 0;
  33. }