Pygame Tutorial number 7.Please PLEASE help.Can't procede.

+1 Usama tariq · November 7, 2015

import pygame

green = (0,255,0)
black = (0,0,0)
pygame.init()
GameDisplay=pygame.display.set_mode((800,600))
pygame.display.set_caption("Momo Killer")
x= False
lead_x = 300
lead_y = 300

while x is False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()


if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
lead_x -= 20
if event.key == pygame.K_RIGHT:
lead_x += 20

pygame.draw.rect(GameDisplay,green,[lead_x,lead_y,20,20])
pygame.display.update()

pygame.quit()
quit()


When I use this code.It makes another box without deleting the previous one.Please help me please please.

Post a Reply

Replies

Oldest  Newest  Rating
0 sfolje 0 · November 7, 2015
If you watched tutorial (retorical question), there is another line :
GameDisplay.fill(black) #in tutorial is white ;)

before line:
pygame.draw.rect(GameDisplay,green,[lead_x,lead_y,20,20])

Maybe that line "GameDisplay.fill(black)" seems useless because Display is already 'filled' with black but in fact it is so important that solves your problem ;-)  It fills whole display in black including the old box, and then next linecode draws the next box.
Now it works fine for me.
0 Usama tariq · November 7, 2015
it looks like this./images/forum/upload/2015-11-07/336f8f652ea79de947139f454ef423a0.png
  • 1

Python

107,234 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator