New to Fuse4-want a Faery Tale Adventure like game
-
To make the music play at constant speed no matter the FPS, you need to incorporate the measured frame rate into account somehow. The length in second of the previous frame is returned by deltaTime(). Care needs to be taken: it will not be exactly 1/60 if you hit 60 fps and 1/30 if you drop to 30 fps. Even in the best case, it is going to fluctuate a little around 1/60. The playback code should cope with that.
What I tried, and it worked, is to modify the playMelody function near the bottom. Before it, I declare a global variable:
melodyRemainder = 0.0
And in the body, I replace
melodyTimer += melodyTempo
with this:
melodyRemainder += deltaTime() * 60 // take into account actually passed time melodySteps = floor(melodyRemainder) // take only integer part if melodySteps < 1 then melodySteps = 1 endIf // advance at least one step melodyRemainder -= melodySteps // keep balance for next frame melodyTimer += melodyTempo * melodySteps
If you hit 60 FPS, even if deltaTime fluctuates, melodySteps will be 1 almost all of the time, so no change. And if you hit 30 FSP, deltaTime() will be about 2, so will melodySteps.
Or, if you prefer it to be simpler, you can omit the melodyRemainder variable and just do
melodyTimer += melodyTempo * deltaTime() * 60
This might even be better, depending on how sound and video output interact timing wise. Go with the simpler version first and switch to the more complicated one only if the simple version doesn't work for you.
Regarding the map: Make sure it is really the map rendering. Just because you jump from 30 to 60 FPS if you disable it says nothing; maybe the map rendering takes 1 ms and the rest of your main loop takes 16 ms, just fast enough to allow 60 FPS, and the map rendering just pushes you over the edge. You can test that by not removing the map rendering, but replacing it with
sleep(0.008) // 8 ms of sleep
If you still get 60 FPS with that, you know the map rendering takes more than about 8 ms and yeah, you'll need to do something about that.
But if you drop to 30 FPS, you know the rest of your main loop takes more than about 8 ms and that's where you're more likely to find improvement opportunities.
You can play with the 0.008 parameter to get a better feel for where the problems lie.If it is indeed the map rendering, there would be one way to deal with it without splitting the map. Instead of rendering the map to the screen, you render a section of the map, say of size 3x3 screens, into an image. That image is then what you render to the screen. Since it is larger than the screen, you can scroll around in it quite a bit before you hit the edge; until you do so, you do not have to refresh it from the map. Of course, every time you do have to refresh the image, there will be a short, but noticeable, pause. And any chance to maybe put sprites behind map objects is lost. I'd just split the map up, I think.
(Well, no. I would try to implement the metatile system, fail miserably and give up.) -
@Z-Mann thank you for your analysis!
I tried the simple fix (1 line approach) and the note freq music played normally at 60 FPS so that fixed that issue.
I inserted the sleep (0.008) statement and removed load / draw map statements and the FPS did stay at 60 FPS so that tells me it’s a draw map issue. Perhaps with the music sounding right again, the game appears to be ok at 30 FPS. Is it ok to have it at 30 FPS or should it always be close to 60 FPS?
I’m heading on vacation in the morning to Ohio for a few days so I won’t be able to work on this until Friday.
Thank you again!
-
If you do manage to hold 30 FPS to the end, it should be fine. It's a slow paced game. The original ran at 20 FPS at most, going by memory and feeling, and that was not an issue. Focus your attention to things that matter more.
-
Hi All! I haven’t left the site but experienced a job loss which turned into a transfer and promotion within my company. I have moved with my wife to Utah from Illinois and have been tied up with my new role and purchasing a house. I will continue with my FUZE4 FTA like game in February or March once we close on the house. (Tim)
-
Sounds busy! Good look with everything you're doing, and happy coding (once you got time for it again, that is)
-
Glad you haven’t left, Tim. Congrats on the promotion!