您好,即使您可能认为存在类似的问题,但我的情况与此完全不同.
我正在尝试从目录加载图像,并将我的屏幕大小(自动)设置为正在加载的图像的大小为"背景".
import pygame
import sys
from pygame.locals import *
image_resources = "C:/Users/user/Desktop/Pygame App/image_resources/"
class load:
def image(self, image):
self.image = image
return (image_resources + image)
def texture(self, texture):
self.texture = texture
return (image_resources + texture)
bg = load().image("bg_solid_black.jpg")
pygame.init()
#screen = pygame.display.set_mode((width,height),0,32)
#background = pygame.image.load(bg).convert()
#width = background.get_width()
#height = background.get_height()
Run Code Online (Sandbox Code Playgroud)
我用"load()"类加载的图像被设置为变量"bg",我想使用我加载的任何大小为"bg"来确定窗口的大小.如果你试图移动
background = pygame.image.load(bg).convert()
width = background.get_width()
height = background.get_height()
Run Code Online (Sandbox Code Playgroud)
除此之外:
screen = pygame.display.set_mode((width,height),0,32)
Run Code Online (Sandbox Code Playgroud)
PyGame返回一个错误,其中指出未设置显示模式.如果我这样做:
screen = pygame.display.set_mode((width,height),0,32)
background = pygame.image.load(bg).convert()
width = background.get_width()
height = …Run Code Online (Sandbox Code Playgroud)