Saturday, March 30, 2013

Lesson #4: Mouse and Touchscreen Control (taught by middle school student)

Middle school student, age 13, teaches you how to get mouse control working on the moving square.
  • Goes through event queue to check for the mouse button. event.type == MOUSEBUTTONDOWN:
  • Checks for point collision with a rectangle: collidepoint(mouse_pos)


  1. In terms of the response of a touch screen device, how does the device distinguish between a touch and a swipe? So far it looks to me like simply touching the screen to start a swipe is interpreted as a buttondown event. This behavior doesn't seem compatible with a game where you want to direct, say, the path of a projectile with swiping and the launch of the projectile with a touch of a soft button put on the screen by the app while the user is still swiping.

  2. Pygame can't do a swipe. Create a virtual controller.

    1. If you really need a swipe, and you game may not, you'll need to use Kivy. However, that's more complex, both for adults, and kids. Suggest you keep to Pygame.