So I started playing around with this doing my own basic sample code and I noticed that pretty much no matter what I my scripts start to experience 2~3 second delay between input and changes after around 20 seconds of runtime.
Here is my basic sample code:
-- Globals, becuase Lua is silly like that
num = 15
time = 0
text = 'wtf'
x = 100
y = 100
--Updates
function love.update()
end
--Checks Input
function love.keypressed(k)
if k == 'left' then
time = love.timer.getTime()
end
if k == 'w' then
y = y - 5
end
if k == 's' then
y = y + 5
end
if k == 'a' then
x = x - 5
end
if k == 'd' then
x = x + 5
end
end
--Draws to scren
function love.draw()
love.graphics.setFont(love.graphics.newFont(18))
love.graphics.print('Hello World!', 400, 300)
love.graphics.print(num, 200,200)
love.graphics.print(time, 400,320)
love.graphics.print(text, x,y)
end
------
Does anyone know what I might be doing to cause this or anyway to prevent/fix this rather annoying bug I seem to be experiencing? Would greatly appreciate any help on the topic. I do not experience any such lag when running any of the demos regardless of run-time so I feel it must be something I'm doing. Thanks again!
Delay while running after around 20 seconds
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Delay while running after around 20 seconds
First of all, please use the code tags in the future, it makes it much easier to help you. Second of all, your bug was because you were creating a new font with every frame drawn. Here's my revised code:
As you can see, I moved a few things into love.load(), and did some minor housekeeping. I would advise avoiding the word time, I'm pretty sure it's a reserved word. Also, you will want to start looking into dt next, it'll help you uncouple movement from keypresses.
Code: Select all
function love.load()
love.graphics.setFont(love.graphics.newFont(18))
num = 15
thetime = 0
text = 'wtf'
x = 100
y = 100
end
function love.update(dt)
-- nothing, but isDown could be used here for smoother movement
end
function love.keypressed(k)
if k == ' ' then
thetime = love.timer.getTime()
end
if k == 'w' then
y = y - 5
end
if k == 's' then
y = y + 5
end
if k == 'a' then
x = x - 5
end
if k == 'd' then
x = x + 5
end
end
function love.draw()
love.graphics.print('Hello World!', 400, 300)
love.graphics.print(num, 200,200)
love.graphics.print(thetime, 400,320)
love.graphics.print(text, x,y)
end
Kurosuke needs beta testers
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Delay while running after around 20 seconds
Nope. os.time() is a standard library function though.tentus wrote:I would advise avoiding the word time, I'm pretty sure it's a reserved word.
Help us help you: attach a .love.
Re: Delay while running after around 20 seconds
Lua is not silly:Kantos wrote:-- Globals, becuase Lua is silly like that
num = 15
time = 0
text = 'wtf'
Code: Select all
-- Script locals
local num = 15
local time = 0
local text = 'wtf'
But of course there are better ways to organize your code.
Cheers,
Andre
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests