Dear Corona community,
what I'd like to do: I would like to create a "my friends" newText displayobject in sceneA and keep this object when I "slideLeft" to sceneB and also "slideLeft" further from sceneB to sceneC. When - at any time (sceneA, sceneB or sceneC) - I change to sceneD, sceneE or sceneF, the object has to disappear. The "myfriends" text should not slide with the scene (by adding it into the scenegroup) and it also should not disapear and reappear when changing scenes (by using :did-phases).
what I have done so far: Following the Goodbye Globals tutorial I have setup a "submenus.lua" file. Within the :show function of sceneA, I create the textobject and store a reference to it in this submenus.lua:
local submenus = require("submenus") title = display.newText("my friends", display.contentCenterX, screenTop + 25, native.systemFontBold, 26) title:setFillColor(0.35) submenus.menu = title
Since this object is not placed into the scenegroup, it persists on screen. I can access it in sceneB or sceneC by requiring my "submenus.lua" and changing its fillColor for example:
local submenus = require("submenus") local title = submenus.menu title:setFillColor(0.5)
In scenes where I don't want the title, I check for the existence of "submenus.menu". In case it is not (yet) nil, I remove it:
submenus.menu:removeSelf() submenus.menu = nil
What I dont like about this solution: I have like twenty scenes in total, and only three of them are supposed to display my "my friends" title. The solution above works, but now I have to run additional code (check for existence of submenus.menu) in each and every scene while only a few scenes actually show the title.
My question now is: Is there any better way of keeping a text-object untouched alive among three scenes, while as soon as you leave one of those scenes and go to one of the rest of the scenes, it disappears?
Hope it got clear what I want do to