python3 pygame load图片不显示_Python Pygame无法正确显示图像

我是Python的新手,我从Eric Matthes的” Python崩溃课程”开始学习.我正处于Pygame一章的开头,并且遵循代码,但是我加载的图像总是看起来损坏,我也不知道为什么.代码来自本书.第一个文件:

import pygame

class Ship():

def init(self, screen):

“””Initialize the ship and set its starting position.”””

Load the ship image and get its rect.

self.image = pygame.image.load(‘ship.bmp’)

self.screen = screen

self.rect = self.image.get_rect()

self.screen_rect = screen.get_rect()

Start each new ship at the bottom center of the screen.

self.rect.centerx = self.screen_rect.centerx

self.rect.bottom = self.screen_rect.bottom

def blitme(self):

self.screen.blit(self.image, self.rect)

第二档:

import sys

import pygame

from settings import Settings

from ship import Ship

def run_game():

Initialize game and create a screen object.

pygame.init()

ai_settings = Settings()

screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))

pygame.display.set_caption(“Alien Invasion”)

ship = Ship(screen)

bg_color = (230, 230, 230)

Start the main loop for the game.

while True:

Watch for keyboard and mouse events.

for event in pygame.event.get():

if event.type == pygame.QUIT:

sys.exit()

Make the most recently drawn screen visible.

screen.fill(ai_settings.bg_color)

ship.blitme()

pygame.display.flip()

run_game()

设置文件:

class Settings():

“””A class to store all settings for Alien Invasion.”””

def init(self):

“””Initialize the game’s settings.”””

Screen settings

self.screen_width = 800

self.screen_height = 600

self.bg_color = (230, 230, 230)

我的bmp看起来像这样:

python3 pygame load图片不显示_Python Pygame无法正确显示图像

我尝试添加其他图像,但没有运气:

python3 pygame load图片不显示_Python Pygame无法正确显示图像

我该如何解决?

Original: https://blog.csdn.net/weixin_39655993/article/details/113645760
Author: weixin_39655993
Title: python3 pygame load图片不显示_Python Pygame无法正确显示图像

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/783142/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球