0

I am new to pygame. I was just trying to move an image with pygame but it fails my code is

import pygame
from pygame.locals import*
img = pygame.image.load('tank.jpg')

white = (255, 64, 64)

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

screen.fill((white))

running = 1

while running:

  x = 5
  x++
  y  = 10
  y++

  screen.fill((white))
  screen.blit(img,(x,y))
  pygame.display.flip()
  pygame.update()

I have tried this code to move the image. But it didn't help me.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
user3830347
  • 1
  • 1
  • 1
  • 4

1 Answers1

2

1)your overwriting x and y in every iteration of while loop

2) you can't do x++ in python, use x+=1 instead

3) pygame.update() --> I think you meant pygame.display.update()

Try using this:

running = 1                     
x= 5                            
y = 5                           
while running:                  
    x +=1                       
    y +=1                       
    screen.fill((white))        
    screen.blit(img,(x,y))      
    pygame.display.flip()       
    pygame.display.update()
Ashoka Lella
  • 6,631
  • 1
  • 30
  • 39