Python 创建图像曲面窗口的精灵图纸

Python 创建图像曲面窗口的精灵图纸,python,python-3.x,pygame,sprite-sheet,Python,Python 3.x,Pygame,Sprite Sheet,我正在尝试在pygame/python中重新创建chrome no internet dino游戏。但每当我运行它而不是创建主文件窗口时,它都会从精灵工作表文件创建图像窗口。不知道我做错了什么 主文件: # importing the other file where the spritesheet class is from SpriteSheet import SpriteSheet import pygame pygame.init() SW = 500 SH = 500 win =

我正在尝试在
pygame
/
python
中重新创建chrome no internet dino游戏。但每当我运行它而不是创建主文件窗口时,它都会从精灵工作表文件创建图像窗口。不知道我做错了什么

主文件:

# 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))
精灵工作表文件:

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
它不创建主文件窗口,而是创建图像窗口

没有。没有什么比图像窗口更好的了

与显示关联的对象的内容就是您在窗口中看到的内容

win=pygame.display.set_模式((SW,SH))
首先在
image
(在
SPRITESHEET.get\u image()
中)上blit
SPRITESHEET

image.blit(self.SpriteSheet,(0,0),(x,y,宽度,高度))
现在,
image
的内容是
SPRITESHEET
。然后在
win

win.blit(图像,(0,0))
因此,将显示
图像
(与
子画面
)的内容

如果不想在窗口中看到
精灵表的内容,则必须删除该行

>win.blit(图像,(0,0))


顺便说一下,pygame wiki提供了一个很好的完整示例