Original Post
Hi there! I have some problems with viewing a sprite on a black screen with pygame. I want to make a pacman clone as my first project since I belive it is about hard enough. I have two modules, one that creates the pacman and one that at the moment only tries to show him on the screen. When I run the program I see a black screen that instantly dissapears, and I can't see a trace of my Pacman in there. Could you show my whats wrong and please tell me why it's wrong. Thanks in advance. pacman.py game.py
""" The pacman module, containing info
about mr. Pacman himself. """
import pygame
pygame.init()
class Pacman(pygame.sprite.Sprite):
""" The class that creates Pacman """
location = "data/pacman.gif"
def __init__(self, posX, posY):
""" Creates the creature """
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(location)
self.image = self.image.convert()
self.rect = self.image.get_rect()
self.rect.centerx = posX
self.rect.centery = posY
""" pacman clone by Christoffer Lejdborg
http://zyngame.wordpress.com/ """
import pygame
pygame.init()
def main():
# set up the display
screen = pygame.display.set_mode((390, 390))
pygame.display.set_caption("Pacman clone")
# set up the background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 0))
screen.blit(background, (0, 0))
hero = pacman.Pacman.__init__(100, 150)
# set up tha main loop
keepGoing = True
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
allSprites = pygame.sprite.Group(hero)
while keepGoing:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)
pygame.display.flip()
pygame.mouse.set_visible(True)
if __name__ == "__main__":
main()