Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Basic Text Class
#1
Hi there, I am working on creating a simple text class where you could create a text object, define the text, text size, location, colour (and eventually duration on scree).

I'm obviously having a brain fart here. My message isn't rendering. I've no errors. But the message doesn't display. Can anyone see what obviously silly mistake I've made? This is driving me bonkers!!

#GrumpyOgre
#Text Class

import pygame, sys
from pygame.locals import *

# set up the window and environment
pygame.init()
iFPS = 160 # frames per second setting
fpsClock = pygame.time.Clock()
frmWindow = pygame.display.set_mode((600, 600), 0, 32)
pygame.display.set_caption('Text Demo')

# pen inks
clrBlack = (0, 0, 0)
clrRed = (255, 0, 0)
clrGreen = (0, 255, 0)
clrBlue = (0, 0, 255)
clrWhite = (255, 255, 255)

class text:
	def __init__(self):
		self.x = 0
		self.y = 0
		self.colour = clrBlack
		self.size = 12
		self.duration = 10
		self.text = ""
		self.font = pygame.font.Font('comic.ttf', self.size)
		self.surface = self.font.render(self.text , 1, self.colour)
	
	def define(self, x, y, colour, size, duration, message):
		self.x = x
		self.y = y
		self.colour = colour
		self.size = size
		self.duration = duration
		self.text = message
	
	def display(self):
		frmWindow.blit( self.surface, (self.x,self.y))

message = text()
message.define(200, 200, clrBlack, 12, 20, 'boom')
frmWindow.fill(clrWhite)		 
while True: # the main game loop
	for event in pygame.event.get():
		if event.type == QUIT:
			pygame.quit()
			sys.exit()
	
	message.display()
	pygame.display.update()
	fpsClock.tick(iFPS)
Thx for any tips in advance.
Reply


Messages In This Thread
Basic Text Class - by GrumpyOgre - May-22-2018, 10:45 PM
RE: Basic Text Class - by metulburr - May-23-2018, 12:31 PM
RE: Basic Text Class - by GrumpyOgre - May-23-2018, 05:11 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020