Hey
So this is sorta a basic question:
Until now I have been doing all my coding in the love.update() function but i began to think "If this was being played on a much faster computer that could manage a faster frame rate wouldn't the game be played much quicker to because it would be updating far faster" ?
if i say as long as the mouse is down change X by 3 this will happen every frame but if the frame rate is higher it will happen faster???
if this is True how do you work around it
Frame Rate Questions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Frame Rate Questions
Yes, you have to take into account delta(dt) which is the time elapsed between updates.
So instead of change X by 3 you would write change X by (3*dt)
where 3 is the speed (3 units, usually pixels, per second)
and dt is delta in seconds
So instead of change X by 3 you would write change X by (3*dt)
where 3 is the speed (3 units, usually pixels, per second)
and dt is delta in seconds
Re: Frame Rate Questions
dt is the elapsed time. So, if one call is made 0.1 seconds after the previous, that code would move the player 0.3 pixels on position; so, in the end, after all the different times we can have, the player will always move 3 pixels on one second, whatever machine it is played on
Re: Frame Rate Questions
Hey folks,
I've a similar question. Suppose you have a function which contains an array and a counter to drive its index. The function is called randomly by the user. The functionality you’re looking for is to cycle trough the array elements each time a frame is drawn, that is, we get element number 1 (index = 1) of the array at frame 1, we get element number 2 (index = 2) at frame 2, and so on.
Here, we need the counter to update after every dt time, but the counter can’t be a direct function of dt, as we strictly need integer values (incremented in exactly 1 unit) to drive the indices of our array. How would you do that?
I've a similar question. Suppose you have a function which contains an array and a counter to drive its index. The function is called randomly by the user. The functionality you’re looking for is to cycle trough the array elements each time a frame is drawn, that is, we get element number 1 (index = 1) of the array at frame 1, we get element number 2 (index = 2) at frame 2, and so on.
Here, we need the counter to update after every dt time, but the counter can’t be a direct function of dt, as we strictly need integer values (incremented in exactly 1 unit) to drive the indices of our array. How would you do that?
Re: Frame Rate Questions
If I understand correctly, then can't you just increment the counter in love.update(dt)?
I'm a little confused by what exactly you're looking for. Give an example.
Code: Select all
array = {--[[stuff]]}
function A()
return array[index]
end
function love.update(dt)
index = index + 1
end
Re: Frame Rate Questions
Hey MarekkPie,
I’ll tell you why I’m asking this. In the game I’m working on, I wanted to give the illusion of a “smooth” character jump; I decided to move the player along the Y axis according to a free fall formula, a parabola.
Anyway, I computed the Y points needed for this and stored them in an array, so each time the “jump” function was called the character was translated to a Y position according to the Y values in my array. The character needed to move one position exactly on each new frame, so I was a little bit unsure of how to do this, hence my previous question.
What I ended up doing was exactly what you posted, but I was wondering if there is an alternate method for achieving this.
I’ll tell you why I’m asking this. In the game I’m working on, I wanted to give the illusion of a “smooth” character jump; I decided to move the player along the Y axis according to a free fall formula, a parabola.
Anyway, I computed the Y points needed for this and stored them in an array, so each time the “jump” function was called the character was translated to a Y position according to the Y values in my array. The character needed to move one position exactly on each new frame, so I was a little bit unsure of how to do this, hence my previous question.
What I ended up doing was exactly what you posted, but I was wondering if there is an alternate method for achieving this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Frame Rate Questions
You could use dt.
See math.floor for more information.
Code: Select all
function A()
return array[math.floor(index)] -- this is the trick that makes it work
-- it rounds index to the nearest smaller-or-equal integer.
end
function love.update(dt)
index = index + dt * speed
end
Help us help you: attach a .love.
Re: Frame Rate Questions
The counter can be float, only array index should be integer. So:verilog wrote:Here, we need the counter to update after every dt time, but the counter can’t be a direct function of dt, as we strictly need integer values (incremented in exactly 1 unit) to drive the indices of our array. How would you do that?
Code: Select all
char=Char[math.floor(counter)]
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
Re: Frame Rate Questions
Depending on his system speed, just flooring dt might skip or repeat frames and whatnot. For example, an average dt of 1.5 would give him:
I think the only way to guarantee a number will give you the correct integer value is if you increment it by an integer. At which point just having a separate integer-based counter is best.
Code: Select all
First pass:
array[math.floor(dt)] or array[1]
Second pass:
array[math.floor(dt * 2)] or array[3]
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Frame Rate Questions
You know, if dt is 1.5, you have an FPS of 0.67. Skipping frames is not your worst problem then.MarekkPie wrote:Depending on his system speed, just flooring dt might skip or repeat frames and whatnot. For example, an average dt of 1.5 would give him:
Help us help you: attach a .love.
Who is online
Users browsing this forum: No registered users and 200 guests