The following question is from chapter 12 of the book:
"Python Crash Course
".
I need to write a class that draws a *.bmp
image at the center of the screen.
I had a look here and here, which is a very specific case.
My class, which didn't raise much success, is:
import pygame, sys
class Lion():
def __init__(self, screen):
self.screen = screen
self.screen_width = 1000
self.screen_height = 500
self.bg_color = (230, 230, 230)
self.image = pygame.image.load('C:/Users/yoelp/Desktop/Python Works/lion.bmp')
self.rect = self.image.get_rect()
self.rect.centerx = self.screen_rect.centerx
self.rect.centery = self.screen_rect.centery
# Creating an instance of Lion.
lion = Lion(screen)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self.screen.blit(self.image, self.rect)
pygame.display.flip()
Any ideas?
Thank you.