On Sun, Sep 19, 2010 at 5:08 AM, kevin hayes <kevinosky@xxxxxxxxx> wrote:
Hi, I'm just beginning to learn python and pygame. I've gone through the first four chapters of "Game Programming, The L-line, the Express Line to Learning. Right now I'm working on an exercise that asks me to "make a box that moves in a diagonal path. Can someone tell me why when I run the code the program only executes while I move the mouse? Also, can you tell me how i can change my code to avoid this? Thanks, Kevinhere is my code:import pygamepygame.init()screen = pygame.display.set_mode((640, 480))pygame.display.set_caption("Diagonal Red Square")background = "">background = "">background.fill((0, 0, 0))box = pygame.Surface((20, 20))box = box.convert()box.fill((255, 0, 0))box_x = 0 #box variable for the x-axisbox_y = 0 #" " y-axisclock = pygame.time.Clock()keepGoing = Truewhile keepGoing:clock.tick(30)for event in pygame.event.get():if event.type == pygame.QUIT:keepGoing = Falsebox_x += 5box_y += 5if box_y > screen.get_height(): #checking for screen boundariesbox_y = 0if box_x > screen.get_width():box_x = 0screen.blit(background, (0, 0))screen.blit(box, (box_x, box_y))pygame.display.flip()pygame.quit()You change the box position only if an event is present, so you need to move the mouse or press keys to move.Move out of the event loop the lines that change the position, that is, dedent one level the lines:box_x += ...box_y += ...--claudio
- References:
- [pygame] moving a box diagnally
- From: kevin hayes
- Re: [pygame] moving a box diagnally
- From: claudio canepa
- Prev by Author: [pygame] moving a box diagnally
- Next by Author: [pygame] program crashes
- Previous by thread: Re: [pygame] moving a box diagnally
- Next by thread: [pygame] Opinions on the status of GUI libraries
- Index(es):