|
Post by rosy on Apr 14, 2021 5:33:48 GMT -6
1. How does the FPS function work? 2. Can I handle two mice?
|
|
|
Post by johnno56 on Apr 14, 2021 16:59:17 GMT -6
Hi Rosy As I had never used the FPS() function before, I figured that since you asked, I would give it a try... lol DrawText("FPS " + str(fps()), 0, 0) Note: DrawText() requires that a font be preloaded as well as a colour. Although: using a simple Print fps() would also work. But it seems that fps() only 'reports' the current FPS. I do not think there is a way to use this command to actually 'set' the FPS... But I have been wrong before... lol I have attached a screenshot of my platformer with the added FPS (bottom left)...
|
|
|
Post by n00b on Apr 19, 2021 21:25:25 GMT -6
1. How does the FPS function work? It just reports the number of times the screen is drawn each second. 2. Can I handle two mice? No
|
|
|
Post by rosy on Apr 20, 2021 9:54:29 GMT -6
But how does it count? Counts Updates and divides the program runtime from its launch? Only in a loop? Or else ...
|
|
|
Post by n00b on Apr 21, 2021 21:52:20 GMT -6
It counts the number of times UPDATE() runs per second.
|
|
|
Post by rosy on Apr 22, 2021 1:39:36 GMT -6
From the beginning of the program, or in some recent period of time?
I entered:
Update print FPS
displayed 0
|
|
|
Post by n00b on Apr 22, 2021 10:46:33 GMT -6
Your program needs to run for atleast 1 second before you call FPS to get an accurate count.
|
|
|
Post by rosy on Apr 23, 2021 8:24:05 GMT -6
We can't get along with something.
In any case, the FPS value was different than in my tests.
|
|
|
Post by johnno56 on Apr 23, 2021 17:03:07 GMT -6
Hi Rosy,
It goes without saying that, the FPS value will be different on pretty much each computer, because CPU speeds are generally different. If you want your game to run at the same speed on most machines, then you may have to include a "Delta Time" routine.
Bplus, of the QB64 community, game me such a routine. It is quite simple and seems to work well... (it does for me... lol)
Function updatedelta() delta = (Timer - timedelay) * 0.001 timedelay = Timer End Function Call this function from within your 'game loop'. Make sure that it is the first thing the game loop executes, then your game should run at the same speed on just about any machine... (you may have to initialize the variable 'timedelay')
I hope this helps.
J
do clearcanvas updatedelta() <------- updateLevel() updateObjects() updatePlayer() checkExit() hud() wait(60) update() if key(k_escape)<>0 then gameover = 1 exit do end if loop until nextlevel = 1 This is how I used it in one of my games....
|
|
|
Post by rosy on Apr 24, 2021 2:37:49 GMT -6
The FPS difference is mainly due to the screen refresh rate. And again you write off topic ...
Just inserting this routine of yours won't do anything. There is still something to be done about this delta. BUT you can expect trouble anyway. The use of Wait must also be carefully considered. I just wrote the whole article about it ...
A ha ... And it makes no sense to use the same delta formula in every game. This delta affects the speed of movement. For example, in Ping-Pong I multiplied by 0.01, in your example it is 0.001, which is 10 times slower movement.
|
|
|
Post by johnno56 on Apr 24, 2021 3:23:22 GMT -6
Again? My apologies for the inconvenience.
|
|
|
Post by tbird on Apr 24, 2021 20:10:13 GMT -6
I'm pretty sure we went over this already when we put delta time in Johnno56 game. The 0.001 is not an arbitrary number that you change its because it's 1/1000 as in 1000 MS in a second....to use Deltatime you would have the function for it but need to multiply all movements by delta then multiply again with your desired speed, so yes it applies to every game, and will provide the same amount of pixels per second on every machine regardless of refresh rate.
|
|
|
Post by rosy on Apr 25, 2021 0:42:46 GMT -6
Was this supposed to be a polemic with me? Little did I understand ... Are you saying that it must be 1/1000 and not 1/100?
|
|
|
Post by tbird on Apr 25, 2021 7:18:49 GMT -6
I suppose it wouldn't have to be division by 1000, I find it easier to work with and understand but 100 would be the same as your speed variables could just adjust. If the character speed variable in my game is 250, it would simply have to be 25 using the dt setup you have in your blog, and after reading it, you obviously know how this all works anyways. So my comment is pointless anyways....oh well.
I do like your function on limiting the frame rate to 60, makes for a consistent experience.
|
|
|
Post by rosy on Apr 25, 2021 8:07:20 GMT -6
Of course I adjusted dt to the previously adopted speeds ... You did a lot of unnecessary things. You came up with a multiplier of 1/1000, although there is no reasonable explanation for just such a value (it makes sense to assume dt = 1). Then you had to adjust the speed of each object to this value, and it was enough to choose the appropriate dt value and leave the rest unchanged.
You were probably talking about the game Attak. I'm surprised it didn't crash in the beginning because you initially set timeDelay = 0, so deltaTime was huge at first, so the initial speed of the objects should be huge too.
Also, like I said, you shouldn't update the dt value in every run of the loop.
|
|