Pygame Sprite/Font rendering issues
Posted
by Grimless
on Stack Overflow
See other posts from Stack Overflow
or by Grimless
Published on 2010-04-16T22:18:28Z
Indexed on
2010/04/16
22:23 UTC
Read the original article
Hit count: 266
Hey guys. Here's my problem:
I have a game class that maintains a HUD overlay that has a bunch of elements, including header and footer background sprites. Everything was working fine until I added a 1024x128 footer sprite. Now two of my text labels will not render, despite the fact that they DO exist in my Group and self.elements array. Is there something I'm missing? When I take out the footerHUDImage line, all of the labels render correctly and everything works fine. When I add the footerHUDImage, two of the labels (the first two) no longer render and the third only sometimes renders. HELP PLEASE! Here is the code:
class AoWHUD (object):
def __init__(self, screen, delegate, dataSource):
self.delegate = delegate
self.dataSource = dataSource
self.elements = []
headerHudImage = KJRImage("HUDBackground.png")
self.elements.append(headerHudImage)
headerHudImage.userInteractionEnabled = True
footerHUDImage = KJRImage("ControlsBackground.png")
self.elements.append(footerHUDImage)
footerHUDImage.rect.bottom = screen.get_rect().height
footerHUDImage.userInteractionEnabled = True
lumberMessage = "Lumber: " + str(self.dataSource.lumber)
lumberLabel = KJRLabel(lumberMessage, size = 48, color = (240, 200, 10))
lumberLabel.rect.topleft = (_kSpacingMultiple * 0, 0)
self.elements.append(lumberLabel)
stoneMessage = "Stone: " + str(self.dataSource.stone)
stoneLabel = KJRLabel(stoneMessage, size = 48, color = (240, 200, 10))
stoneLabel.rect.topleft = (_kSpacingMultiple * 1, 0)
self.elements.append(stoneLabel)
metalMessage = "Metal: " + str(self.dataSource.metal)
metalLabel = KJRLabel(metalMessage, size = 48, color = (240, 200, 10))
metalLabel.rect.topleft = (_kSpacingMultiple * 2, 0)
self.elements.append(metalLabel)
foodMessage = "Food: " + str(len(self.dataSource.units)) + "/" + str(self.dataSource.food)
foodLabel = KJRLabel(foodMessage, size = 48, color = (240, 200, 10))
foodLabel.rect.topleft = (_kSpacingMultiple * 3, 0)
self.elements.append(foodLabel)
self.selectionSprites = {32 : pygame.image.load("Selected32.png").convert_alpha(), 64 : pygame.image.load("Selected64.png")}
self._sprites_ = pygame.sprite.Group()
for e in self.elements:
self._sprites_.add(e)
print self.elements
def draw(self, screen):
if self.dataSource.resourcesChanged:
lumberMessage = "Lumber: " + str(self.dataSource.lumber)
stoneMessage = "Stone: " + str(self.dataSource.stone)
metalMessage = "Metal: " + str(self.dataSource.metal)
foodMessage = "Food: " + str(len(self.dataSource.units)) + "/" + str(self.dataSource.food)
self.elements[2].setText(lumberMessage)
self.elements[2].rect.topleft = (_kSpacingMultiple * 0, 0)
self.elements[3].setText(stoneMessage)
self.elements[3].rect.topleft = (_kSpacingMultiple * 1, 0)
self.elements[4].setText(metalMessage)
self.elements[4].rect.topleft = (_kSpacingMultiple * 2, 0)
self.elements[5].setText(foodMessage)
self.elements[5].rect.topleft = (_kSpacingMultiple * 3, 0)
self.dataSource.resourcesChanged = False
self._sprites_.draw(screen)
if self.delegate.selectedUnit:
theSelectionSprite = self.selectionSprites[self.delegate.selectedUnit.rect.width]
screen.blit(theSelectionSprite, self.delegate.selectedUnit.rect)
© Stack Overflow or respective owner