blob: 66fecb4e9e760fc6de712a00f306a57c1ad3333d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
from typing import List
import pygame
def get_sprites(sprite_sheet) -> List:
sheet_width, sheet_height = sprite_sheet.get_size()
sprite_width, sprite_height = 32, 32
rows = sheet_height // sprite_height
columns = sheet_width // sprite_width
sprites = []
for row in range(rows):
for col in range(columns):
x = col * sprite_width
y = row * sprite_height
# Create a new surface for the current sprite and blit it from the
# sprite sheet onto this new surface
new_sprite_surface = pygame.Surface(
(sprite_width, sprite_height), pygame.SRCALPHA)
new_sprite_surface.blit(
sprite_sheet, (0, 0), (x, y, x + sprite_width, y + sprite_height))
# Add this new surface to our list of sprites
sprites.append(new_sprite_surface)
return sprites
|