Tuesday, September 23, 2014

Never give up, never surrender!

SO FINALLY!

I remade the whole screen architecture for the game, with a solid hashmap to store all the different screens that our game will have (splash, main menu, game, highscores etc.).

The code was pretty much straightforward, and I did not hit any bumps, it was just a lot of code to be switched, updated and added. Until I wanted to jump some with the frog. It was gone.

A quick debug session made me realise that the delta value that was being fed to update was way off. The update is using the delta time which is the last time since the a frame was rendered. This delta time value makes the game logic run the same on a device with 12 fps as a device with 60 fps. But as I said it was crazy high. It should be a value of about 0.015 seconds, instead it was counting seconds and going up.

Since I remade the architecture of a lot of update and render methods, I no longer had update(float delta) methods, all my update methods took no variables in the parameters. So I created the delta time using

delta += Gdx.graphics.getDeltaTime();

which is pretty bad because it basically just says how long the game had been running, or since the delta value was resetted.

It took me however a solid 30-40 minutes to figure out this stupid error. Mainly because I am tired. But the solution.


This returns the correct delta value, it prints the smallest value between the .getDeltaTime(), which is when the last frame was added, and 1/60, which forces it to be 60 fps, if needed.

Anyway, the architecture is taking its final form.