1
\$\begingroup\$

I'm currently developing a game using Kotlin and LibGDX. But this Question should be Framework/Engine agnostic. Given I have a Screen class like this:

class MyScreen: Screen {

    private val assetManager = AssetManager()

    private var anyTexture: Texture? = null

    override fun show() {
        assetManager.load("/.../anyTexture.png", Texture.class)
        anyTexture = assetManager.get("/.../anyTexture.png", Texture.class)
    }    

    override fun render(delta: Float) {
        // do rendering
    }

    override fun dispose() {
        assetManager.unload("/.../anyTexture.png", Texture.class)
        anyTexture = null
    }
}

Every Screen I have manages it's own assets.
How would I achieve the same Lifecyle of my assets without using the nullable Type for every asset in the Screen? My Goal is just load all assets when the screen is loaded and then unload them when the game switches to another Screen. Has anybody got an idea for implementing this?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.