Last active
          December 10, 2015 23:09 
        
      - 
      
 - 
        
Save hortonew/4507770 to your computer and use it in GitHub Desktop.  
    Pygame - Image group
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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