我正在努力更新被闪电击中的分数,但它没有改变

  • 本文关键字:改变 努力 更新 python pygame
  • 更新时间 :
  • 英文 :

class Score:
def __init__(self):
self.Colour = (230, 230, 230)
self.x = 25
self.y = 0
self.Shape = pygame.Rect((self.x, self.y), (200, 100))
self.Team1Score = 0
self.Team2Score = 0
self.Title = f"{self.Team1Score}  -  {self.Team2Score}"
self.text_type = pygame.font.SysFont('arialunicode', 40).render(self.Title, True, (0, 0, 0))
self.text_rect = self.text_type.get_rect(center=self.Shape.center)
self.Score = False
def DrawScore(self, window):
pygame.draw.rect(window, self.Colour, self.Shape)
window.blit(self.text_type, self.text_rect)
def AddScore(self, score, p1, window):
self.Score = score
if p1.Shooting:
if self.Score:
if p1.Colour == (255, 0, 0):
self.Team1Score += 1
self.text_type = pygame.font.SysFont('arialunicode', 40).render(self.Title, True, (0, 0, 0))
window.blit(self.text_type, self.text_rect)
else:
self.Team2Score += 1
self.text_type = pygame.font.SysFont('arialunicode', 40).render(self.Title, True, (0, 0, 0))

我正在尝试更新游戏中的分数,但由于某种原因,变量没有改变。如何更新变量,以便在屏幕上更新文本。我需要为文本创建更新功能吗?

更改Team1ScoreTeam2Score后,必须重新创建

self.Title = f"{self.Team1Score}  -  {self.Team2Score}"

获取新字符串


if p1.Colour == (255, 0, 0):
self.Team1Score += 1
else:
self.Team2Score += 1
self.Title = f"{self.Team1Score}  -  {self.Team2Score}"
self.text_type = pygame.font.SysFont('arialunicode', 40).render(self.Title, True, (0, 0, 0))
#window.blit(self.text_type, self.text_rect)

最新更新