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

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.
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

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

Post 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!
Last edited by ErvinGamez on Tue Apr 15, 2014 4:07 pm, edited 1 time in total.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: 2 backgrounds (moving) at the same time

Post by davisdude »

We need a .love in order to help you out.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

Re: 2 backgrounds (moving) at the same time

Post 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:
Attachments
Game.love
(3.87 MiB) Downloaded 114 times
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: 2 backgrounds (moving) at the same time

Post by davisdude »

It is combining the 2, actually.
I needed the .love to make sure the images were actually transparent, etc.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

Re: 2 backgrounds (moving) at the same time

Post 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?
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: 2 backgrounds (moving) at the same time

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

Re: 2 backgrounds (moving) at the same time

Post 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.
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: 2 backgrounds (moving) at the same time

Post 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. :)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

Re: 2 backgrounds (moving) at the same time

Post 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!
ErvinGamez
Prole
Posts: 17
Joined: Tue Apr 15, 2014 11:32 am

Re: 2 backgrounds (moving) at the same time

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

Who is online

Users browsing this forum: No registered users and 4 guests