I'm trying to recreate the chrome no internet dino game inside pygame/python. But whenever I run it it instead of creating the main file window it creates the image window from the sprite sheet file. Don't know what I'm doing wrong here.
main file:
# importing the other file where the spritesheet class is
from SpriteSheet import SpriteSheet
import pygame
pygame.init()
SW = 500
SH = 500
win = pygame.display.set_mode((SW, SH))
SPRITE_SHEET = pygame.image.load('sheet.png')
# mainloop
run = True
while run:
# checking for clicking the x button
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# cropping the image from the spritesheet
spritesheet = SpriteSheet(SPRITE_SHEET)
image = spritesheet.get_image(
848, 2, 44, 47, (255, 255, 255))
win.blit(image, (0, 0))
sprite sheet file:
import pygame
# creating the class
class SpriteSheet(object):
SpriteSheet = None
# getting the spritesheet
def __init__(self, sheet):
self.SpriteSheet = sheet
# cropping the image
def get_image(self, x, y, width, height, color):
image = pygame.display.set_mode([width, height])
image.blit(self.SpriteSheet, (0, 0), (x, y, width, height))
image.set_colorkey(color)
return image
No. There is nothing like a image window.
The content of the
pygame.Surfaceobject which is associated to the display is what you see in the window.First you blit
SPRITESHEETonimage(inSpriteSheet.get_image())Now the content of
imageis theSPRITESHEET. Then you blitimageonwinHence the content of
image(which is the same asSPRITESHEET) is displayed.When you don't want to see the content of
SPRITESHEETin the window, then you have to remove the line>win.blit(image, (0, 0))By the way, pygame wiki provides a nice and complete Spritesheet example.