sâmbătă, 1 octombrie 2011

pygame - test mouse class - update

Today I will show how to test mouse with pygame. This is very simple , just you try to use MOUSEBUTTONDOWN. Also , the click mouse only registers once so you can use it with another event. If you don't want to use an event handler, you can check for input with:
I created a class called Game, which contains four functions. A function that needs to pay attention is mainLoop. This function deals with events in the following order. While there is no event QUIT then read events. If there is event QUIT or MOUSEBUTTONDOWN then is running this: Event QUIT the program is quit. Event MOUSEBUTTONDOWN print mouse events , next is use update function with print "update function". Press mouse buttons: left,right,mouse wheel ,spinning mouse wheel.
(1, 0, 0)
update function
(0, 0, 1)
update function
(0, 1, 0)
update function
(0, 0, 0)
update function
The code is show bellow.
import pygame
from pygame.locals import *

screen_mode = (640, 480)
color_black = 0, 0, 0

class Game:
 def __init__(self):
  self.screen = pygame.display.set_mode(screen_mode)
  pygame.display.set_caption("Pygame first window")
  self.quit = False
 def update(self):
  print "update function"
 def draw(self):
 def mainLoop(self):
  while not self.quit:
   for event in pygame.event.get():
    if event.type == pygame.QUIT:
     self.quit = True
    elif  event.type  == pygame.MOUSEBUTTONDOWN:
     print pygame.mouse.get_pressed()
if __name__ == '__main__':
 game = Game()

Niciun comentariu:

Trimiteți un comentariu