因此,在此类中的绘制方法中,由于某种原因,我遇到了位置参数错误。
File "/Users/wallera/PycharmProjects/MAJORPROJECT2/maintest.py", line 21, in <module>
game.run()
File "/Users/wallera/PycharmProjects/MAJORPROJECT2/src/game.py", line 21, in run
self.draw()
File "/Users/wallera/PycharmProjects/MAJORPROJECT2/src/game.py", line 35, in draw
self.world.draw(self.screen)
TypeError: World.draw() missing 1 required positional argument: 'screen'
问题是... world.draw() 确实有参数“screen”。这是我提供的最后一个方法。
import pygame as pg
from src.map import World
class Game:
def __init__(self, screen: pg.Surface, clock: pg.time.Clock, window_size: pg.Vector2):
self.screen = screen
self.clock = clock
self.window_size = window_size
self.playing = True
self.world = World
def run(self):
while self.playing:
self.clock.tick(60)
self.screen.fill((0, 0, 0))
self.events()
self.update()
self.draw()
pg.display.update()
def events(self):
for event in pg.event.get():
if event.type == pg.QUIT:
self.playing = False
if event.type == pg.KEYDOWN:
if event.key == pg.K_ESCAPE:
self.playing = False
def update(self):
pass
def draw(self):
self.world.draw(self.screen)
我不确定出了什么问题,我没想到会出现这种情况,而且我不知道是什么导致了这个问题。
在初始化你的类时,你应该使用类 World 的对象而不是类。所以代替:
self.world = World
您应该使用:
self.world = World()