user3830347
user3830347

Reputation: 1

Moving image with pygame

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.

Upvotes: 0

Views: 12059

Answers (1)

Ashoka Lella
Ashoka Lella

Reputation: 6729

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()

Upvotes: 2

Related Questions