I have a game with diferent scenes and codes. I have try to implement a global label to display a timer like the FPS label that can be displayed in the director that works independent of the scene.
Is there any easy way to implement it?
A fast, easy to use, free, and community supported 2D game engine
I have a game with diferent scenes and codes. I have try to implement a global label to display a timer like the FPS label that can be displayed in the director that works independent of the scene.
Is there any easy way to implement it?
Just a tought, you could have like a HUDLayer which is always on top of other layers (z >>), so you can store it's z value on a singelton or something...
BTW, take a look at the displayFPS function, don't have my mac at hand so I can't really take a look and maybe give you pointers.
Yes, but this HUDLayer will be added to the scene, but as I change the scene it will be lost each time. I'll try to create a singleton layer with this timer and add it to each scene.
"HUDLayer will be added to the scene, but as I change the scene it will be lost each time."
you could consider the HUDLayer the 'view'. It could just have the code that displays the HUD *but* the HUDLayer keeps no state information itself. Then make a HUDModel singleton object that keeps all necessary information. When the HudLayer has to redraw, it gets its info from the HUDModel, so even if one HUDLayer is swapped out for a new HUDLayer it keeps displaying smoothly.
OK, another idea: make a category for Director and override -drawFPS and make it draw your HUD instead. A kludge solution for sure, you have to use categories to override methods carefully, but I think it would work.
good luck zon7!
Since my game board is used in several different scenes, I have it as a separate layer. The way I handled the problem of things getting lost on scene change was simply to put a line to re-add the game layer to the scene in the "onEnter" function of each scene I wanted it to appear in. Since animations and scheduled selectors also get stopped when this happens, I wrote a function in the game layer that re-starts all of those, and also call that in the onEnter function.
You could pass the HUD layer as a parameter to each scene, and then add it to the layer/retain it.
Shaz: Rather than doing that, why not adopt a singleton pattern and make a static sharedHUD. Thats what I used for my game layer in the process I described above. That way I don't need to pass it around, I can just reference it in the onEnter/ onExit functions for each scene.
You must log in to post.