Problem with creating a parallaxing/scrolling background

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Problem with creating a parallaxing/scrolling background

#1 Post by GeeSeki »

I thought it'd be as simple as this but this makes the background all janky and buggy and the game would send the various layers of the background shooting left and right instead of a smooth motion that loops, as well as showing past the very right of each layer.

What I'm guessing is that the layers that are being completed and repeated quicker than the others are affecting those layers as well for some reason?

Any help, I'm sure the solution is simple but I can't seem to work it out.

Code: Select all

layeredimage bg_parallaxingtest:
    always:
        "bg_parallaxingtest_back1"
    always:
        "bg_parallaxingtest_back2"
    always:
        "bg_parallaxingtest_road"
    always:
        "bg_parallaxingtest_front"

image bg_parallaxingtest_back1:
    "/images/background/ParallaxingTempBack1.png"
    xalign 0
    linear 20 xalign 1.0
    repeat

image bg_parallaxingtest_back2:
    "/images/background/ParallaxingTempBack2.png"
    xalign 0
    linear 10 xalign 1.0
    repeat

image bg_parallaxingtest_road:
    "/images/background/ParallaxingTempRoad.png"
    xalign 0
    linear 5 xalign 1.0
    repeat

image bg_parallaxingtest_front:
    "/images/background/ParallaxingTempFront.png"
    xalign 0
    linear 1 xalign 1.0
    repeat

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Problem with creating a parallaxing/scrolling background

#2 Post by Ocelot »

Can you show what you mean by that and what you expect? And ideally, a small test project which shows the problem.
< < insert Rick Cook quote here > >

User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Re: Problem with creating a parallaxing/scrolling background

#3 Post by GeeSeki »

Ocelot wrote: Tue Jun 22, 2021 9:16 am Can you show what you mean by that and what you expect? And ideally, a small test project which shows the problem.
https://www.youtube.com/watch?v=AlKM1Zp ... amMiracles

This is the result I want except looping (the assets I have loops).

But the code I have at the moment doesn't do that, it looks like chaos where images are being shoved left and right sporadically. The assets are all the same dimension and I thought I could just change the linear speed of layer.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Problem with creating a parallaxing/scrolling background

#4 Post by Ocelot »

It is slightly hard to understand the problem without seeing it, but I have a guess.
This is less likely one:
xalign 0. means "align left side of the image to the left side of the screen"
xalign 1. means "align right side of the image to the right side of the screen"
If displayable in those two positions do not look exactly same, you will have jumps.

The more likely one:
0 and 0. (or 0.0 or .0) are two very different numbers. One it integer and represent absolute positioning in pixels. Other one is real number and represent positioning in fractions of the screen or displayable. You must not mix them, because it leads to unexpected results. Replace 0 with 0.0 and see if problem persists.
< < insert Rick Cook quote here > >

User avatar
GeeSeki
Regular
Posts: 112
Joined: Sat Dec 17, 2016 3:39 am
Projects: A Town Uncovered
itch: geeseki
Contact:

Re: Problem with creating a parallaxing/scrolling background

#5 Post by GeeSeki »

Ocelot wrote: Tue Jun 22, 2021 9:32 am It is slightly hard to understand the problem without seeing it, but I have a guess.
This is less likely one:
xalign 0. means "align left side of the image to the left side of the screen"
xalign 1. means "align right side of the image to the right side of the screen"
If displayable in those two positions do not look exactly same, you will have jumps.

The more likely one:
0 and 0. (or 0.0 or .0) are two very different numbers. One it integer and represent absolute positioning in pixels. Other one is real number and represent positioning in fractions of the screen or displayable. You must not mix them, because it leads to unexpected results. Replace 0 with 0.0 and see if problem persists.
I managed to fix the problem by simply doing

Code: Select all

scene bg_parallaxingtest_back1
    show bg_parallaxingtest_back2
    show bg_parallaxingtest_road
    show bg_parallaxingtest_front
    with fade
Each layer loops/repeats at different times so the way I was doing it early seemed to messed with each layer everytime a transform animation repeats when another isn't complete yet. If I were to describe it in words, it's like the background was taking 2 steps forwards one step back instead of just moving one direction at a steady pace.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]