Questions about scrolling (and platforming)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Robert Freeman
Prole
Posts: 5
Joined: Mon Apr 11, 2016 11:21 pm

Questions about scrolling (and platforming)

Post by Robert Freeman »

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.
Image

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:
Attachments
scrollinginmyskin.love
Scroll test
(192.75 KiB) Downloaded 110 times
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Questions about scrolling (and platforming)

Post by s-ol »

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.
Image

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:
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).
Last edited by s-ol on Tue Apr 12, 2016 4:12 pm, edited 1 time in total.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: Questions about scrolling (and platforming)

Post by pgimeno »

Even better to add w to x rather than to set x to 0. That preserves velocity.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Questions about scrolling (and platforming)

Post by s-ol »

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).
:P

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: Questions about scrolling (and platforming)

Post by pgimeno »

Oops, didn't see your edit.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Questions about scrolling (and platforming)

Post by s-ol »

pgimeno wrote:Oops, didn't see your edit.
It wasn't an edit, the edit only fixed a typo :P but whatever :)

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Robert Freeman
Prole
Posts: 5
Joined: Mon Apr 11, 2016 11:21 pm

Re: Questions about scrolling (and platforming)

Post by Robert Freeman »

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).
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: Questions about scrolling (and platforming)

Post by Vimm »

Robert 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).
Post the love again with the edited code, its easier that way :P
Robert Freeman
Prole
Posts: 5
Joined: Mon Apr 11, 2016 11:21 pm

Re: Questions about scrolling (and platforming)

Post by Robert Freeman »

Alright, here it is.
Attachments
scroll2.love
(192.76 KiB) Downloaded 118 times
User avatar
pgimeno
Party member
Posts: 3641
Joined: Sun Oct 18, 2015 2:58 pm

Re: Questions about scrolling (and platforming)

Post by pgimeno »

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:

Code: Select all

if x < -desert_ground:getWidth() then
  x = x + desert_ground:getWidth()
end
(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:

Code: Select all

function love.update(dt)
  x = x - 180*dt
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests