I think you should keep trying. This is something essential which you'll need again and again.
love.graphics.getWidth() is the width of the screen, so love.graphics.getWidth()/2 is the exact middle of the screen, along the x-axis. love.graphics.getHeight()/2 is the exact middle along the y-axis.
So drawing a circle there will center it perfectly:
Code: Select all
function love.draw()
love.graphics.setColor(255,255,255,255)
love.graphics.circle("fill", love.graphics.getWidth()/2, love.graphics.getHeight()/2, love.graphics.getHeight()/2)
end
Now, if you want to draw a rectangular image instead, it's origin is usually the upper left corner of the image. So instead of drawing it in the center, you need to draw it a little further to the top and left. By "a little", I mean exactly half the width and height of the image, which is what you were trying to do with the offset variables.
Try:
Code: Select all
function love.draw()
love.graphics.setColor(255,255,255,255)
love.graphics.draw(map, love.graphics.getWidth()/2 - map:getWidth()/2, love.graphics.getHeight()/2 - map:getHeight()/2)
end
Of course, love.graphics.getWidth()/2 - map:getWidth()/2 can be rewritten as: (love.graphics.getWidth() - map:getWidth())/2
which saves you a division (speeeed!)
If it's not working, please post more of your code!