Closed maxlund closed 5 years ago
Hi,
I could have mentioned that in a comment, you are right :) dispose() in this case is actually doing nothing because all disposable things are created in the Main game class and get disposed when the game shuts down.
The lines were added mainly as a safety in case LoadingScreen or MainScreen are creating resources that need to be disposed. Since dispose does not get called automatically when you switch screens, I just wanted to make sure to call them for the "One time" screens that are only used once and get removed after we switch away from them.
But again, in the example you can simply remove the call. It does not make any difference.
Regards Simon
Ah okay, thanks for the quick answer and for clarifying that "dispose does not get called automatically when you switch screens".. good to know i should override the method and make sure to dispose of any resources before i switch screens! :)
Personally I never needed the screen dispose method because nowadays I just use the libktx context that I create and dispose in the Game class. The context contains the assetmanager, spritebatch and other disposables that then get automatically disposed when calling context.dispose().
I think especially for small games it makes it very easy and convenient.
For big games I can imagine this is not the best practice as you will need to keep all your resources in memory all the time which might not be good.
But for me it was always small pixelated games so keeping those ~50MB resources in memory is not an issue at all and therefore there was no need for a releasing/reallocating of resources during the lifetime of the game ;)
If you aim for a small game then I would recommend that approach first as it makes it way easier.
Sounds good! I didn't look into using injection provided by libktx yet, I'm going through java based documentation and tutorials (like your own on YT), but writing everything in kotlin.. Hopefully can get into using libktx more when I get comfortable with the fundamentals :)
I will close this issue then, ok?
for further questions feel free to contact me here or via quillraven@gmail.com
Hey! Thanks for the helpful introduction guide to libktx!
I'm wondering about the calls to dispose() in LoadingScreen/MainMenuScreen, they are not doing anything since they are just
override fun dispose() = Unit
inKtxScreen
.and in MainMenuScreen before it got renamed here:
and in LoadingScreen after it got renamed: