function drawCharacter()
if love.keyboard.isDown("up") then
print("up")
for rowIndex = 1, #tileTable do
local row = tileTable[rowIndex]
for columnIndex = 1, #row do
local char = row[columnIndex]
if tileTable[rowIndex][columnIndex] == 'C' then
print("C")
--local x = (columnIndex)*tileW
--local y = (rowIndex)*tileH
love.graphics.drawq(tileset, quads['C'], (columnIndex-2)*tileW, (rowIndex-1)*tileH)
end
end
end
end
end
My thought process here is to make a function that reads where the character is currently at (C) and then draws the character ('C' in quad) at a block that's one above (columnIndex-2).
My problem is that nothing changes on the screen when I press up. The console print commands work fine.
An immediate problem that I see: You can only call love.graphics function from within love.draw().
Is this function run in love.draw()?
EDIT: Looking again I see you are checking the keyboard state, you will likely need to do this every frame. I would assign the function to a variable and call it in love.update() so that any function can access the keyboard state. Example:
Ensayia wrote:You can only call love.graphics function from within love.draw().
That's not the complete story. You can only call love.graphics functions that actually draw something within love.draw(). This is because of this code inside love.run():
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear()
if love.draw then love.draw() end
end
love.update() is called, then everything on-screen is cleared. Then everything is re-drawn. This is why you can't draw anything inside love.update()*.
*Unless of course you redefine love.run(). But drawing in love.update() is a very bad practice.
I decided to change it about and now I'm using two layers, the second layer has the character on it and blank (transparent) tiles for everything else.
However, when I run the code, I only see layer 2 (it's drawn after) and the blank tile spots are just black (which is the LOVE2D background because Layer 1 is no longer being drawn)