python - Failed to draw a row of rectangles (pygame) -


i'm trying draw simple row of rectangles, somewhow when execute code doesn't draw screen. can't figure out why. overlooking obvious, need point me it.

my code:

import pygame  # define colors black    = (   0,   0,   0) white    = ( 255, 255, 255) green    = (   0, 255,   0) red      = ( 255,   0,   0)  pygame.init()  # set width , height of screen [width,height] size = [255,255] screen = pygame.display.set_mode(size)  pygame.display.set_caption("my game") width = 20 height = 20 margin = 5 x = 0  #loop until user clicks close button. done = false  # used manage how fast screen updates clock = pygame.time.clock()  # -------- main program loop ----------- while done == false:     # event processing should go below comment     event in pygame.event.get(): # user did         if event.type == pygame.quit: # if user clicked close             done = true # flag done exit loop     # event processing should go above comment       # game logic should go below comment      # game logic should go above comment      # code draw should go below comment      # first, clear screen white. don't put other drawing commands     # above this, or erased command.     screen.fill(black)     column in range(10):         pygame.draw.rect(screen,white,[x,0,width, height])         x += width      # code draw should go above comment      # go ahead , update screen we've drawn.     pygame.display.flip()      # limit 20 frames per second     clock.tick(20)  # close window , quit. pygame.quit() 

i have looked around on stackoverflow , google, , found 1 solution: instead of range(10) put in range(1,100,10),and change x column. still not understand why code doesn't work, because seems alright me.

you never reset x 0 within loop, squares shunted off right side of screen.

screen.fill(black) x=0 column in range(10):     pygame.draw.rect(screen,white,[x,0,width, height])     x += width 

result:

enter image description here


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -