Corona + objects are not cleared between levels despite removeSelf + set to nil -


i have multilevel game , objects stay 'empty' in memory between levels mean if set physics hybrid, when come again in level, (or level) shows box without picture. (and physics act on these empty boxes) in destroyscene have made sure

   myobj:removeself()     myobj = nil 

and print message prove it.

also in menu in enterscene, in case

  local prior_scene = storyboard.getprevious()   storyboard.purgescene( prior_scene ) 

and tried

  storyboard.removeall() 

and

  storyboard.purgeonscenechange = true 

nothing works when go next level, or same level again, previous objects still here, don't it

ok, it's gonna bit long here entire level. go through destroyscene somehow display objects not removed.

-- scene5 ----------------------------------------------------------------------------------  local storyboard = require( "storyboard" ) local scene5 = storyboard.newscene()  function scene5:createscene( event )     local group = self.view   puppetjcolcount = 0   print ("createscene5", puppetjcolcount)     -----------------------------------------------------------------------------     --  create display objects , add them 'group' here.     --  example use-case: restore 'group' saved state.     local physics = require("physics")     physics.start()     --physics.setscale(50)     puppett_outside = false     puppetj_outside = false  end -- scene -------------------------   -- set , release catapult puppett function arm_puppett(event)     if event.phase == "began"         display.getcurrentstage():setfocus(puppett)         arming_puppett = true     elseif event.phase == "moved"         puppett.x = event.x         puppett.y = event.y     elseif event.phase == "ended"             puppett:applylinearimpulse(event.xstart - event.x, event.ystart - event.y, puppett.x, puppett.y)             display.getcurrentstage():setfocus(nil)             arming_puppett = false     end end -- arm_puppett ----------------------------------------------------------------------------  function build_puppett() -- setup puppett             puppett = display.newimage("assets/t-head-57-78.png")     puppett.x = 80     puppett.y = 100     physics.addbody(puppett,"dynamic",{density=1.0, friction =0.3, bounce=0.2}) -- setup catapult event arming puppett     puppett:addeventlistener("touch", arm_puppett)  end -- build_puppett  function build_puppetj_wall()  puppetjcolcount = puppetjcolcount + 1  -- how many columns of puppetj     puppetjij = {}              -- define puppetj array     ij = 0     ipuppetjtot = 0 --puppetjcolcount = 1     print ("build_puppetj_wall puppetjcolcount>" , puppetjcolcount);     i=1, 4         j=1, puppetjcolcount         ij = ij + 1         -- # of puppetjs on screen         ipuppetjtot = ipuppetjtot + 1         puppetjij = display.newimagerect("assets/j-head-70-75.png",80,75)          puppetjij.x = 600 + j*22         puppetjij.y = 100 + (puppetjij.height /2 * (i -1))          physics.addbody(puppetjij,"dynamic",{density=1.0,friction=0.3,bounce=0.2,issensor=false,radius = var})         end     end print ("building puppetjs #:" ,ipuppetjtot) end -- build_puppetj_wall -------------------------------------------------------------   function every_frame( event ) end -- every_frame --------------------------------------------------------------------  --reset level function tap_reset_level(event)         puppett:applylinearimpulse(0, 0, 0, 0)  -- stop kick         print "restarting physics?"         puppett:setlinearvelocity( 0, 0 )   -- stop speed     puppett.x = 80     puppett.y = 100      ij = 1,ipuppetjtot         if (puppetjij)             puppetjij:removeself()             puppetjij = nil ------         end     end   puppett:removeself()   puppett = nil      build_puppetj_wall()   build_puppett()      puppett_outside = false     puppetj_outside = false     -- physics.addbody(puppett,"dynamic",{density=1.0, friction =0.3, bounce=0.2})     -- puppett:addeventlistener("touch", arm_puppett)     --physics.start()  end -- tap_reset_level -------------------------------------------------------------------------  function tap_main_menu(event) print ("going main menu")   runtime:removeeventlistener("enterframe", every_frame)       ij = 1,ipuppetjtot         if (puppetjij)             puppetjij:removeself()             puppetjij = nil ------         end     end     if (puppett)         puppett:removeself()         puppett = nil     end       -- scene5:exitscene(scene5)     storyboard.gotoscene( "menu" )   end --  tap_main_menu --------------------------------------------------------------------------------- -- ====================================================================================== -- called after scene has moved onscreen: function scene5:enterscene( event )     local group = self.view      -----------------------------------------------------------------------------     --  insert code here (e.g. start timers, load audio, start listeners, etc.) --  group:insert( reset_btn ) -- load background print ("enterscene scene5 " , puppetjtot)      background = display.newimage("assets/parliament-1200-800.png",0,0) --create reset level button     reset_btn = display.newimagerect( "assets/btn_reset_128.png", 50,50)     reset_btn.x = 50     reset_btn.y = 50  --create main menu button     main_menu_btn = display.newimagerect( "assets/btn_home_128.png", 50,50)     main_menu_btn.x = 100     main_menu_btn.y = 50  -- show level     local mytext = display.newtext( "level 5", display.contentwidth - 60, 50,  "helvetica", 24 )     mytext:settextcolor(255, 255, 255)  --  insert(floor);      floor = display.newrect(20,display.contentheight - 40,display.contentwidth - 40 ,10)     physics.addbody(floor,"static",{density=1.0, friction =-0.3,bounce=-0.2,issensor=false})  -- build puppett   build_puppett()   print ("width=" , display.contentwidth , "height=",display.contentheight)   -- setup puppetjs     build_puppetj_wall()  -- happens in everyframe function runtime:addeventlistener("enterframe", every_frame)  --add reset event     reset_btn:addeventlistener( "tap", tap_reset_level )  --add mainmenu event     main_menu_btn:addeventlistener( "tap", tap_main_menu )   end -- scene:enterscene ---------------------------------------------------------------- -- ======================================================================================   -- called when scene move offscreen: function scene5:exitscene( event )     local group = self.view print "scene:exitscene5"     -----------------------------------------------------------------------------     --  insert code here (e.g. stop timers, remove listeners, unload sounds, etc.) end -- exitscene   -- called prior removal of scene's "view" (display group) function scene5:destroyscene( event )     local group = self.view      runtime:removeeventlistener("enterframe", every_frame)     puppetjcolcount = 0      if (reset_btn) print ("destroyscene5 - removing tap_reset_level")         reset_btn:removeeventlistener( "tap", tap_reset_level )          reset_btn:removeself()     end         reset_btn = nil     if (main_menu_btn)         main_menu_btn:removeeventlistener( "tap", tap_main_menu )         main_menu_btn:removeself()     end         main_menu_btn = nil     ij = 1,ipuppetjtot         if (puppetjij)             puppetjij:removeself()         end             puppetjij = nil ------     end      if (puppett)     puppett:removeself()    end     puppett = nil   scene5 = nil  end -- destroyscene ------------------------------------------------------------    scene5:addeventlistener( "createscene", scene5 )  scene5:addeventlistener( "enterscene", scene5 )  scene5:addeventlistener( "exitscene", scene5 )  scene5:addeventlistener( "destroyscene", scene5 )  ---------------------------------------------------------------------------------  return scene5 

update:

hi @devfar

ha, have restarted scratch corona template , figured out few things:

1) exitscene/destroyscene if local group used group display objects. removes display group ! not obvious there 1 declaration in it, no code such

2) reason why had of removeself of objects on place because nothing working. tried pretty under web.

3) , reason why didnt work because creating display objects function. , somehow display group not passed there. if move code createscene function indeed cleared when going next scene.

problem .. group puppetcreation code ! e.g.

function scene:createscene( event )         local group = self.view         local physics = require("physics")         physics.start()         background = display.newimage("assets/bckg.png",0,0)     group:insert(background)         createpuppet1(group)        createpuppet2(group) end function createpuppet1(group)         puppet1= display.newimage("assets/puppet1.png",0,0)     group:insert(puppet1) end function createpuppet2(group)         puppet2= display.newimage("assets/puppet2.png",0,0)     group:insert(puppet2) end 

i passed (group) because function createpuppet doesnt let me specify local group = self.view

my email address edualczatebed@gmail.com

thank help

there's lot of bug in code way implement not because when go scene , switch scene removing of object on destroyscene it's listener not efficient cannot point out what's causing problem because said there lot of bug in code. think didn't quite understand how use storyboard on corona. give idea on how solve problem implement code understand if not remove object on destroyscene can remove object via it's on display groups.

local rectangle local circle  local function nextscene(event)   storyboard.gotoscene( "scene_2", "fade", "500")  end  -- called when scene's view not exist: function scene:createscene( event )     local group = self.view      -----------------------------------------------------------------------------      rectangle = display.newrect(100,100,100,100)     rectangle:setfillcolor(255,0,0)     rectangle.x = 100     rectangle.y = 100      circle = display.newcircle(100,100,50)     circle.x = 250     circle.y = 100     circle:setfillcolor(0,255,0)      --inserting of object display group if destroy scene display group remove     group:insert(rectangle)      group:insert(circle)       -----------------------------------------------------------------------------  end   -- called after scene has moved onscreen: function scene:enterscene( event )     local group = self.view      -----------------------------------------------------------------------------      rectangle:addeventlistener("tap", nextscene)     circle:addeventlistener("tap", nextscene)        -----------------------------------------------------------------------------  end   -- called when scene move offscreen: function scene:exitscene( event )     local group = self.view      -----------------------------------------------------------------------------       -----------------------------------------------------------------------------  end   -- called prior removal of scene's "view" (display group) function scene:destroyscene( event )     local group = self.view      -----------------------------------------------------------------------------        -----------------------------------------------------------------------------  end 

as can see create 2 object rectangle , circle after created objects insert group on enterscene added tap listener go second scene if tap object. notice didn't bother remove object , listener on destroyscene when go scene_2 because when insert object display group whenever change scene remove object. after moving next scene can either purged last scene or remove when scene recreate object. hope can solve problem


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -