Skip to content

Instantly share code, notes, and snippets.

@AnimeshShaw
Created January 2, 2015 13:51
Show Gist options
  • Select an option

  • Save AnimeshShaw/3676ed9079b7aa40fdc8 to your computer and use it in GitHub Desktop.

Select an option

Save AnimeshShaw/3676ed9079b7aa40fdc8 to your computer and use it in GitHub Desktop.
Explosion animation using Spritesheets in PyGame. More Details :- http://www.rawcoders.com/Thread-Python-Explosion-animation-using-Spritesheets-in-PyGame
#! /usr/bin/env python
import sys
import pygame
from pygame.constants import QUIT, K_ESCAPE, KEYDOWN
def sprite( w, h ):
animation_frames = []
timer = pygame.time.Clock()
screen = pygame.display.set_mode( ( 200, 200 ), 0, 32 )
image = pygame.image.load( "BombExploding.png" ).convert_alpha()
width, height = image.get_size()
for i in range( int( width / w ) ):
animation_frames.append( image.subsurface( ( i * w, 0, w, h ) ) )
counter = 0
while True:
for evt in pygame.event.get():
if evt.type == QUIT or ( evt.type == KEYDOWN and evt.key == K_ESCAPE ) :
sys.exit()
screen.fill( ( 27, 27, 27 ) )
screen.blit( animation_frames[counter], ( 90, 60 ) )
counter = ( counter + 1 ) % 13
pygame.display.update()
timer.tick( 10 )
if __name__ == "__main__":
sprite( 32, 64 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment