Page 1 of 2

2 backgrounds (moving) at the same time [SOLVED]

Posted: Tue Apr 15, 2014 3:18 pm
by ErvinGamez
Now, the idea is, that I have a semi transparent background at the top, and an opaque background at the bottom.
both of them randomly moving/scrolling, now, I have 2 problems with this, I put this at the top:

Code: Select all

        background=love.graphics.newImage('space1.png')
        background2=love.graphics.newImage('space2.png')
and then this at the bottom:

Code: Select all

function love.draw()
    love.graphics.draw(background)
    love.graphics.draw(background2)
end
But all this does is draw background1, not background2 (which is the semi-transparent one).
That was the first problem, now I need the second one, I have absolutely no idea how to make them both randomly (but smoothly) scroll.
Thanks for the help!

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:38 pm
by davisdude
We need a .love in order to help you out.

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:43 pm
by ErvinGamez
davisdude wrote:We need a .love in order to help you out.
Not sure why'd you need one, since I told you the code, but whatever, here:

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:48 pm
by davisdude
It is combining the 2, actually.
I needed the .love to make sure the images were actually transparent, etc.

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:50 pm
by ErvinGamez
davisdude wrote:It is combining the 2, actually.
I needed the .love to make sure the images were actually transparent, etc.
Hm, so is there anyway to separate them 2?

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:53 pm
by davisdude
What do you mean? It should be exactly what you want, if I'm understanding you correctly. It is drawing both of them, with 2 at the top, and 1 at the bottom.

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 3:58 pm
by ErvinGamez
davisdude wrote:What do you mean? It should be exactly what you want, if I'm understanding you correctly. It is drawing both of them, with 2 at the top, and 1 at the bottom.
Oh, it is!
Haha, 1 has stars that look similar to 2, so I thought it was just 1.
I asked you how I can separate them because I thought they were both merged into one image, and I don't want that since I want them both to smoothly and randomly move. Hope you can understand what I'm saying.

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 4:02 pm
by davisdude
Ah. No, they are not actually "merged", I just meant that they were both being drawn.
To get the scrolling effect, you can just set the x value for the images, and use it as the second argument in love.draw.

Code: Select all

function love.load()
    background=love.graphics.newImage('space1.png')
    background2=love.graphics.newImage('space2.png')
    background1x = 0
    background2x = 0
    dir =  -16
end

function love.draw()
    love.graphics.draw(background, background1x )
    love.graphics.draw(background2, background2x)
end

function love.update( dt )
    background2x = background2x + dir * dt
end
This should look how you want. :)

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 4:07 pm
by ErvinGamez
davisdude wrote:Ah. No, they are not actually "merged", I just meant that they were both being drawn.
To get the scrolling effect, you can just set the x value for the images, and use it as the second argument in love.draw.

Code: Select all

function love.load()
    background=love.graphics.newImage('space1.png')
    background2=love.graphics.newImage('space2.png')
    background1x = 0
    background2x = 0
    dir =  -16
end

function love.draw()
    love.graphics.draw(background, background1x )
    love.graphics.draw(background2, background2x)
end

function love.update( dt )
    background2x = background2x + dir * dt
end
This should look how you want. :)

That looks AWESOME! Thank you so much for all your help. The result was better than what I was planning!

Re: 2 backgrounds (moving) at the same time

Posted: Tue Apr 15, 2014 4:12 pm
by ErvinGamez
davisdude wrote:Ah. No, they are not actually "merged", I just meant that they were both being drawn.
To get the scrolling effect, you can just set the x value for the images, and use it as the second argument in love.draw.

Code: Select all

function love.load()
    background=love.graphics.newImage('space1.png')
    background2=love.graphics.newImage('space2.png')
    background1x = 0
    background2x = 0
    dir =  -16
end

function love.draw()
    love.graphics.draw(background, background1x )
    love.graphics.draw(background2, background2x)
end

function love.update( dt )
    background2x = background2x + dir * dt
end
This should look how you want. :)
One more thing, how do I "loop" it?