Skip to content

Instantly share code, notes, and snippets.

@hortonew
Last active December 10, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hortonew/4507770 to your computer and use it in GitHub Desktop.
Save hortonew/4507770 to your computer and use it in GitHub Desktop.
Pygame - Image group
import pygame, sys, os
running = True
pygame.init()
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
#calculate current path + location of player image
mypath = os.path.dirname( os.path.realpath( __file__) )
p_path = os.path.join(mypath, 'player.png')
#create player image, move to 400,300
player_image = pygame.sprite.Sprite()
player_image.image = pygame.image.load(p_path).convert()
player_image.rect = player_image.image.get_rect().move(400,300)
player_group = pygame.sprite.Group()
player_group.add(player_image)
def update():
#draw player group to screen
player_group.draw(screen)
if __name__ == "__main__":
while running:
update()
pygame.display.flip()
clock.tick(30)
pygame.quit()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment