I would like create a two layered scrolling background but everytime I run the programm below it make everything wrong, and I don't know why :/ Can you help me ?
I've try the code below :
'bg scrolling try'
import pygame as pg
from pygame.locals import *
pg.init()
screen = pg.display.set_mode((1920, 1080), pg.NOFRAME)
a = True
land_0 = pg.image.load('sprites/land_0.png').convert_alpha()
land_1 = pg.image.load('sprites/land_1.png').convert_alpha()
bg = pg.image.load('sprites/bg.png').convert_alpha()
pos_l0_0 = 2
pos_l0_1 = 1920
pos_l1_0 = -1000
pos_l1_1 = 920
hight_land = 500
hight_land_1 = 400
s_speed = 2
while a:
screen.blit(bg,(0, 0))
pos_l1_0 = pos_l1_0 - s_speed
pos_l1_1 = pos_l1_1 - s_speed
if pos_l1_0 == - 1920:
pos_l1_0 = 1920
elif pos_l1_1 == - 1920:
pos_l1_0 = 1920
screen.blit(land_1,(pos_l1_0, hight_land_1))
screen.blit(land_1,(pos_l1_1, hight_land_1))
# 2nd
pos_l0_0 = pos_l0_0 - s_speed/2
pos_l0_1 = pos_l0_1 - s_speed/2
if pos_l0_0 == - 1920:
pos_l0_0 = 1920
elif pos_l0_1 == - 1920:
pos_l0_0 = 1920
screen.blit(land_0,(pos_l0_0, hight_land))
screen.blit(land_0,(pos_l0_1, hight_land))
pg.display.update()
I would like the first layer scroll fast and the second ( in background scroll slow ), I working prettry during the first 20 seconds but after this it random : one layer diseappear or one is blitting, so strange...
See Question&Answers more detail:os