[Solved] Yet another frame rate-related question
Posted: Wed Aug 31, 2011 6:17 pm
I'm new to LOVE and these forums(and to Lua, really), but I decided to see what's up and try to program a few simple things. Like others, I assume, I soon ran into a slight problem regarding timing and frame rates.
After searching around this forum a little, I found that you can somewhat limit the frame rate by using the love.timer.sleep() according to dt. I also have been using dt in all my update functionality(update object movement, etc) as is recommended to do.
I have two problems with both of these scenarios. Basically, I have a player on the bottom of the screen that shoots bullets towards the top when you hold down the z button. For testing purposes, these bullets contain an event to make them veer to the right after a certain amount of time has passed.
The first problem is that as more bullets are drawn on the screen, the game's frame rate begins to slow down(I'm not using sleep(), I'm outputting 1/dt onto the screen). LOVE seems to want to stay at about 1000 updates per second, but once I have around ten or so bullets on the screen, it slows down to like 200. I obviously only want 60; maybe then it would be drawing at a constant rate.
That might not be as much of a problem if not for this second element. I'm giving the bullet objects a table to list events that modify its behavior - such as "at step 20, make y-speed 50". Each bullet keeps its own timer, which(at the moment) increments by 100*dt each time the bullet is updated. My current approach to this is: if the timer has exceeded the frame of the event between this update and the previous one, then execute the event.
The clear problem with this is that now when I fire a stream of bullets, they all end up at different y-positions(that is, they go up, then veer directly right at "step" 20, but plus or minus a couple of pixels). If I'm going to make patterns of bullets that require timing precision, this is going to cause everything to be off a bit. And since I obviously can't be sure about the value of dt every single frame, I can't get it so that a bullet's timer ends up exactly on every whole number.
Does anyone have any advice? Is LOVE suited to something that requires a bit more timing like this? I can upload my .love file if needed. I'm not too familiar with the language yet, so some of this might sound a little strange; if it does, I'll try and clarify it.
After searching around this forum a little, I found that you can somewhat limit the frame rate by using the love.timer.sleep() according to dt. I also have been using dt in all my update functionality(update object movement, etc) as is recommended to do.
I have two problems with both of these scenarios. Basically, I have a player on the bottom of the screen that shoots bullets towards the top when you hold down the z button. For testing purposes, these bullets contain an event to make them veer to the right after a certain amount of time has passed.
The first problem is that as more bullets are drawn on the screen, the game's frame rate begins to slow down(I'm not using sleep(), I'm outputting 1/dt onto the screen). LOVE seems to want to stay at about 1000 updates per second, but once I have around ten or so bullets on the screen, it slows down to like 200. I obviously only want 60; maybe then it would be drawing at a constant rate.
That might not be as much of a problem if not for this second element. I'm giving the bullet objects a table to list events that modify its behavior - such as "at step 20, make y-speed 50". Each bullet keeps its own timer, which(at the moment) increments by 100*dt each time the bullet is updated. My current approach to this is: if the timer has exceeded the frame of the event between this update and the previous one, then execute the event.
The clear problem with this is that now when I fire a stream of bullets, they all end up at different y-positions(that is, they go up, then veer directly right at "step" 20, but plus or minus a couple of pixels). If I'm going to make patterns of bullets that require timing precision, this is going to cause everything to be off a bit. And since I obviously can't be sure about the value of dt every single frame, I can't get it so that a bullet's timer ends up exactly on every whole number.
Does anyone have any advice? Is LOVE suited to something that requires a bit more timing like this? I can upload my .love file if needed. I'm not too familiar with the language yet, so some of this might sound a little strange; if it does, I'll try and clarify it.