DarkRunner
DarkRunner

Reputation: 449

Pygame Font Unsupported?

For some reason,my code isnt working.I believe it is just because I specified the font as "None".The only reason why I did so was because it seemed no other font was supported! Not even arial or monospace. Here is the code(this is coded in Pygame):

import pygame
pygame.init()
white = (34,34,34)
black=(0,0,0)
red=(255,0,0)
led=45
pik=105
silver=(110,108,108)
yellow=(193,206,104)
yellow2=(213,230,100)
display_height=600
display_width=800
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Slither')

def text_objects(text, font):
    textSurface = font.render(text, True, black)

def message_display(text):
    largeText = pygame.font.Font(==>None<==,115)
    TextSurf, TextRect = text_objects(text , largeText)
    TextRect.center = (display_width/2),(display_height/2)
    gameDisplay(TextSurf, TextRect)

    time.sleep(2)

    game_loop()

gameExit=False

myfont = pygame.font.SysFont("monospace", 15)
lead_x = 300
lead_y = 300
ps=-43+300
background_color=black
while not gameExit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            gameExit = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                lead_x -= 10
                print("LEFT")

            if event.key == pygame.K_RIGHT:
                lead_x +=10
                print("RIGHT")
            if event.key == pygame.K_UP:
                 lead_y -=10
                 print("UP")
            if event.key == pygame.K_DOWN:
                 lead_y +=10
                 print("DOWN")
            if event.key == pygame.K_a:
                gameDisplay.fill(red)
                led +=10
                ps -=5
            if led == 95:
                background_color=red
                message_display('You found me')


    gameDisplay.fill(background_color)
    pygame.draw.ellipse(gameDisplay, black,[-295+300,-54+300,75,100])
    pygame.draw.ellipse(gameDisplay, red,[-285+300,-35+300,20,34])
    pygame.draw.ellipse(gameDisplay, red,[-255+300,-35+300,20,34])
    pygame.draw.circle(gameDisplay, yellow, (650, 300), 105, 45)
    pygame.draw.rect(gameDisplay, silver,[470+lead_x,-35+lead_y,75,30])
    pygame.draw.ellipse(gameDisplay, yellow,[375+lead_x,ps,105,led])


    pygame.display.update()

pygame.quit()
quit()

Upvotes: 0

Views: 157

Answers (1)

elegent
elegent

Reputation: 4007

The problem is that the function text_objects(text, font) returns nothing but you call

TextSurf, TextRect = text_objects(text , largeText)

So you need to change your text_objects() function for instance to

def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()

Hope this helps :)

Upvotes: 1

Related Questions