From 1be5df38b646a494530014cd9a1dfe66dffe0393 Mon Sep 17 00:00:00 2001 From: davesilver Date: Wed, 28 Jul 2010 17:05:00 +0000 Subject: Testing Drawable Font Objects --- (limited to 'devtools/CompleteTestKit') diff --git a/devtools/CompleteTestKit/DrawableFontObject.py b/devtools/CompleteTestKit/DrawableFontObject.py new file mode 100644 index 0000000..dbd5d65 --- /dev/null +++ b/devtools/CompleteTestKit/DrawableFontObject.py @@ -0,0 +1,14 @@ +import pygame +from DrawableObject import DrawableObject + +class DrawableFontObject(DrawableObject, pygame.sprite.Sprite): + + def __init__(self,text,font,fps = 10, x = 0, y = 0, xVelocity = 0, yVelocity = 0): + + self.font = font + self.textImage = font.render(text, True, (0,0,0)) + DrawableObject.__init__(self, [self.textImage], '', fps, x, y, xVelocity, yVelocity) + + def changeText(self, newtext): + + self._images[0] = font.render(newText, True, (0,0,0)) diff --git a/devtools/CompleteTestKit/FontDirtyTest.py b/devtools/CompleteTestKit/FontDirtyTest.py new file mode 100644 index 0000000..6d17908 --- /dev/null +++ b/devtools/CompleteTestKit/FontDirtyTest.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python +import pygame +from pygame.locals import * +from boxes import BouncingBox +from time import time +from Scene import Scene +from DrawableObject import DrawableObject +from DynamicDrawableObject import DynamicDrawableObject +pygame.init() + +FRAME=500 +screenWidth = 600 +screenHeight = 400 +numImages = 1 +maxTrial = 5 # multiple trials, but hard coded in this test +dirtyList=[] + +print "width,height", +print screenWidth, +print ",", +print screenHeight + +screen = pygame.display.set_mode( [int(screenWidth), + int(screenHeight)] ) #Screen Set 600x400 +pygame.display.set_caption("Sprite Speed Test Window") +GREEN = 0, 192, 0 # green +background = pygame.image.load("Room.gif") +screen.blit(background,[0,0]) +pygame.display.flip() +start = time() + +for aTrial in range(maxTrial): + start = time() + + font = pygame.font.Font(None, 16) + d = DrawableFontObject(font, "hello world") + d.goToAnim("anim1") + + group1=Scene(d) + groups=[group1] + print (time()-start) , + print " -- Time to load" + + + clock = pygame.time.Clock() + clock.tick() + start = time() + for frame in range(FRAME): + dirtyList=[] + for image in range(numImages): + #move / collision detection + groups[image].update(clock.get_time()) + clock.tick() + #individually blit each image group - add to list for update + dirtyList.extend(groups[image].draw(screen)) + + #draw the images flip/update + pygame.display.update(dirtyList) + for image in range(numImages): + groups[image].clear(screen, background) + + #print 1/((time()-start)/FRAME) + pygame.display.flip() -- cgit v0.9.1