Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit update frequency. #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bird12/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ function love.load()

-- initialize mouse input table
love.mouse.buttonsPressed = {}

-- limit framerate
min_dt = 1/60
next_time = love.timer.getTime() + min_dt
end

function love.resize(w, h)
Expand Down Expand Up @@ -155,6 +159,15 @@ function love.mouse.wasPressed(button)
end

function love.update(dt)
local cur_time = love.timer.getTime()
if cur_time < next_time then
return
end
next_time = cur_time + min_dt
if dt < min_dt then
dt = min_dt
end

if scrolling then
backgroundScroll = (backgroundScroll + BACKGROUND_SCROLL_SPEED * dt) % BACKGROUND_LOOPING_POINT
groundScroll = (groundScroll + GROUND_SCROLL_SPEED * dt) % VIRTUAL_WIDTH
Expand All @@ -167,11 +180,12 @@ function love.update(dt)
end

function love.draw()

push:start()

love.graphics.draw(background, -backgroundScroll, 0)
gStateMachine:render()
love.graphics.draw(ground, -groundScroll, VIRTUAL_HEIGHT - 16)

push:finish()
end
end