1

Hi there i am working on a side scrolling abckground to put in my game, heres what ive got at the moment:

import pygame
import sys
import pygame.sprite as sprite

theClock = pygame.time.Clock()
background = pygame.image.load('space.jpg')
background_size = background.get_size()
background_rect = background.get_rect()
screen = pygame.display.set_mode(background_size)
w,h = background_size
x = 0
y = 0
x1 = 0
y1 = -h
running = True
while running:
    screen.blit(background,background_rect)
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    y1 += 5
    y += 5
    screen.blit(background,(y,x))
    screen.blit(background,(y1,1))
    if y > h:
        y = -h
    if y1 > h:
        y1 = -h
    pygame.display.update()
    theClock.tick(25)
pygame.quit()

at the moment i am getting a flickering screen with the moving image going to the right and the original image stationary flickering over it any help would be greatly appreciated - as its for my a-level computing coursework a and have trying to implement a feature liket his into the game for ages.... again thanks for help

  • You are 'updating' twice. remove the first `pygame.display.update()` – ninMonkey Oct 24 '13 at 23:29
  • thank you, and how would i make it to go right to left instead of whats its doing at the moment?? thanks –  Oct 24 '13 at 23:43
  • What are `y`, `y1`? Are you making parallax scrolling? If so, they are using the same texture, that confused me. -- You might find tutorial 21 and 21 useful: [lazyfoo's SDL](http://lazyfoo.net/SDL_tutorials/) -- To scroll right, you end up subtracting from your x, to move the initial offset farther left. -- Edit: See this pygame demo: http://stackoverflow.com/a/14357169/341744 – ninMonkey Oct 25 '13 at 01:44
  • after looking at the tutorials theyre in c++ which is a real shame beacuse it looked really good and could've helped me big time, is there anything else you know of thanks! –  Oct 25 '13 at 15:07
  • i found this: import pygame, sys from pygame.locals import * pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((600,400),0,32) b1 = "c:\\back.jpg" back = pygame.image.load(b1).convert() back2 = pygame.image.load(b1).convert() x = 0 screenWidth = 600 while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() screen.blit(back, (x,0)) screen.blit(back2,(x-screenWidth,0)) x = x + 1 if x == screenWidth: x = 0 msElapsed = clock.tick(100) pygame.display.flip() Thanks –  Oct 25 '13 at 16:13

1 Answers1

0

i struggled with a parallax effect in my 'game' as well. I would suggest this to you: http://www.pygame.org/project-pyParallax-2623-.html

download the module, and run and disassemble the demo, it is very easy to understand and replicate. (Hint: the parallax.ParallaxSurface.add() method has a third argument you can pass to it that will scale your image appropriately for you. Very Very easy to use module.

kBeezee
  • 48
  • 1
  • 6