Why isn't text showing up in pygame

Why isn't text showing up in pygame

Postby merlinthecat » Sat Nov 09, 2013 4:28 pm

Ok, so this is the code:

Code: Select all
import pygame
from pygame import *
pygame.init()
#set the window size
window = pygame.display.set_mode((800,600) ,0,24)
pygame.display.set_caption("Game Title")
fillcolour=(255,255,255)
window.fill(fillcolour)
pygame.display.update()

#create strings for screen info
text1= "MOUSE DOWN POSITION"
text2= ""
mouse_x=0
mouse_y=0

#endless loop for main
running=True
while running:
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == MOUSEBUTTONDOWN:
            text1=str(pos)
        elif event.type == MOUSEMOTION:
            mouse_x = pos[0]
            mouse_y = pos[1]
            text2="mouse x position "+str(mouse_x)

    #convert text to graphics
    myfont = pygame.font.SysFont("Britannic Bold", 40)
    label1 = myfont.render(text1, 1, (255,0,0))
    myfont = pygame.font.SysFont("Britannic Bold", 30)
    label2 = myfont.render(text2, 1, (255,0,0))

    window.fill(fillcolour)
    window.blit(label1, (0, 20))
    window.blit(label2, (450, 550))
    pygame.display.update()

Ok, so this is meant to give feedback on the mouse motion and when it is clicked.
The window is meant to have a white background which it does, but that is where it stops doing what I want it to. The text that is meant to show feedback on the mouse does not show up on the screen. However if I take the following part of the code out of it, then run it, the text will show, however I need this part for it to work:

Code: Select all
#endless loop for main
running=True
while running:
    for event in pygame.event.get():
        pos = pygame.mouse.get_pos()
        if event.type == MOUSEBUTTONDOWN:
            text1=str(pos)
        elif event.type == MOUSEMOTION:
            mouse_x = pos[0]
            mouse_y = pos[1]
            text2="mouse x position "+str(mouse_x)

Any ideas guys? Is it something wrong with the above part of the code. I'm a newbie, so forgive me if it is something really stupid
:oops: :oops: :oops: :oops: :oops: :oops: :oops:
Last edited by Mekire on Wed Nov 13, 2013 11:42 pm, edited 1 time in total.
Reason: Added code tags as best I can. Please remember in the future.
merlinthecat
 
Posts: 4
Joined: Wed Nov 06, 2013 10:52 pm

Re: Why isn't text showing up in pygame

Postby DrakeMagi » Sat Nov 09, 2013 5:17 pm

1. PLEASE USE CODE TAGS !!!!!
Then more help will come .

2. Use some type of time control .
Code: Select all
clock = pygame.time.Clock()
# in main loop
    clock.tick(60)
DrakeMagi
 
Posts: 89
Joined: Sun May 12, 2013 8:36 pm


Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron