"argument 1 must be pygame.Surface, not pygame.Rect" 我该如何解决这个问题,它在说什么?
"argument 1 must be pygame.Surface, not pygame.Rect" How do I fix this, what is it saying?
我正在尝试制作一款类似于 cookie clicker 的游戏,但使用的是铅笔。使用 pygame.
class pencilsDisplay():
def __init__(self, x, y):
self.x = x
self.y = y
self.height = 100
self.length = 100
def draw(self):
font = pygame.font.Font('font/Gidole-Regular.ttf', 24)
small_font = pygame.font.Font('font/Gidole-Regular.ttf', 24)
PENCILS = font.render('{} Pencils'.format( int(user.pencils) ), True, WHITE)
PENCILSPERSECOND = font.render('Per Second: {}'.format( int(user.pencils) ), True, WHITE)
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
screen.blit(PENCILSPERSECOND.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
pencil = MainPencil(100,100)
pencil_display = pencilsDisplay(100,0)
class Player:
def __init__(self):
self.pencils = 0
self.pencilspersecond = 0
user = Player()
def draw():
pencil.draw()
pencil_display.draw()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos
if pencil.collidepoint(mouse_pos):
user.score += 1
pencil.animation_state = 1
if event.type == pygame.QUIT:
running = False
draw()
我在上面有加载 window 的代码,但这是错误所指的区域。
window 中没有显示任何内容,我明白了。
File "main.py", line 82, in <module>
draw()
File "main.py", line 67, in draw
pencil_display.draw()
File "main.py", line 52, in draw
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
TypeError: argument 1 must be pygame.Surface, not pygame.Rect
exit status 1
我做错了什么?
我对 pygame 还很陌生,所以如果有任何解释,我将不胜感激。
pygame.Surface.blit
的第一个参数是来源 Surface:
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
screen.blit(PENCILS, PENCILS.get_rect(center = (int(self.x + self.length/2), int(self.y + self.height/2))))
我正在尝试制作一款类似于 cookie clicker 的游戏,但使用的是铅笔。使用 pygame.
class pencilsDisplay():
def __init__(self, x, y):
self.x = x
self.y = y
self.height = 100
self.length = 100
def draw(self):
font = pygame.font.Font('font/Gidole-Regular.ttf', 24)
small_font = pygame.font.Font('font/Gidole-Regular.ttf', 24)
PENCILS = font.render('{} Pencils'.format( int(user.pencils) ), True, WHITE)
PENCILSPERSECOND = font.render('Per Second: {}'.format( int(user.pencils) ), True, WHITE)
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
screen.blit(PENCILSPERSECOND.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
pencil = MainPencil(100,100)
pencil_display = pencilsDisplay(100,0)
class Player:
def __init__(self):
self.pencils = 0
self.pencilspersecond = 0
user = Player()
def draw():
pencil.draw()
pencil_display.draw()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
mouse_pos = event.pos
if pencil.collidepoint(mouse_pos):
user.score += 1
pencil.animation_state = 1
if event.type == pygame.QUIT:
running = False
draw()
我在上面有加载 window 的代码,但这是错误所指的区域。 window 中没有显示任何内容,我明白了。
File "main.py", line 82, in <module>
draw()
File "main.py", line 67, in draw
pencil_display.draw()
File "main.py", line 52, in draw
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
TypeError: argument 1 must be pygame.Surface, not pygame.Rect
exit status 1
我做错了什么? 我对 pygame 还很陌生,所以如果有任何解释,我将不胜感激。
pygame.Surface.blit
的第一个参数是来源 Surface:
screen.blit(PENCILS.get_rect( center=( int(self.x + self.length/2),int(self.y + self.height/2) )))
screen.blit(PENCILS, PENCILS.get_rect(center = (int(self.x + self.length/2), int(self.y + self.height/2))))