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

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.
Post Reply
JHB
Prole
Posts: 30
Joined: Tue Feb 12, 2013 6:15 pm

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

Post 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

--
Xugro
Party member
Posts: 114
Joined: Wed Sep 29, 2010 8:14 pm

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

Post 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.
Attachments
repeating_background.love
(144.1 KiB) Downloaded 431 times
JHB
Prole
Posts: 30
Joined: Tue Feb 12, 2013 6:15 pm

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

Post 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.
Post Reply

Who is online

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