Example applications #19
Replies: 63 comments
-
While the library was aimed at LibGDX users that want to improve their development experience with Kotlin, one could certainly start with KTX and Kotlin altogether. The documentation is extensive (I hope), but it does require prior LibGDX knowledge - it lacks simple game examples that could take you through the beginning. This should be our first priority right now. |
Beta Was this translation helpful? Give feedback.
-
Just sayin', but I'm learning LibGDX and Kotlin... and I'm using bialjam17 as an example application. Seriously, yes the KTX doc is really good, but it would be awesome to have a "canonical" application that shows the state of the art way to do things with KTX. |
Beta Was this translation helpful? Give feedback.
-
@Tibi I'm fully aware of that, but I just don't have that much time for open source/gamedev lately. I wouldn't mind some contributions that I could just review (and potentially refactor) before making them official examples. Maintaining the project is one thing, but actively creating a decent tutorial + example code requires quite a bit of time. As far as my game jams projects go, bialjam17 is definitely not the worst one. I think it uses a pretty recent KTX version without any major differences between the latest one. While I'd definitely refactor a lot of stuff - like anything hardcoded or using fixed positions - it's still better than nothing. Let me know if you have any questions about general LibGDX/KTX stuff - you can even create a separate issue for that. |
Beta Was this translation helpful? Give feedback.
-
Are you thinking of something similar to this but using KTX for the most part? I also agree that the documentation for each module is great and can be put in the wiki as-is. |
Beta Was this translation helpful? Give feedback.
-
@aouerfelli I wanted to avoid putting the documentation in the wiki instead of About the example project - I wanted to start with a simple game (Flappy Bird clone?) using techniques close to the original LibGDX, and gradually rewrite each part to idiomatic Kotlin with KTX. E.g. initially loading assets manually, then via |
Beta Was this translation helpful? Give feedback.
-
Is there any tutorial showing how exactly i'm supposed to use AssetStorage with ktx-async inside my game properly? |
Beta Was this translation helpful? Give feedback.
-
I'm afraid the |
Beta Was this translation helpful? Give feedback.
-
@czyzby Sorry for the barrage of questions.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@czyzby Thank you, you answered my questions perfectly I appreciate it :) |
Beta Was this translation helpful? Give feedback.
-
@abueide Feel free to create new issues with more questions if anything else comes up. ;) |
Beta Was this translation helpful? Give feedback.
-
@czyzby I set up the website with the tutorial you linked to in a message in this thread - now I feel bad I let the domain expire. I just put the content back up on a different site. https://jojomickymack.gitlab.io/reverie/post/libktx_platformer If anyone is looking for a starter project, I had created this single scene template a long time ago and I continue to use it as a way to start from scratch without having to mess around with the build files or anything else - others who might be coming across ktx for the first time might be looking for something like this to just get up and running where they can start animating and seeing things working. https://github.com/jojomickymack/ktxtemplate001 Here's a version of the ktxtemplate with an on screen gamepad and physical gamepad support - a handy drop in input module. https://github.com/jojomickymack/on_screen_gamepad01 I wrote another article as a sort of starter project for using ashley, the entity component framework. https://jojomickymack.gitlab.io/reverie/post/ashley_ecs again, there's an example project that goes with that. https://github.com/jojomickymack/libgdx_ashley001 If you are interested in the markdown for any of those articles, they are here. Thanks! As you can tell I'm really enthusiastic about the library, I've made some more sophisticated games using it now and I'm constantly discovering more great features in ktx! |
Beta Was this translation helpful? Give feedback.
-
@jojomickymack Thanks, I updated the comment.
Have you tried using
Would you like to add anything to the showcase? |
Beta Was this translation helpful? Give feedback.
-
These examples all use scene2d ktx extensions (no skin builders, texture-packers or dependency injectors). I added a refactored version of the ashley example to use ktx-ashley - it's really nice! https://github.com/jojomickymack/dialog_adventure ktx ashley platformer example Here are some other projects I created within the last several months - I doubt any are showcase material but I should make it a personal goal to extend my best one, the dialog-adventure, to be a complete game so it might be worthy of showcasing. I was inspired that you linked to my tutorial, I should continue working on my games - maybe these examples/templates might help other people somehow if they can find them. edit - ktx-ashley is really really nice. I was able to refactor some repetitive code where I'm adding components to entities and then adding the entities to the engine with this, much nicer code! Even without knowing much about the rest of the project, it's pretty clear that there's 2 entities, one ai-controlled and one user-controlled that each have a texture and different physics. var ashleyEngine = Engine()
with(ashleyEngine) {
addSystem(PhysicsSystem())
addSystem(RenderSystem())
addSystem(UserControlledSystem())
addSystem(AiControlledSystem())
addSystem(CameraFollowSystem())
}
ashleyEngine.add {
entity {
with<TextureComponent> {
region = TextureRegion(Texture(Gdx.files.internal("alex.png")))
}
with<PhysicsComponent> {
w = 30f
h = 50f
pos.set(200f, 200f)
}
with<UserControlledComponent> {}
with<CameraFollowComponent> {}
}
entity {
with<TextureComponent> {
region = TextureRegion(Texture(Gdx.files.internal("enemy.png")))
}
with<PhysicsComponent> {
w = 40f
h = 40f
topSpeed = 100f
pos.set(100f, 200f)
}
with<AiControlledComponent> {}
}
} Ktx is filled with nice stuff like this, I also didn't realize that I could queue up Actions to make a "scene" like this. Really great stuff. var label = Label("Welcome To The Game", AppObj.skin, "default")
label += sequence(delay(2f) + fadeIn(2f)) + delay(2f) + fadeOut(2f) and then add the label to the stage with the same += syntax stage += label I think I'm going to try to consolidate these examples into a single app where you select an example and it's loaded into a screen, that way I don't have dozens of repositories with one example each. You know I always meant to use the actual extensions more and haven't until now - really great stuff! |
Beta Was this translation helpful? Give feedback.
-
@Quillraven Good job! I had a quick look at it and it looks good so far, I'll read through the whole thing this week. I don't mind linking your wiki in this repository. |
Beta Was this translation helpful? Give feedback.
-
There are a bunch of 'graphics demos' I consolidated into this ktx-demos app - it's a hodge podge of shader demos I refactored to kotlin from mattdesl's tutorials and some other sources. This is some pretty advanced opengl stuff and working with it is a learning experience. I'm planning on adding more stuff highlighting ktx features as I keep going, but since the app is in a working state I wanted to throw it on here with the other links. I know it's buggy and not very original, still, the effects are really cool and they're all tweakable. |
Beta Was this translation helpful? Give feedback.
-
@Quillraven I'll go ahead and link your tutorial in the repo's wiki. Thanks for the contribution! |
Beta Was this translation helpful? Give feedback.
-
@jojomickymack Would you mind adding tags to your blog posts or some way to filter the posts that mention KTX? I'd like to link your blog as well, if you're OK with this. |
Beta Was this translation helpful? Give feedback.
-
Glad I could help :) I have a question though and sorry if this is the wrong place for it. I create my skin like this: private fun createSkin(assets: AssetManager): Skin {
// create fonts that are referenced in skin's json file
// and store them in a map to pass them as resource dependencies for the skin
val skinResources = ObjectMap<String, Any>()
val fontGenerator by assets.loadOnDemand<FreeTypeFontGenerator>("ui/8-bit.ttf")
skinResources.put("font_default", fontGenerator.generateFont { size = 32 })
skinResources.put("font_huge", fontGenerator.generateFont { size = 64 })
// unload the generator as it is no longer needed
assets.unload("ui/8-bit.ttf")
return assets.loadOnDemand<Skin>("ui/ui.json", SkinLoader.SkinParameter(skinResources)).asset
} The "loadFreeTypeFont" method always returned the same asset for some reason so I changed it to this version where I am using a generator. Also, "freeTypeFontParameter" cannot be used for "generateFont" because it is a LoaderParameter and not a "normal" parameter. Is this correct? Is there an easier/better way to do it? My skin json file is using "font_default" and "font_huge" as font values and therefore I need to create them before loading the skin and passing them as dependencies. When disposing the assetmanager I get a "Pixmap already disposed" exception. From what I can tell this seems to be a bug because the font dependency for the skin is not correctly handled and therefore the skin is disposing them and also the assetmanager. override fun dispose() {
// remove bitmap fonts from skin because they are loaded via assetmanager and he will take
// care of the disposal. Otherwise they get disposed twice and we get an "Pixmap already disposed" exception
val skin = context.inject<Skin>()
for (fontKey in skin.getAll(BitmapFont::class.java).keys()) {
skin.remove(fontKey, BitmapFont::class.java)
}
context.dispose()
super.dispose()
} Again, is there a better way to do it? And if not, maybe we could add something to freetype extension to automatically do this stuff before disposing the assetmanager? And thank you again for these great extensions. I really learned a lot from it and I have a lot of fun learning and using them in my projects :) |
Beta Was this translation helpful? Give feedback.
-
@czyzby I just made some changes to my blog to make the whole thing ktx exclusive - I changed the title of the blog to 'ktx-reverie' - I probably shouldn't change the name of the url though (it would invalidate previously used links). I also just wanted to note that the repo for the site is public, meaning that anyone can do a merge request and I will approve it. The site is made using hugo - so it's really low maintenance - anyone can contribute, not just me. Having revisited that site makes me feel that it needs some improvements (pictures, more articles, etc), so I'll be updating it/enhancing it periodically. I'd like to do a short series of physics demos similar to the nature of code using your excellent box2d extensions. |
Beta Was this translation helpful? Give feedback.
-
@jojomickymack Wow, that's great! Looking forward to the physics demo. I linked the blog on the wiki, thanks.
When in doubt, you can always create a second issue. It's OK to create issues with questions about the project.
This is because in LibGDX
Well, it comes down to a simple Java object, so there could be a utility method similar to
I'm a bit biased, but I'd use
If you look at the Again, I'd give |
Beta Was this translation helpful? Give feedback.
-
@czyzby I've shaped up this ktx demos repo quite a bit with some box2d and ktx specific graphics and scene2d stuff and it continues to grow. It's intended to be run on Android with a RecyclerView menu, but there's a desktop launcher with a minimal menu for selecting demos for desktop development/debugging. Once it gets to a certain size I'd like to put it up in the play store for free. If anybody on github feels like adding additional screens to this, I'll merge any pull requests! One thing I wanted to mention since I was just adding the 'use' extension for all my batches and shaders - another possible feature might be to have the same 'use' extension extend to FrameBuffer since they too have begin() and end() wrapping calls (usually containing draw calls for a batch - which would result in nested 'use' blocks). You can see an example of how framebuffers are typically used in mattdesl's wiki - I wonder if nesting 'use' blocks would cause problems? Anyway, just wanted to relay that feature idea to you since batches and shaders have 'use' extensions but FrameBuffers don't yet and it seems like they could to blend in with the others. |
Beta Was this translation helpful? Give feedback.
-
Good idea. I don't see why we wouldn't support most of these, although LibGDX APIs do not support a common interface for classes with |
Beta Was this translation helpful? Give feedback.
-
@czyzby Hey, sorry this is kind of turning into a q and a thread - I'm going through my examples and changing all the lines below in my render methods from Gdx.gl.glClearColor(0.6f, 0.6f, 0.6f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT or GL20.GL_DEPTH_BUFFER_BIT) to clearScreen(0.6f, 0.6f, 0.6f). clearScreen does the same thing with all examples except for those that use models, ie this model example and I found that the model doesn't render with clearScreen. The ktx clearScreen method only clears the buffer bit - the 'or GL20.GL_DEPTH_BUFFER_BIT' part is missing, which is the only difference from what I normally put there. I started doing that probably because it's stated in the libgdx wiki to have the depth buffer bit part - honestly I don't understand when or why it might clear one or the other, but it seems to make a big difference when rendering models. I was checking on xoppa's most basic 3d example, and the 'or GL20.GL_DEPTH_BUFFER_BIT' is definitely there and removing it results in the model not being rendered. I wonder if ktx should have 'or GL20.GL_DEPTH_BUFFER_BIT' added in the 'clearScreen' method? I'm not sure if there's any drawbacks to it - I've been using it for all 3d and 2d stuff for as long as I can remember. |
Beta Was this translation helpful? Give feedback.
-
@jojomickymack Sounds reasonable, could you submit a PR? |
Beta Was this translation helpful? Give feedback.
-
@czyzby Here's that #202 - I did the pull request to master, let me know if I should've done the pull request to the dev branch. I modified the unit test so it passes with the change. |
Beta Was this translation helpful? Give feedback.
-
@czyzby did a new PR branching off the develop branch this time #203 |
Beta Was this translation helpful? Give feedback.
-
Latest |
Beta Was this translation helpful? Give feedback.
-
@Quillraven created a YouTube series explaining various parts of the framework. I think this series combined with the tutorial and other KTX resources is enough to get started. |
Beta Was this translation helpful? Give feedback.
-
gdx-setup
project templates.@jojomickymack
demos showcase various setups and use many KTX modules.@Quillraven
's Adventure game and Dark Matter are some good examples.See also czyzby/gdx-setup#38.
Beta Was this translation helpful? Give feedback.
All reactions