Hi All
I hope I can explain this ok.
I have an app, when I change scenes I want it to delete everything, but the text stays.
- Because text cannot be added to a group like an image, it doesn’t adhere to normal rules and as such needs to be removed manually and always sits on top
So, I get it, I can’t insert to a group and I have to remove it manually.
local function gotohome() if (ranknum) then ranknum:removeSelf() ranknum = nil end composer.gotoScene("menu", {time = 600, effect = "slideRight"}) end
but, this is displaying a table, so the variable ‘ranknum’ has been used several time in a do…while loop. So this just removes the last text added, not all the text.
Please see the loop below
local function loadday() display.remove (today) display.remove (week) display.remove (month) for i = 1, #feedstable do if (feedstable[i]) then local yPos = 150 + (i \* 56) print (feedstable[i].dateday) print ("i"..i) print ("legnth"..#feedstable) local headertext = display.newText("Date Time ml FeedType", display.contentCenterX-300,display.contentCenterY-400,native.systemFont,36) headertext.anchorX = 0 headertext:setFillColor(0,0,0) local datetime = os.date ("\*t") --get date and time and store in a table if (feedstable[i].dateyear == datetime.year and feedstable[i].datemonth == datetime.month and feedstable[i].dateday == datetime.day ) then ranknum = display.newText(i, display.contentCenterX-320, yPos,"Arial", 36) ranknum:setFillColor (0.8) ranknum.anchorX = 1 local thisscore = display.newText(feedstable[i].dateday..".".. feedstable[i].datemonth.. "."..feedstable[i].dateyear.. " "..feedstable[i].timehour.. ":"..feedstable[i].timemin.. " "..feedstable[i].feedammount.. " "..feedstable[i].feedtype, display.contentCenterX-300, yPos, native.systemFont, 36) thisscore.anchorX = 0 thisscore:setFillColor (0,0,0) end end end end
I have attached an image where you can see the text has been removed, but 2 & 3 are still there.
And of course, that makes sense. How would Corona know to remove them also, they are no longer the ranknum variable.
So my question is, how, in the simplest way possible, can I clear the screen. In other scenes I do not have this issue with text, but here I do.
Please someone help me. I spent 2 or 3 hours Googling this, I am not the only one who has had this problem but it was never the exact same.
All the code below, if it helps
local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() local today local week local month local ranknum local function gotohome() if (ranknum) then ranknum:removeSelf() ranknum = nil end composer.gotoScene("menu", {time = 600, effect = "slideRight"}) end local function addfeed() composer.gotoScene("AddFeed",{time=600,effect = "crossFade"}) end local function gotocalc() composer.gotoScene("calculator",{time=400, effect ="crossFade"}) end local function gotoabout() composer.gotoScene("about",{time=400, effect ="crossFade"}) end local json = require ("json") local filePath = system.pathForFile ("feeds.json",system.DocumentsDirectory) local file = io.open (filePath, "r") --open file as read only local contents = file:read("\*a") -- load contents into variable 'contents' io.close(file) -- closes the file feedstable = json.decode (contents) -- decode the file into LUA table local function loadday() display.remove (today) display.remove (week) display.remove (month) for i = 1, #feedstable do if (feedstable[i]) then local yPos = 150 + (i \* 56) print (feedstable[i].dateday) print ("i"..i) print ("legnth"..#feedstable) local headertext = display.newText("Date Time ml FeedType", display.contentCenterX-300,display.contentCenterY-400,native.systemFont,36) headertext.anchorX = 0 headertext:setFillColor(0,0,0) local datetime = os.date ("\*t") --get date and time and store in a table if (feedstable[i].dateyear == datetime.year and feedstable[i].datemonth == datetime.month and feedstable[i].dateday == datetime.day ) then ranknum = display.newText(i, display.contentCenterX-320, yPos,"Arial", 36) ranknum:setFillColor (0.8) ranknum.anchorX = 1 local thisscore = display.newText(feedstable[i].dateday..".".. feedstable[i].datemonth.. "."..feedstable[i].dateyear.. " "..feedstable[i].timehour.. ":"..feedstable[i].timemin.. " "..feedstable[i].feedammount.. " "..feedstable[i].feedtype, display.contentCenterX-300, yPos, native.systemFont, 36) thisscore.anchorX = 0 thisscore:setFillColor (0,0,0) end end end end function scene:create( event ) local sceneGroup = self.view local ranknum local background = display.newImageRect (sceneGroup, "Background.png",800,1400) background.x = display.contentCenterX background.y = display.contentCenterY local footer = display.newImageRect(sceneGroup,"Footer.png",793,120) footer.x = display.contentCenterX footer.y = 1150 local header = display.newImageRect(sceneGroup,"Header.png",794,140) header.x = display.contentCenterX header.y = -100 local mainbutton = display.newImageRect (sceneGroup, "Button.png",120,120) mainbutton.x = display.contentCenterX mainbutton.y = 1080 local logo = display.newImageRect(sceneGroup,"pumpit.png",282,122) logo.x = display.contentCenterX logo.y = -50 local circle = display.newImageRect (sceneGroup, "circle.png",95,95) circle.x = 232 circle.y = 1140 local homebutton = display.newImageRect (sceneGroup,"home.png",69,69) homebutton.x = 70 homebutton.y = 1140 local feeds = display.newImageRect (sceneGroup,"feeds.png",69,69) feeds.x = 230 feeds.y = 1140 local calc = display.newImageRect (sceneGroup,"calculator.png",69,69) calc.x = 550 calc.y = 1140 local info = display.newImageRect (sceneGroup,"info.png",69,69) info.x = 700 info.y = 1140 today = display.newImageRect (sceneGroup,"today.png",598,158) today.x = display.contentCenterX today.y = 300 week = display.newImageRect (sceneGroup,"week.png",598,158) week.x = display.contentCenterX week.y = 500 month = display.newImageRect (sceneGroup,"month.png",598,158) month.x = display.contentCenterX month.y = 700 homebutton:addEventListener ("tap", gotohome) mainbutton:addEventListener ("tap", addfeed) calc:addEventListener("tap", gotocalc) info:addEventListener("tap", gotoabout) today:addEventListener("tap", loadday) -- Code here runs when the scene is first created but has not yet appeared on screen end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) composer.removeScene("viewfeeds") elseif ( phase == "did" ) then composer.removeScene("viewfeeds") end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
Thanks in advanced
Dale

