Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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