core_input_multitouch.c 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. //------------------------------------------------------------------------------------
  16. // Program main entry point
  17. //------------------------------------------------------------------------------------
  18. int main(void)
  19. {
  20. // Initialization
  21. //--------------------------------------------------------------------------------------
  22. const int screenWidth = 800;
  23. const int screenHeight = 450;
  24. InitWindow(screenWidth, screenHeight, "raylib [core] example - input multitouch");
  25. Vector2 touchPositions[MAX_TOUCH_POINTS] = { 0 };
  26. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  27. //---------------------------------------------------------------------------------------
  28. // Main game loop
  29. while (!WindowShouldClose()) // Detect window close button or ESC key
  30. {
  31. // Update
  32. //----------------------------------------------------------------------------------
  33. // Get multiple touchpoints
  34. for (int i = 0; i < MAX_TOUCH_POINTS; ++i) touchPositions[i] = GetTouchPosition(i);
  35. //----------------------------------------------------------------------------------
  36. // Draw
  37. //----------------------------------------------------------------------------------
  38. BeginDrawing();
  39. ClearBackground(RAYWHITE);
  40. for (int i = 0; i < MAX_TOUCH_POINTS; ++i)
  41. {
  42. // Make sure point is not (0, 0) as this means there is no touch for it
  43. if ((touchPositions[i].x > 0) && (touchPositions[i].y > 0))
  44. {
  45. // Draw circle and touch index number
  46. DrawCircleV(touchPositions[i], 34, ORANGE);
  47. DrawText(TextFormat("%d", i), (int)touchPositions[i].x - 10, (int)touchPositions[i].y - 70, 40, BLACK);
  48. }
  49. }
  50. DrawText("touch the screen at multiple locations to get multiple balls", 10, 10, 20, DARKGRAY);
  51. EndDrawing();
  52. //----------------------------------------------------------------------------------
  53. }
  54. // De-Initialization
  55. //--------------------------------------------------------------------------------------
  56. CloseWindow(); // Close window and OpenGL context
  57. //--------------------------------------------------------------------------------------
  58. return 0;
  59. }