Jump to content
  • Advertisement
Sign in to follow this  
biztor

newbie problem with pygame, moving rectangle

This topic is 2085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this:

 

 

 
pygame.init()
screen=pygame.display.set_mode((500,500))
pygame.display.set_caption("test")
clock1=pygame.time.Clock()
 
colour1=(100,100,100)
colour2=(200,200,200)
colour3=(253,213,90)
 
sur=pygame.Surface((200,200))
 
rec=pygame.Rect(300,200,100,100)
 
 
sur.fill(colour2)
 
 
 
while True:
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
        if event.type==pygame.KEYDOWN:
            if pygame.event == pygame.K_LEFT:
                rec.move(-100,0)
            if pygame.event == pygame.K_RIGHT:
                rec.move(100,0)
 
 
 
 
    clock1.tick(20)
    screen.fill(colour1)
    screen.blit(sur,(100,100))
    pygame.draw.rect(screen,colour3,rec)
 
    pygame.display.update()
 
 
 
but the rectangles doesnt move. why?
thank you

Share this post


Link to post
Share on other sites
Advertisement
Don't know anything about pygame but after looking the internet I think in the
for event in pygame.event.get()
loop you should do
if event.key == pygame.K_LEFT
instead of
if pygame.event == pygame.K_LEFT

and the same for the other key (K_RIGHT).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!