用pygame移动图像

时间:2014-07-12 04:51:09

标签: python pygame pygame-surface

我是pygame的新手。我只是试图用pygame移动图像,但是我的代码失败了

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

我试过这段代码来移动图片。但它对我没有帮助。

1 个答案:

答案 0 :(得分:1)

1)在while循环的每次迭代中覆盖xy

2)你不能在python中x++使用x+=1代替

3)pygame.update() - >我认为你的意思是pygame.display.update()

尝试使用:

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()
相关问题