显示文本参数解释

2024-04-24 19:56:15 发布

您现在位置:Python中文网/ 问答频道 /正文

def texts(score):
  font=pygame.font.Font(None,30)
  scoretext=font.render("Score:"+str(score), 1,(255,255,255))
  screen.blit(scoretext, (500, 457))

font.render中的第二个参数(1)是用来做什么的?你知道吗

class safeguardClass(pygame.sprite.Sprite):
    def __init__(self,image_file, location = [0,0]):
       pygame.sprite.Sprite.__init__(self) #call Sprite initializer
       self.image = pygame.image.load(image_file)
       self.rect = self.image.get_rect()
       self.rect.left, self.rect.top = location

此外,请指导我什么是self在上述子类?你知道吗


Tags: rectimageselfinitdeflocationrenderpygame
2条回答

如果您查找pygame.font.Font.renderdocumentation,它会显示:

render(text, antialias, color, background=None) -> Surface

This creates a new Surface with the specified text rendered on it. Pygame provides no way to directly draw text on an existing Surface: instead you must use Font.render() to create an image (Surface) of the text, then blit this image onto another Surface.

(...)

The antialias argument is a boolean: if true the characters will have smooth edges.

此外,self是对在^{} function中构造的对象的引用。你知道吗

第二个参数是抗锯齿,根据PyGame documentation.

相关问题 更多 >