簡體   English   中英

由於某種原因在 pygame 我不能移動我的太空船

[英]for some reason in pygame i cant move my space ship

我只想讓它在沒有任何按鈕的情況下移動,它什么都不做。

import pygame

def player(x, y):
        screen.blit(playerImg, (x, y))

        
pygame.init()
screen = pygame.display.set_mode((800, 600))
playerImg = pygame.image.load("spaceship.png")

playerX = 350
playerY = 500
playerX_change = 0
playerX -= 2

running = True;
while running:
 
    for event in pygame.event.get():
         if event.type == pygame.QUIT:
                running = False

                screen.fill((255, 0, 0))
                player(playerX, playerY)
                
                playerX -= 1
                pygame.display.update()

看看你的縮進:只有當你准備好退出游戲時才會更新。 除非隊列中有event ,否則您不能移動。 修復它,使更改進入正常的移動循環:

while running:

    screen.fill((255, 0, 0))
    player(playerX, playerY)
    
    playerX -= 1
    pygame.display.update()

您必須以其他方式處理您的事件隊列; 有關如何在響應事件時異步移動,請參閱相應的教程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM