2015-11-02 64 views
-1

我在pygame上使用2.7.10,我不明白爲什麼權利繼續下去,而不是正確的。左邊的作品很完美。我找不到任何有關的問題,所以有人知道這有什麼問題嗎?pygame,權利下降

import pygame 

pygame.init() 

GameDisplay = pygame.display.set_mode((800, 600)) 

White = (255,255,255) 
Black = (0,0,0) 
Red = (255,0,0) 

pygame.display.set_caption('Test') 

PyQuit = False 

lead_x = 300 
lead_y = 300 

while not PyQuit: 
    for event in pygame.event.get(): 
     if event.type == pygame.QUIT: 
      PyQuit = True 
     if event.type == pygame.KEYDOWN: 
      if event.key == pygame.K_LEFT: 
       lead_x -= 10 
      if event.key == pygame.K_RIGHT: 
       lead_y += 10 


    GameDisplay.fill(White) 
    pygame.draw.rect(GameDisplay, Black, [lead_x,lead_y,10,10]) 
    pygame.display.update() 

pygame.quit() 
quit() 

回答

2

相反的:

lead_y += 10 

嘗試:

lead_x += 10 

水平使用lead_x,垂直使用lead_y

+0

謝謝!現在我懂了! =] – Sabrina

1
if event.key == pygame.K_RIGHT: 
       lead_y += 10' 

正在製作的lead_y + = 10時,你應該將10 x座標

​​3210
+0

感謝您的幫助! – Sabrina