![](/img/trans.png)
[英]Python / Pygame - How to blit different transparencies onto an invisible surface
[英]Not sure how to blit font with a variable onto a surface, pygame
试图在屏幕上 blit 一个带有变量的字体 - 你已经达到的分数 - 在死后出现在屏幕上。
BLACK = (0, 0, 0)
font_small = pygame.font.SysFont("Verdana", 20)
scoreMsg = "Your score: {0}".format(SCORE)
show_score = font_small.render(scoreMsg, True, BLACK)
稍后我这样调用 show_score 变量:
screen.blit(show_score, (30, 400))
这是完整的代码: https://pastebin.com/5RnShSCG
编辑:我忘了说。 文本“你的分数:”出现在屏幕上,但变量始终为 0,即使分数更高。
SCORE
与show_score
表面无关。 当您更改SCORE
时, show_score
表面不会神奇地改变。 您必须重新渲染show_score
表面:
class Enemy(pygame.sprite.Sprite):
# [...]
def move(self):
global SCORE, show_score
self.rect.move_ip(0,SPEED)
if (self.rect.top > 600):
self.rect.top = 0
SCORE+=1
show_score = font_small.render("Your score: {0}".format(SCORE), True, BLACK)
self.rect.center = (random.randint(30, 370), 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.