[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Keyboard events problem in Mac OS X 10.6 Snow Leopard



Not really. In fact, it works fine on my 10.6.2 MacBook Pro.

A difference would be that I use ActivePython rather that MacPorts Python.

Does the screen appear on your machine? The red box just doesn't move?


On 4/3/10 8:54 AM, Mathieu Richardoz wrote:
Hi Dan,

Thank you for your reply :-)

Here's the code:

---

import pygame
pygame.init()

screen = pygame.display.set_mode((640, 480))

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 255))

box = pygame.Surface((25, 25))
box = box.convert()
box.fill((255, 0, 0))

box_x = 200
box_y = 200

clock = pygame.time.Clock()
playing = True

while playing:

     clock.tick(30)

     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             playing = False

     keys = pygame.key.get_pressed()
     if keys[pygame.K_UP]:
         box_y -= 5
     if keys[pygame.K_DOWN]:
         box_y += 5
     if keys[pygame.K_LEFT]:
         box_x -= 5
     if keys[pygame.K_RIGHT]:
         box_x += 5

     screen.blit(background, (0, 0))
     screen.blit(box, (box_x, box_y))
     pygame.display.flip()

---

Do you see anything I might have done wrong?

Math