For example
Code: Select all
player_draw
background_draw
but
Code: Select all
if blaa blaa then
player_draw
end
background_draw
Code: Select all
player_draw
background_draw
Code: Select all
if blaa blaa then
player_draw
end
background_draw
I have no idea how this is causing the player to be drawn on top. Can you post the code for player_draw and background_draw?lolsasory wrote:player is on top.Code: Select all
player_draw background_draw
Code: Select all
function background_draw()
love.graphics.draw(bg, background.x, background.y)
end
Code: Select all
function player_draw()
love.graphics.draw(player.image, player.x, player.y)
if love.keyboard.isDown("w")then
player.image = love.graphics.newImage("images/ship02.png") else
player.image = love.graphics.newImage("images/ship01.png")
end
end
Code: Select all
function love.draw()
if gamestate == "menu" then
menu_draw()
end
if gamestate == "playing" then
player_draw()
end
background_draw()
end
Code: Select all
function love.draw()
background_draw()
-- ..etc etc
end
Code: Select all
function love.load()
ship02 = love.graphics.newImage("images/ship02.png")
ship01 ) love.graphics.newImage("images/ship01.png")
-- etc etc
end
Code: Select all
function player_draw()
if love.keyboard.isDown("w")then
player.image = ship02
else
player.image = ship01
end
end
love.graphics.draw(player.image, player.x, player.y)
The memory use will be a bit inefficient, but Lua _is_ garbage-collected and it's not like his code would leave dangling references. I'm more concerned about the performance overhead incurred by constantly reloading the same image from disk (or from the RAM cache, depending on the OS, but it still has to be processed by the CPU).Roland_Yonaba wrote:And , just noticing, do not create new images each frame. That will quickly consume more and more memory.
Instead, load them once, then alternate the picture to be drawn inside love.draw.
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 7 guests