core_input_multitouch.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Input multitouch
  4. *
  5. * This example has been created using raylib 2.1 (www.raylib.com)
  6. * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
  7. *
  8. * Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
  9. *
  10. * Copyright (c) 2019 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. #define MAX_TOUCH_POINTS 10
  15. int main(void)
  16. {
  17. // Initialization
  18. //--------------------------------------------------------------------------------------
  19. const int screenWidth = 800;
  20. const int screenHeight = 450;
  21. InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch");
  22. Vector2 touchPositions[MAX_TOUCH_POINTS] = { 0 };
  23. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  24. //---------------------------------------------------------------------------------------
  25. // Main game loop
  26. while (!WindowShouldClose()) // Detect window close button or ESC key
  27. {
  28. // Update
  29. //----------------------------------------------------------------------------------
  30. // Get multiple touchpoints
  31. for (int i = 0; i < MAX_TOUCH_POINTS; ++i) touchPositions[i] = GetTouchPosition(i);
  32. //----------------------------------------------------------------------------------
  33. // Draw
  34. //----------------------------------------------------------------------------------
  35. BeginDrawing();
  36. ClearBackground(RAYWHITE);
  37. for (int i = 0; i < MAX_TOUCH_POINTS; ++i)
  38. {
  39. // Make sure point is not (0, 0) as this means there is no touch for it
  40. if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
  41. {
  42. // Draw circle and touch index number
  43. DrawCircleV(touchPositions[i], 34, ORANGE);
  44. DrawText(TextFormat("%d", i), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK);
  45. }
  46. }
  47. DrawText("touch the screen at multiple locations to get multiple balls", 10, 10, 20, DARKGRAY);
  48. EndDrawing();
  49. //----------------------------------------------------------------------------------
  50. }
  51. // De-Initialization
  52. //--------------------------------------------------------------------------------------
  53. CloseWindow(); // Close window and OpenGL context
  54. //--------------------------------------------------------------------------------------
  55. return 0;
  56. }