我正在用pygame库用Python编写一个spaceshooter程序,但屏幕上没有显示我编程要显示的任何内容。代码似乎没有问题。这是主文件
import sys
import pygame
import bullet
from settings import Setting
from ship import Ship
from pygame.sprite import Group
import functions as gf
def run_game():
pygame.init()
gmSet = Setting()
screen = pygame.display.set_mode((gmSet.screen_w, gmSet.screen_h))
pygame.display.set_caption("Alien Invasion")
bg_color = gmSet.bg_color
ship = Ship(screen)
bullets = Group()
while True:
gf.check_events(ship, gmSet, screen, bullets)
bullets.update()
for bullet in bullets.copy():
if bullet.rect.bottom <= 0:
bullets.remove(bullet)
print(len(bullets))
gf.update_screen(gmSet, screen, ship, bullets)
run_game()
下面是update_screen
函数
def update_screen(settings, screen, ship, bullets):
screen.fill(settings.bg_color)
for bullet in bullets.sprites():
bullet.draw_bullet()
ship.place()
Python在运行时没有给出任何错误,我可以说程序也没有陷入while循环如果我只提供了有限的信息,请告诉我
您需要更新显示。 您实际上是在^{} 对象上绘制的。如果在与PyGame显示屏关联的表面上绘制,则不会立即在显示屏上看到。当使用^{} 或^{} 更新显示时,更改将变为visibel
见^{} :
在
update_screen
函数中或在应用程序循环结束时调用pygame.display.flip()
:相关问题 更多 >
编程相关推荐