NOTE - I am new to Love2D (Though I remember using it a little before), so I might not know about everything exactly.
Ok, so I want to do a scrolling effect on the background (The sky texture, ground texture, and maybe clouds). I am not sure how to do this easily, as I want it to be as clean (and simple) as possible. If anyone could give me some advice, that would be great.
EDIT: SO I kind of got it down, except now I have to figure out a way to have it so when x reaches a certain coordinate, a duplicate of the shape (q) will reset to 1000 (since the image is 1000 x 200, and the coordinates for x start at 0 x 550). If you don't entirely understand what I mean:
Questions about scrolling (and platforming)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 5
- Joined: Mon Apr 11, 2016 11:21 pm
Questions about scrolling (and platforming)
- Attachments
-
- scrollinginmyskin.love
- Scroll test
- (192.75 KiB) Downloaded 110 times
Re: Questions about scrolling (and platforming)
The simplest way is to always draw two copies of the background at x and x+w (w is the images width) and move them. Then if x < -w set it to 0 again (add w to make it not snap that frame).Robert Freeman wrote:NOTE - I am new to Love2D (Though I remember using it a little before), so I might not know about everything exactly.
Ok, so I want to do a scrolling effect on the background (The sky texture, ground texture, and maybe clouds). I am not sure how to do this easily, as I want it to be as clean (and simple) as possible. If anyone could give me some advice, that would be great.
EDIT: SO I kind of got it down, except now I have to figure out a way to have it so when x reaches a certain coordinate, a duplicate of the shape (q) will reset to 1000 (since the image is 1000 x 200, and the coordinates for x start at 0 x 550). If you don't entirely understand what I mean:
Last edited by s-ol on Tue Apr 12, 2016 4:12 pm, edited 1 time in total.
Re: Questions about scrolling (and platforming)
Even better to add w to x rather than to set x to 0. That preserves velocity.
Re: Questions about scrolling (and platforming)
pgimeno wrote:Even better to add w to x rather than to set x to 0. That preserves velocity.
s-ol wrote:Then if x < -w set it to 0 again (add w to make it not snap that frame).
Re: Questions about scrolling (and platforming)
Oops, didn't see your edit.
Re: Questions about scrolling (and platforming)
It wasn't an edit, the edit only fixed a typo but whateverpgimeno wrote:Oops, didn't see your edit.
-
- Prole
- Posts: 5
- Joined: Mon Apr 11, 2016 11:21 pm
Re: Questions about scrolling (and platforming)
I'm extremely close to getting it. Though there seems to be one issue:
I can't seem to figure out how to have the second image move by 3 while reseting to 0, since it will just end up at -3 (Since it thinks I'm telling it to remove 3 from the X coordinates, rather then telling it to translate by 3).
I can't seem to figure out how to have the second image move by 3 while reseting to 0, since it will just end up at -3 (Since it thinks I'm telling it to remove 3 from the X coordinates, rather then telling it to translate by 3).
Re: Questions about scrolling (and platforming)
Post the love again with the edited code, its easier that wayRobert Freeman wrote:I'm extremely close to getting it. Though there seems to be one issue:
I can't seem to figure out how to have the second image move by 3 while reseting to 0, since it will just end up at -3 (Since it thinks I'm telling it to remove 3 from the X coordinates, rather then telling it to translate by 3).
-
- Prole
- Posts: 5
- Joined: Mon Apr 11, 2016 11:21 pm
Re: Questions about scrolling (and platforming)
Alright, here it is.
- Attachments
-
- scroll2.love
- (192.76 KiB) Downloaded 118 times
Re: Questions about scrolling (and platforming)
Quick fix: Inside the if, set x to 0 and q to 1000.
Better fix: Get rid of q, draw one image at x, z and the other at x + desert_ground:getWidth(), z
Then change the if to this:
(even better, use a variable to cache the value of desert_ground:getWidth() and use it instead)
As a side note, it's not a good idea to use a constant increment per frame. Frame rate varies between systems (e.g. I can configure my monitor for 60 Hz or 75 Hz, and if you disable vsync, or if the system doesn't support it, things can go crazy). Use the love.update event to increase x, multiplying the speed by dt. That will give a constant speed in any system. Something like:
Better fix: Get rid of q, draw one image at x, z and the other at x + desert_ground:getWidth(), z
Then change the if to this:
Code: Select all
if x < -desert_ground:getWidth() then
x = x + desert_ground:getWidth()
end
As a side note, it's not a good idea to use a constant increment per frame. Frame rate varies between systems (e.g. I can configure my monitor for 60 Hz or 75 Hz, and if you disable vsync, or if the system doesn't support it, things can go crazy). Use the love.update event to increase x, multiplying the speed by dt. That will give a constant speed in any system. Something like:
Code: Select all
function love.update(dt)
x = x - 180*dt
end
Who is online
Users browsing this forum: Google [Bot] and 3 guests