Advertisement
cookertron

Un Nu Python Pygame Multi-touch

Feb 10th, 2022
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1.  
  2. import pygame
  3. from pygame import Vector2, Rect
  4. from pygame.locals import *
  5.  
  6. class control:
  7.     def __init__(s, px, py):
  8.         global PDR
  9.         pos = Vector2(px * PDR.w, py * PDR.h)
  10.         s.r = Rect(pos - (100, 100), (200, 200))
  11.  
  12. pygame.init()
  13. PDS = pygame.display.set_mode()
  14. PDR = PDS.get_rect()
  15.  
  16. BLACK = (0, 0, 0)
  17. WHITE = (255, 255, 255)
  18.  
  19. controls = {}
  20.  
  21. while True:
  22.     events = pygame.event.get()
  23.     for e in events:
  24.         if e.type == FINGERDOWN:
  25.             controls[e.finger_id] = control(e.x, e.y)
  26.         if e.type == FINGERUP:
  27.             del controls[e.finger_id]
  28.    
  29.     PDS.fill(BLACK)
  30.     for fid, c in controls.items():
  31.         pygame.draw.rect(PDS, WHITE, c.r)
  32.     pygame.display.update()
  33.     pygame.time.Clock().tick(60)
  34.    
  35.            
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement