Brianna
Brianna

Reputation: 107

How to change speed of scrolling background pygame?

I'm making a game for Pygame, and I want the background to scroll faster, but I don't know how to. This is the code that is relevant to the scrolling background:

#Scrolling background

    background = "foxhabitat.jpg"
    back = pygame.image.load(background).convert()
    back2 = pygame.image.load(background).convert()

    screenWidth = 900
    back=pygame.transform.scale(back, (1000,600))
    back2=pygame.transform.scale(back, (1000,600))   

    screenscroll.blit(back, (xx,0))
    screenscroll.blit(back2,(xx-screenWidth,0))

    xx = xx + 1
    if xx == screenWidth:
        xx = 0

    msElapsed = clock.tick(500) # thought it would change speed of scrolling?

I've tried to change the speed of the clock.tick but it didn't do anything, and yes, I imported the clock at the beginning of the program. How do I change the speed of the scrolling background? Oh, and screenscroll is screenscroll = pygame.display.set_mode((1000,600),0,0) Help would be much appreciated, thanks!

Upvotes: 0

Views: 636

Answers (1)

furas
furas

Reputation: 142651

Add bigger value

xx = xx + 2 

That's all.


And use >= because sometimes xx may not be equal screenWidth

if xx >= screenWidth:
    xx = 0

clock.tick(500) means "give me not more than 500 FPS" but sometimes it can be less. If you have slow computer it can give you always only 25 FPS.

Upvotes: 1

Related Questions