-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.py
More file actions
24 lines (18 loc) · 767 Bytes
/
helper.py
File metadata and controls
24 lines (18 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pygame
from settings import *
""" Convert a spritesheet to a single frame image.
"""
def get_spritesheet_frame(sheet, frame_nr, width, height, scale):
image = pygame.Surface((width, height), TRANSPARENT).convert_alpha()
image.blit(sheet, (0,0), (frame_nr*width, 0, width, height))
image = pygame.transform.scale(image, (width*scale, height*scale))
return image
""" Create an animation which is a list of images.
"""
def create_animation(path, n_steps, width, height, scale):
sheet = pygame.image.load(path).convert_alpha()
# Convert sheet to animation.
animation_list = []
for frame_nr in range(n_steps):
animation_list.append(get_spritesheet_frame(sheet, frame_nr, width, height, scale))
return animation_list