Code: Alles auswählen
"C:\Spiele und Programme\Python\python.exe" "C:/Users/N4SONIC/Desktop/Python Projekte/Game/main.py"
Traceback (most recent call last):
File "C:/Users/N4SONIC/Desktop/Python Projekte/Game/main.py", line 61, in <module>
text_health.render(window)
File "C:/Users/N4SONIC/Desktop/Python Projekte/Game/main.py", line 43, in render
str = font.render(self.text.format, (player.health), True, self.color)
TypeError: Invalid foreground RGBA argument
Process finished with exit code 1
Code: Alles auswählen
import pygame
pygame.init()
window = pygame.display.set_mode((800,600))
pygame.display.set_caption("window")
black = (0,0,0)
white = (255,255,255)
blue = (50,60,200)
green = (40,255,40)
yellow = (255,255,85)
red = (255,85,85)
orange = (255,170,0)
FPS = 60
clock=pygame.time.Clock()
class Player:
def __init__(self, health, color, x, y, width, height):
self.health = health
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
def render(self, window):
pygame.draw.rect(window, (self.color), (self.x, self.y, self.width, self.height))
font = pygame.font.SysFont("arial", 20)
class Text_Health:
def __init__(self, text, color, x, y):
self.text = text
self.color = color
self.x = x
self.y = y
def render(self, window):
str = font.render(self.text.format, (player.health), True, self.color)
window.blit(str, (self.x, self.y))
player = Player(100, black, 400, 300, 50, 50)
text_health = Text_Health("Leben {0}", red, 5, 5)
gameLoop=True
while gameLoop:
for event in pygame.event.get():
if (event.type==pygame.QUIT):
gameLoop=False
window.fill(blue)
player.render(window)
text_health.render(window)
clock.tick(FPS)
pygame.display.flip()
pygame.quit()