Reputation: 87
background = love.graphics.newImage ("joust.png")
bird = love.graphics.newImage ("bird.png")
x = 0
y = 128
speed = 300
function love.update (dt)
if love.keyboard.isDown ("d") then
x = x + (speed * dt)
end
if love.keyboard.isDown ("a") then
x = x - (speed * dt)
end
if love.keyboard.isDown ("w") then
y = y - (speed * dt)
end
if love.keyboard.isDown ("s") then
y = y + (speed * dt)
end
end
function love.draw()
love.graphics.draw(bird, x, y)
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
end
Let me first start with I know this is a lot of code so I'm sorry. I'm trying to make a character moving with an image behind it as the background. when I run the program, what seems to happen is the background overlaps the character and you can't see the character. when I remove the background code the character appears and works as it should. Could anyone tell me what I am doing wrong? Much appreciated
Upvotes: 1
Views: 1636
Reputation: 5857
Rearrange love.draw() function to paint bird after background:
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
love.graphics.draw(bird, x, y)
end
Upvotes: 5