2
0

core_input_multitouch.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - Input multitouch
  4. *
  5. * Example originally created with raylib 2.1, last time updated with raylib 2.5
  6. *
  7. * Example contributed by Berni (@Berni8k) and reviewed by Ramon Santamaria (@raysan5)
  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) 2019-2022 Berni (@Berni8k) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include "raylib.h"
  16. #define MAX_TOUCH_POINTS 10
  17. //------------------------------------------------------------------------------------
  18. // Program main entry point
  19. //------------------------------------------------------------------------------------
  20. int main(void)
  21. {
  22. // Initialization
  23. //--------------------------------------------------------------------------------------
  24. const int screenWidth = 800;
  25. const int screenHeight = 450;
  26. InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch");
  27. Vector2 touchPositions[MAX_TOUCH_POINTS] = { 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. // Get multiple touchpoints
  36. for (int i = 0; i < MAX_TOUCH_POINTS; ++i) touchPositions[i] = GetTouchPosition(i);
  37. //----------------------------------------------------------------------------------
  38. // Draw
  39. //----------------------------------------------------------------------------------
  40. BeginDrawing();
  41. ClearBackground(RAYWHITE);
  42. for (int i = 0; i < MAX_TOUCH_POINTS; ++i)
  43. {
  44. // Make sure point is not (0, 0) as this means there is no touch for it
  45. if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
  46. {
  47. // Draw circle and touch index number
  48. DrawCircleV(touchPositions[i], 34, ORANGE);
  49. DrawText(TextFormat("%d", i), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK);
  50. }
  51. }
  52. DrawText("touch the screen at multiple locations to get multiple balls", 10, 10, 20, DARKGRAY);
  53. EndDrawing();
  54. //----------------------------------------------------------------------------------
  55. }
  56. // De-Initialization
  57. //--------------------------------------------------------------------------------------
  58. CloseWindow(); // Close window and OpenGL context
  59. //--------------------------------------------------------------------------------------
  60. return 0;
  61. }