【发布时间】:2020-01-15 22:06:27
【问题描述】:
我正在使用 PyGame 在 Python 3.7 中制作我自己的“游戏引擎”。我想创建一个使用pygame.rect() 函数的类,但是当我运行它时,它每次都会给我这个错误或类似的错误。
main.py (./pyseed/)
# Imports
import pygame
pygame.init()
# class
class Shape:
def __init__(self, width, height, color):
self.width = width
self.height = height
self.color = color
self.SHAPE = pygame.rect(self, width, height, color)
# RunApp() function
def runApp(width, height):
screen = pygame.display.set_mode((width, height))
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
testing.py(import main 将更改为 import pyseed.main)
# PySeed Testing Zone
import main as pyseed
myShape = pyseed.Shape(90, 90, (0, 100, 255))
pyseed.runApp(400, 300)
感谢您的帮助。
【问题讨论】:
-
为什么你认为
pygame.rect是一个函数? -
我想你的意思是
pygame.Rect()(注意'R'不是'r'),这是一个class初始化器调用,所以不是真正的函数调用,但出于所有意图和目的,它是. -
@Kingsley,我对程序做了一些更改,我发现我必须使用 'pygame.draw.rect()'。感谢您的帮助!
标签: python pygame python-3.7