Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to add a background image into pygame?

$
0
0

new to pygame just wondering how i would go about adding a background image into the game itself? this is my code so far, i've been using the bg as a way to import my image but the py file itself refuses to load up.

import pygameimport sysfrom pygame.locals import *clock = pygame.time.Clock()screen = pygame.display.set_mode((600,500))bg = pygame.image.load("images\space.png")pygame.mouse.set_visible(0)ship = pygame.image.load("images\ship.png")ship_top = screen.get_height() - ship.get_height()ship_left = screen.get_width()/2 - ship.get_width()/2screen.blit(ship, (ship_left,ship_top))shot = pygame.image.load("images\shot.png")shoot_y = 0pygame.display.set_caption('galaxy invaders')while True:    clock.tick(60)    screen.fill((r,0,0))    screen.blit(bg.(0,0))    x,y = pygame.mouse.get_pos()    screen.blit(ship, (x-ship.get_width()/2, ship_top))    for event in pygame.event.get():        if event.type == pygame.QUIT:            sys.exit()        elif event.type == MOUSEBUTTONDOWN:            shoot_y = 500            shoot_x = x    if shoot_y > 0:        screen.blit(shot, (shoot_x, shoot_y))        shoot_y -= 10    pygame.display.update()

Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>