Quick question about scene hierarchy
# korge
p
Quick question about scene hierarchy
I have a
BaseScene
that will be a parent for all my other scenes and it contains all the common functionality and views. It overrides the korge
Scene
object
Container.sceneInit()
function as well. How I could use the views for there and insert into the childs
sceneInit
function? E.g. I have a text about the fps in the BaseScene and I want to show that view in every child scene too. Is this question is okay anyway? (I mean is that clear? Is it okay that I’m asking question like this? I mean if you can’t answer it, because we have the Jam, then it’s all fine and I’ll figure out something else. I’m also not sure that I will use this structure at the end, but probably it will be useful and cleaner.)
n
It’s totally okay to ask any question. The quality of your games shall not be any less good because you didn’t get an answer to a questions. It’s no secret in open source anyways :) only shorter paths. But we need @Deactivated User for that :)
🙏 1
d
Feel free to ask questions. This is not an exam 🙂 You want to copy views? Why not creating those views in your sub-scenes? Or you want to have one single Text with fps, then reference it in the other scenes?
🙏 1
p
Sorry, I missed your replies. First of all, thank you for all the support 🙏 😊 Yes, I need that fps text in every view (okay this is an example, so I’m not sure it will be there in the final version too, but it would be good to achieve this behaviour for further code clean up). But I don’t want to implement it everywhere. And also other mechanics like when you press ESC on any scene, then you get the menu. That could be easily achieved if I’m put the same code into every scene. But I’m a “lazy” developer who don’t like to write the same code twice if it isn’t necessary. But I realised that isn’t the most urgent question in the current state of the game, so maybe I just lost in the details here 😅 (I mean code quality it really important, but first you need an MVP). But anyways, I’m still curious 😅
(I paused the Do Not Disturb mode until the end of Game Jam, so I won’t miss further answers)
d
you would normally create a function like: fun Container.addFps() { val text = text("FPS: ...") addUpdater { text.text = "FPS: ..." } } That way you don't have to copy those views, just call that function where you need it to be available
👍 3
p
Oh really… extension functions for
Container
… it’s obvious 🤦‍♂️ (Maybe I should get some rest… But I want to finish a few things before that.) Thank you for the answer! 🙏
👍 2