Background image?

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
marshallclan
Prole
Posts: 3
Joined: Sat Sep 15, 2012 4:39 pm

Background image?

Post by marshallclan »

Is there a way to add a background image? Sorry for such a simple question, but I can't find how to anywhere, and can you make it repeat? Thanks in advance.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Background image?

Post by Robin »

If you do it manually like this, yes:

Code: Select all

function love.load()
   -- other things
   background = love.graphics.newImage("yourbackgroundfile.png")
end

-- other callbacks

function love.draw()
    for i = 0, love.graphics.getWidth() / background:getWidth() do
        for j = 0, love.graphics.getHeight() / background:getHeight() do
            love.graphics.draw(background, i * background:getWidth(), j * background:getHeight())
        end
    end
    -- draw other things
end
EDIT: this version tiles the background

Note if the background is really small, you might want to use another approach, like SpriteBatch or Canvas.
Last edited by Robin on Sat Sep 15, 2012 6:24 pm, edited 1 time in total.
Help us help you: attach a .love.
marshallclan
Prole
Posts: 3
Joined: Sat Sep 15, 2012 4:39 pm

Re: Background image?

Post by marshallclan »

Thanks, another thing, how would I make it repeat?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Background image?

Post by Robin »

I edited my post. :)
Help us help you: attach a .love.
marshallclan
Prole
Posts: 3
Joined: Sat Sep 15, 2012 4:39 pm

Re: Background image?

Post by marshallclan »

Thanks :awesome:

I shall learn what I can from this :U
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 5 guests