저는 작업중인 작은 프로젝트의 제목을 렌더링하려고합니다. 옵션 세트를 생성하는 데 사용 된 것과 동일한 코드를 복제했지만 아직 작동하지 않습니다. 누군가 내가 잘못 가고 있는지 알고 있는지 궁금 해서요? 아마 뭔가 분명 할 것 같지만 파이썬에 대해서는 경험이 없습니다. 난 당신이 어떻게 할 정확히 모르는Python/Pygame 제목 렌더링
import pygame
class Option:
hovered = False
def __init__(self, text, pos):
self.text = text
self.pos = pos
self.set_rect()
self.draw()
def draw(self):
self.set_rend()
screen.blit(self.rend, self.rect)
def set_rend(self):
self.rend = menu_font.render(self.text, True, self.get_color())
def get_color(self):
if self.hovered:
return (255, 255, 255)
else:
return (100, 100, 100)
def set_rect(self):
self.set_rend()
self.rect = self.rend.get_rect()
self.rect.topleft = self.pos
class Title:
hovered = False
def __init__(self, text, pos):
self.text = text
self.pos = pos
self.set_rect()
self.draw()
def draw(self):
self.set_rend()
screen.blit(self.rend, self.rect)
def set_rend(self):
self.rend = title_font.render(self.text, True, self.get_color())
def get_color(self):
if self.hovered:
return (255, 255, 255)
else:
return (255, 255, 255)
def set_rect(self):
self.set_rend()
self.rect = self.rend.get_rect()
self.rect.topleft = self.pos
pygame.init()
screen = pygame.display.set_mode((480, 320))
menu_font = pygame.font.Font(None, 40)
options = [Option("PLAY GAME", (140, 105)), Option("OPTIONS", (155, 155)),
Option("QUIT", (180, 205)), Option("NOTPONG", (150,20))]
title_font = pygame.display.font.Font(None, 42)
title = [Title("NOTPONG", (150,20))
while True:
pygame.event.pump()
screen.fill((0, 0, 0))
for option in options:
if option.rect.collidepoint(pygame.mouse.get_pos()):
option.hovered = True
else:
option.hovered = False
option.draw()
pygame.display.update()
while True:
pygame.event.pump()
screen.fill((0, 0, 0))
for Title in title:
if title.rect.collidepoint(pygame.mouse.get_pos()):
title.hovered = True
else:
title.hovered = False
title.draw()
pygame.display.update()
감사합니다. –