Love game speed

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
lispercat
Prole
Posts: 3
Joined: Sat Oct 30, 2021 1:28 pm

Love game speed

Post 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?
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Love game speed

Post 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 :P
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: Love game speed

Post 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.
obey
lispercat
Prole
Posts: 3
Joined: Sat Oct 30, 2021 1:28 pm

Re: Love game speed

Post 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...
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Love game speed

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: Love game speed

Post 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? :D
obey
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Love game speed

Post 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?
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
lispercat
Prole
Posts: 3
Joined: Sat Oct 30, 2021 1:28 pm

Re: Love game speed

Post 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
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Love game speed

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests