Experiment with creating buttons for a main menu

This commit is contained in:
2026-02-20 13:07:17 +00:00
parent 64af2ed168
commit 01da51665e
4 changed files with 55 additions and 4 deletions

View File

@@ -7,7 +7,6 @@ dependencies {
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.github.kotcrab.vis-ui:vis-ui:$visUiVersion"
api "io.github.libktx:ktx-actors:$ktxVersion"
api "io.github.libktx:ktx-ai:$ktxVersion"
api "io.github.libktx:ktx-app:$ktxVersion"

View File

@@ -15,8 +15,10 @@ class Main : KtxGame<KtxScreen>() {
override fun create() {
KtxAsync.initiate()
addScreen(FirstScreen())
setScreen<FirstScreen>()
// addScreen(FirstScreen())
// setScreen<FirstScreen>()
addScreen(MainMenu())
setScreen<MainMenu>()
}
}

View File

@@ -0,0 +1,50 @@
package com.iofferyoutea.WitchQueen
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import ktx.app.KtxScreen
import ktx.app.clearScreen
import ktx.assets.toInternalFile
import com.badlogic.gdx.graphics.Texture.TextureFilter.Nearest
import com.badlogic.gdx.scenes.scene2d.ui.Skin
class MainMenu : KtxScreen {
val table = Table().apply {
setFillParent(true)
debug = true
}
val stage = Stage().apply {
Gdx.input.inputProcessor = this
addActor(table)
}
val mySkin = Skin("uiskin.json".toInternalFile())
val textureRegion = TextureRegion(Texture("default.png").apply { setFilter(Nearest,
Nearest
)} )
val buttonFont = BitmapFont("default.fnt".toInternalFile())
val style = TextButton.TextButtonStyle().apply { up = TextureRegionDrawable(textureRegion); font = buttonFont }
val button = TextButton("Button", style).apply {
table.add(this).size(512f, 512f)
}
override fun render(delta: Float) {
super.render(delta)
clearScreen(0f, 255f, 0f)
stage.act(delta)
stage.draw()
}
override fun dispose() {
stage.dispose()
}
}