Code: Select all
textToggle = not textToggle
EDIT: Ninja'd, this applies to MarekkPie's post.
Code: Select all
textToggle = not textToggle
Clever on the toggle.bartbes wrote:I'd like to note that the toggle function in your post is unneeded and inefficient, this works:As for why the love.draw example was "wrong", it's because the purist view says draw should really only draw, and not do any "thinking", specifically not mess with anything not directly related to drawing. In this case, the draw code only needs to know if something is drawn, and isn't "supposed to" care about when that happens, just if it happens.Code: Select all
textToggle = not textToggle
EDIT: Ninja'd, this applies to MarekkPie's post.
Code: Select all
function love.draw()
-- Scenario A
if toggle then
love.graphics.print(...)
end
-- Scenario B
if love.keyboard.isDown("p") then
love.graphics.print(...)
end
end
Code: Select all
function love.update(dt)
if love.keyboard.isDown("p") then
textToggle = true
else
textToggle = false
end
end
function love.draw()
if textToggle then
love.graphics.print(...)
end
end
I believe that the general idea in separating draw and update is that you want everything to be "caught up" when you draw it. You don't draw some stuff, work through some physics, and then draw some more stuff. You separate heavy logic and rendering apart, so that the render gives you as close to an instantaneous snapshot as possible. Working through some booleans is close to free on a modern computer, but running AI and physics... well, that could cause things to get out of sync.MarekkPie wrote: But to me, that's going WAY out of your way to do something just to follow some made-up convention. If you decided to run some huge algorithm inside love.draw(), I understand, but , I mean, c'mon. (bartbes: you used quotes around wrong, so you might not agree with the purist viewpoint. But I'm just trying to understand why.)
Code: Select all
function love.update(dt)
textToggle = love.keyboard.isDown("p")
end
function love.draw()
if textToggle then
love.graphics.print(...)
end
end
Well said!bartbes wrote:... What if you hardcode this check in love.draw now, and you decide you want to turn it on with something else? You'll have to modify love.draw ...
It's hardcode, and it's basically the programmer making assumptions that might not hold later.MarekkPie wrote:Sorry to keep this on the offtopic, but what exactly do you mean by "hardcore"? (Only started programming three months ago.)
Code: Select all
function moveLeft(player, dt)
player.x = player.x + 2.5*dt
end
function moveUp(player, dt)
player.y = player.y + 0.5*dt
end
Code: Select all
horizontalSpeed = 2.5
verticalSpeed = 0.5
...
function moveLeft(player, dt)
player.x = player.x + horizontalSpeed * dt
end
function moveUp(player, dt)
player.y = player.y + verticalSpeed * dt
end
Users browsing this forum: Google [Bot] and 3 guests