我已经编写了我的代码,每当我运行它时,我都希望它打开背景屏幕,但实际上什么都没有发生。我不知道我哪里做错了,也不知道我做错了什么
我的代码:
import os.path
import sys
import pygame
from settings import Settings
class Slingshot_Adventures:
def __init__(self):
"""Initialize the game, and create game resources."""
pygame.init()
self.screen = pygame.display.set_mode((1280, 720))
pygame.display.set_caption('Slingshot Adventures')
self.bg_color = (0, 0, 0)
bg = pygame.image.load_basic(os.path.join('Final/bg.bmp'))
def run_game(self):
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Redraw the screen during each pass through the loop.
self.screen.fill(self.bg_color)
# Make the most recently drawn screen visible.
pygame.display.flip()
if __name__ == '__main__':
# Make a game instance, and run the game.
ai = Slingshot_Adventures()
ai.run_game
您已在类
Slingshot_Adventures
的构造函数中设置了局部变量bg
,但未设置属性self.bg
:bg = pygame.image.load_basic(os.path.join('Final/bg.bmp'))
相关问题 更多 >
编程相关推荐