我试图调用 moveleft 方法但没有动作。我通过了角色的距离,这应该更新,但不是。有任何想法吗?
import pygame, sys
from pygame.locals import *
pygame.init()
pygame.font.init()
width,height=(842,595)
window = pygame.display.set_mode((width,height),0,32)
pygame.display.set_caption("game!")
speedX=3
movingX =0
clock= pygame.time.Clock()
man = pygame.image.load("man.png")
target= pygame.image.load("target.png")
x = 100
y = height-300
def name(name=""):
myfont = pygame.font.SysFont(None, 15)
label = myfont.render(name, 1, (255,255,0))
result=window.blit(label, (100, 100))
pygame.display.update()
return name
def moveleft(distanceX):
movingX =0
speedX =0
x=0
while True:
pygame.display.update()
ticks=clock.tick(25)
time_passedSeconds=ticks/1000.0
distanceX = time_passeSeconds*speedX
movingX+=distanceX
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
elif event.type==KEYDOWN:
if event.key ==K_LEFT:
x+=distanceX
window.blit(man, (x,y))
return movingX
name("werodo!")
moveleft(5)
pygame.display.update()