Hello,
sorry for a noobie question, but I've recently started learning game development and got stuck with an issue that I don't understand: why character or any other object movement works gradually. If we take this simple code:
Code: Select all
rectDY = 500
function love.update(dt)
if love.keyboard.isDown('w') then
rectY = rectY - rectDY *dt
elseif love.keyboard.isDown('s') then
rectY = rectY + rectDY *dt
end
end
function love.draw(dt)
love.graphics.rectangle('fill', paddleX, paddleY, 30, 50)
end
the rectangle will gradually move if I press W or S moving smoothly up and down. Now as I see this - update is beng called each frame, thus in case of 60 fps it will be called 60 times. If it's called 60 times, I thought that the rectangle would jump by 500*dt for 60 times per second, like I pressed the button once, it disappeared from initial position, and instantly appeared in a new rectY position - to 500*dt. Instead it slowly and gradually moves up and down, which is correct, but why is it working this way? Can someone please explain me this behaviour? Thank you!