function love.update(dt)
if love.mouse.isDown(1) then
function love.draw()
love.graphics.setColor(0,255,0,255);
love.graphics.printf("LMB: "..tostring(input.mouse.down.left),1,1,200,"left");
end
end
end
Hello, guys. I'm new in LÖVE2D, but i'm experienced with LUA.
I just want to know if this function will create a lot of labels or just 1.
I guess it's going to create labels, but anyway... i don't know how this function works in LÖVE2D.
Could someone help me? Thank you.
It's only going to print that variable once every frame; every frame the screen also gets cleared, so it will only make one. Every LÖVE function that prints/draws something to the screen works that way.
Welcome anyway
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
it redefines love.draw every frame though, and the "if" won't work that way; the first time you press the mouse button it sets love.draw to draw the text every frame and you never change it back.
function love.draw()
if love.mouse.isDown(1) then
love.graphics.setColor(0,255,0,255);
love.graphics.printf("LMB: "..tostring(input.mouse.down.left),1,1,200,"left");
end
end
also there are no "labels" and nothing is "created". love.graphics.print[f] just draws something once (one frame) and doesn't create or save anything.
local trigger = false
function love.update(dt)
if love.mouse.isDown(1) then
trigger = true
else
trigger = false
end
end
function love.draw()
if trigger then
love.graphics.setColor(0,255,0,255);
love.graphics.printf("LMB: "..tostring(input.mouse.down.left),1,1,200,"left");
end
end
Or you could put the mouse button testing inside love.draw too, but that's considered bad practice, since it will combine logic with rendering.
EDIT: Ninjad
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Alright!
Thanks for the nice reception!
Also, how does the window width/height works?
I would like to set a label in the right-top corner of the game screen.
How could i do that?
local label = "I AM NOT A LABEL :3"
local width = love.window.getWidth()
function love.draw()
love.graphics.printf(label, width, 0, width/2, 'right') -- string, x, y, limit, alignment (and other optional stuff after)
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.