Page 1 of 1

Make background image scrolling, an reapeating endless with only update part

Posted: Fri Mar 31, 2017 11:21 am
by JHB
Hi,
I am trying to make a Background image scrolling endless, and repeating, Normaly i use this Code for Stuff i'm making on PC, but this time i have some trouble.

First of all the Code works, but only on PC, i'm trying to make it work on 3DS (LövePotion) and it seems that i can't set vars to other Value as 0 in the LOAD part (Sometimes, Somtimes it works, no idea what's the reason) so bgy2 is 0 wich makes the update part mostly useless. anyway, i gave up making it work with load other Values than 0 for the Background repeating part.
Now i'am trying to use ONLY the Update part for that (exept, bgy1 & bgy2 can still get load in Load but have to be 0) But i'am totaly freaking out, i don't get it to work, try'd a lot of things but nothing was even close. Now i want to start that problem from Zero again, but with a little help (hopefully from you guys)

Code: Select all

Screen Height is also 240
-- Load Part:

bgy1 = 0
bgy2 = konfetti_bg:getHeight() -- It's actually also 240

--
-- Update Part:

bgy1 = bgy1+(block_speed*dt)/3
bgy2 = bgy2+(block_speed*dt)/3

if bgy1 >= 240 then
	bgy1 = -240
end
if bgy2 >= 240 then
	bgy2 = -240
end

--

Re: Make background image scrolling, an reapeating endless with only update part

Posted: Fri Mar 31, 2017 1:10 pm
by Xugro
Since both positions of the background images advances at the same speed you do not need to calculate both. The only difference between the two is the height of the image (plus or minus). So you only have to draw them with an offset of the height of the image. I attached an example of this.

But you should investigate your problem with not being able to initialize variables in love.load() to something different than zero. It might be a bug in LÖVE or in your code.

Re: Make background image scrolling, an reapeating endless with only update part

Posted: Fri Mar 31, 2017 1:44 pm
by JHB
Duh, thanks, i never came to the point to just add the "-height" in the draw part. And also this works great on PC,
BUT if i start using this via LovePotion i get a value somewhere around "66440000" (counting down) for the background Position.

Maybe an idea why this happen ? or even better how to slove this ?

Edit: Okay i don_t know how exacly i did this, but i got it to work finally. in the end i just, "rebuild" your code with "my own words" and, i don't know but it works, thanks man.