【发布时间】:2021-01-21 12:35:32
【问题描述】:
我正在尝试在pygame/python 中重新创建 chrome no internet 恐龙游戏。但是每当我运行它而不是创建主文件窗口时,它都会从精灵表文件创建图像窗口。不知道我在这里做错了什么。
主文件:
# 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
【问题讨论】:
标签: python python-3.x pygame sprite-sheet