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?
Love game speed
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Love game speed
yes, fps magic.
...more like dt 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
- BrotSagtMist
- Party member
- Posts: 661
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Love game speed
This will run most games on double speed after it was executed anywhere in the code:
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.
Code: Select all
love.timer.stepnorm=love.timer.step
love.timer.step=function() return love.timer.stepnorm( )*2 end
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
Re: Love game speed
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...
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Love game speed
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
- BrotSagtMist
- Party member
- Posts: 661
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Love game speed
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?
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?
obey
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Love game speed
Was there? what method are you talking about though?
Me and my stuff True 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.
- zorg
- Party member
- Posts: 3470
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Love game speed
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 True 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.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 3 guests