-
Hi, I'm rather confused by how to properly use Game & Scene and I can't seem to find much of this in the samples, or perhaps there is, but all the code being bunched together makes it difficult to read it imho. I like to separate my code to maintain clean workspace and I would like to separate my scenes from MainMenuScene and PlayScene.
I understand that there is still no documentation on how to load TTF, but is there any short info on how to exactly draw text using TTF font? Or if not, how would I go about converting it to .FNT bitmap? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey! Th
As mentioned above it is completely optional. The only thing that needs to be passed in when creating the app is a
Not necessarily. A
We need to add those scenes to the class SampleGame(context: Context) : Game<Scene>(context) {
override suspend fun Context.start() {
setSceneCallbacks(this) // need to call this to subscribe to the scene callbacks in Game class
// register the scenes - only need to do it once per scene. We can also register it later if we want.
addScene(PlayScene())
addScene(MenuScene())
setScene<MenuScene>() // set initial scene - pass in by class type
onRender {
if (input.isKeyJustPressed(Key.BACKSPACE)) {
if (currentScene !is MenuScene) {
setScene<MenuScene>()
}
}
}
}
}
While we can load a Loading a Ttf: val font: TtfFont = resourcesVfs["arial.ttf"].readTtfFont() Using a val batch = SpriteBatch(context)
val gpuFont = GpuFont(context, font)
gpuFont.addText("My Text!", x = 50, y = 100, pxSize = 16)
onRender {
batch.use {
gpuFont.useShaderWith(it) // need to set to GpuFont shader
gpuFont.draw(it)
}
batch.shader = batch.defaultShader // set back to default SpriteBatch shader
} Using a |
Beta Was this translation helpful? Give feedback.
-
Thank you for the further info! That makes a lot more sense! |
Beta Was this translation helpful? Give feedback.
Hey!
Th
Game
class is an optional class that contains a bunch of tidbits for handling and changing scenes. TheGame
class is completely optional and does not have to be used.As mentioned above it is completely optional. The only thing that needs to be passed in when creating the app is a
ContextListener
. TheGame
class is aContextListener
.Not necessarily. A
Scene
has a reference to theContext
when it's created. WithContext
we can access theresourcesVfs: VfsFile
which we can use…