Page 1 of 1
Love game speed
Posted: Sat Oct 30, 2021 1:32 pm
by lispercat
In last LOVE api there is an option for speed of game and apps.
And now I see it removed. How can I change speed for snake for example? FPS magic?
Re: Love game speed
Posted: Sun Oct 31, 2021 6:41 am
by Gunroar:Cannon()
yes, fps magic.
Code: Select all
love.update(dt)
snake.y = snake.y + snake.speedy*dt
snake.x = snake.x + snake.speedx*dt
end
increaseSpeed()
snake.speedy = snake.speedy+10
snake.speedx = snake.speedx + 10
end
...more like dt magic
Re: Love game speed
Posted: Sun Oct 31, 2021 7:07 am
by BrotSagtMist
This will run most games on double speed after it was executed anywhere in the code:
Code: Select all
love.timer.stepnorm=love.timer.step
love.timer.step=function() return love.timer.stepnorm( )*2 end
This function generates dt in the normally invisible main loop.
It does fail when the game uses the framerate instead of time to calculate its speed. These games will fail on different hardware too tho.
Re: Love game speed
Posted: Sun Oct 31, 2021 3:08 pm
by lispercat
dt is some time parameter? I never used it. About timer it's strange. I try it, and now my snake mobe like 1 tile on 5 seconds...
Re: Love game speed
Posted: Sun Oct 31, 2021 5:33 pm
by Gunroar:Cannon()
dt is delta time. The parameter in love.update(dt). It can also be gotten with love.timer.getDelta(). Lets say the game is at 60 frames every 1 second. dt would be more or less equal to 1/60. So that in 60 updates all the dts add up to 1 second. Want something to move a certain distance in one second? You multiply the difference in positions by the dt.
Code: Select all
--pos is x and y
diffPos = goal.pos-object.pos
object.pos = object.pos + diffPos*dt
--e.g. for x:
diffX = goal.x-object.x
object.x = object.x + diffX*dt
--Just a simple example on how dt works
Re: Love game speed
Posted: Sun Oct 31, 2021 5:44 pm
by BrotSagtMist
It stands for delta time, the time between two frames.
To make this absolute clear: Without using delta time your game will only work on your own computer. Different computers have different refresh times ranging from 30 to 400 times a second, so in the worst case it can run 10 times slower for other ppl.
For quick fix in your game logic you simply need multiply by your own refresh rate (the hrtz of your monitor), say 60:
snake.y = snake.y + snake.speedy*dt*60
Edit: Ninjad by the cannon, did i fell asleep during writing?
Re: Love game speed
Posted: Sun Oct 31, 2021 6:56 pm
by zorg
lispercat wrote: ↑Sat Oct 30, 2021 1:32 pm
In last LOVE api there is an option for speed of game and apps.
And now I see it removed.
Was there? what method are you talking about though?
Re: Love game speed
Posted: Mon Nov 01, 2021 3:41 pm
by lispercat
zorg wrote: ↑Sun Oct 31, 2021 6:56 pm
lispercat wrote: ↑Sat Oct 30, 2021 1:32 pm
In last LOVE api there is an option for speed of game and apps.
And now I see it removed.
Was there? what method are you talking about though?
seconds with ms type. I can't now use something less then 1
Re: Love game speed
Posted: Wed Nov 03, 2021 7:38 am
by zorg
lispercat wrote: ↑Mon Nov 01, 2021 3:41 pm
zorg wrote: ↑Sun Oct 31, 2021 6:56 pm
lispercat wrote: ↑Sat Oct 30, 2021 1:32 pm
In last LOVE api there is an option for speed of game and apps.
And now I see it removed.
Was there? what method are you talking about though?
seconds with ms type. I can't now use something less then 1
The name of the function please; whatever function exists that takes seconds as parameter, you can probably give it decimals, like 0.020 or whatever... but i don't think there was ever any... unless you mean love.timer.sleep, which is not something you should use for that anyway.