-
Notifications
You must be signed in to change notification settings - Fork 0
/
spritesheet_to_animation.py
53 lines (36 loc) · 1.3 KB
/
spritesheet_to_animation.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pygame
from sys import exit
pygame.init()
# Screen
size = width, height = 700, 500
screen = pygame.display.set_mode(size)
pygame.display.set_caption('Eagle')
clock = pygame.time.Clock()
sprite_sheet_image = pygame.image.load('assets/eagle.png').convert_alpha()
def get_image(sheet, frame, width, height, scale):
image = pygame.Surface((width, height)).convert_alpha() # Creamos una superficie
image.blit(sheet, (0, 0), ((frame * width), 0, width, height)) # Cargamos el area del sprite sheet en la superficie
image = pygame.transform.scale(image, (width * scale, height * scale))
return image
# Eagle left
left_0 = get_image(sprite_sheet_image, 0, 32, 32, 2)
left_1 = get_image(sprite_sheet_image, 1, 32, 32, 2)
left_2 = get_image(sprite_sheet_image, 2, 32, 32, 2)
left_frames = [left_0, left_1, left_2]
left_frames_index = 0
running = True
# Main Loop
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
# Background
screen.fill('#ffffff')
# Show image
screen.blit(left_frames[left_frames_index], (0, 0))
left_frames_index += 1
if left_frames_index >= len(left_frames):
left_frames_index = 0
pygame.display.update()
clock.tick(10)