In libgdx, screen.setScreen()
doesn't call dispose automatically right. Inside a overridden setScreen, do I have to call screen.dispose
first and then call super.setScreen
or call the later first?
I know this may seem like duplicate question but still I wanted to know because super.setScreen
calls screen.hide
. Is calling hide
after dispose
run-time safe?
Is it a bad practice?
I am making a 3D game based on this and this example .
Here I am extending GameName
class by Game
and trying to override setScreen
so as to call dispose if screen is not null and then call super.setScreen
.
screen.dispose()
is never called by LibGDX. You must do it manually yourself before dropping the reference to your screen. If you don't plan to reuse the Screen instance, having screen.hide()
call screen.dispose()
is the perfect place to do it.
screen.hide()
is never called in response to Android events.
I don't recommend overriding game.setScreen()
to dispose of screens unless you know for sure you never want to reuse any screen instances. In most simple games, you do want to reuse them rather than waste time unloading and reloading assets repeatedly.