Sunday 15 July 2012

python - How to make the background continuously scrolling with Pygame? -


I am planning to make a space shooting game and I feel that my background keeps running continuously with stars. You can see my code below image

  Import the Pygam import system import pygame.sprite as phant theClock = pygame.time.Clock () background = pygame.image.load (' Background.gif ') background_size = background.get_size () Background_rect = background.get_rect () screen = pygame.display.set_mode (background_size) x = 0 y = 0w, h = background_size running = true while running: the screen. For the event in Blith (background, background) pygame.display.update () Pygame.event.get (): if event.type == pygame.QUIT: move = False if (y> h): y = 0 more: y + = 5 screen. Blunt (background, (x, y)) pygame.display.flip () pygame.display.update () theClock.tick (10)    

Here's what I will do:

Background image from twice to one (0, 0) and on the other (0, - IMG height) Then take them down and when one of these is located on the position (0, IMG.ETH), then place it again at position (0, - IMG. Heights).

  Import Import Import Import Import pygame.sp rite as Phantom theClock = pygame.time.Clock () background = pygame.image.load ('background.gif') background_size = background .get_size () background_rect = background.get_rect () screen = pygame.display.set_mode (background_size) w, h = background_size x = 0 y = 0x1 = 0 y1 = -h is running: while running: the screen. For the event in Blith (Background, Background Gate) pygame.display.update () pygame.event.get (): if event.type == pygame.QUIT: current = false y1 + 5 = 5 y + = 5 screen. Blilt (background, (X, Y)) screen. Blunt (background, (x1, y1)) if y & gt; H: y = -h if y1> H: y1 = -h pygame.display.flip () pygame.display.update () theClock.tick (10)    

No comments:

Post a Comment