Skip to content

Overlay Screens #302

Answered by czyzby
abueide asked this question in Q&A
Discussion options

You must be logged in to vote

Not out of the box, but it's trivial to implement.

KtxGame override

You can store an additional Screen in KtxGame and override render to draw it before the current screen:

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
import ktx.app.KtxGame
import ktx.app.clearScreen
import ktx.app.emptyScreen

class MyGame: KtxGame<Screen>() {
  var baseScreen: Screen = emptyScreen()

  override fun render() {
    clearScreen(0f, 0f, 0f, 1f)
    val delta = Gdx.graphics.deltaTime
    baseScreen.render(delta)
    currentScreen.render(delta)
  }
}

This way you're keeping the base screen logic in a single place, but you do have to mess with the KtxGame API.

Screens composition

You can pass a re…

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by czyzby
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #302 on December 11, 2020 14:15.