Keeping same UI elements across different scenes without recreation

Hello guys,

Imagine you have a set of common UI elements, like a “Score board” on top of the screen, and you want to keep these elements across two or more scenes (in storyboard terms).

Is it possible to do so without recreation of these elements every time? I assume this question should have been already asked, but I was not able to find anything relevant using search…

Thanks in advance!

Well one way would be to create them outside of a storyboard class, for instance in main.lua.

If they are not in a storyboard display group they will remain on screen when you change scene. It means you will have to manually control when they appear/ disappear though, but you can easily have global functions “createScoreboard()” and “removeScoreboard()” in main.lua and call them in the relevant enterScene functions.

So call createScoreboard() in the scenes you need it, with an if statement inside the function which only creates it if it does not already exist, and likewise with removeScoreboard in scenes where you don’t need it (and check that it DOES exist before attempting to remove it).

It works, thanks!

Hello,

I am having problems with the same topic: my global functions do not work as expected. I would like to have a score bar which I can show / hide on top of scenes, including some functions (add points, clear score etc.).

In my main.lua, I created a scorebar outside of storyboard, and it works fine as long as I call the control functions within main.lua. But from scenes I can’t call or access the scorebar or the functions, though all of them are (evil) global. 

What is the best way to achieve this?

I would appreciate any help.

Well one way would be to create them outside of a storyboard class, for instance in main.lua.

If they are not in a storyboard display group they will remain on screen when you change scene. It means you will have to manually control when they appear/ disappear though, but you can easily have global functions “createScoreboard()” and “removeScoreboard()” in main.lua and call them in the relevant enterScene functions.

So call createScoreboard() in the scenes you need it, with an if statement inside the function which only creates it if it does not already exist, and likewise with removeScoreboard in scenes where you don’t need it (and check that it DOES exist before attempting to remove it).

It works, thanks!

Hello,

I am having problems with the same topic: my global functions do not work as expected. I would like to have a score bar which I can show / hide on top of scenes, including some functions (add points, clear score etc.).

In my main.lua, I created a scorebar outside of storyboard, and it works fine as long as I call the control functions within main.lua. But from scenes I can’t call or access the scorebar or the functions, though all of them are (evil) global. 

What is the best way to achieve this?

I would appreciate any help.