Some Questions About Storyboard and Deleting Images Properly

Hi, when I use storyboard to create a scene and include the image to the group i.e.

function scene:createScene(event) local group=self.view imageOne=display.newImage(group, "imageOne.png") end

does imageOne get automatically deleted when the storyboard exits or do I have to manually delete the image? If I do have to manually delete it, is it correct to use:

display.remove(imageOne); imageOne=nil

Thank you.

If you put it in “group” like you are doing, when the storyboard scene gets purged or removed, the objects will be removed.  Just make sure you’re it’s not global.

Rob

If ‘Storyboard’ did not handle removing and clearing objects, then it would be quite a hassle, especially if you’re talking about a project with hundreds of objects.

In some instances you will need to remove and nil objects, in the exitScene.
I am removing&nil-ing the camera module, ‘loader’ (loads levelHelper objects) and my joystick.
If I didn’t then I would get errors because there would be multiple instances of the joystick, loader would not know what to do etc…

Also, as stated in the docs, “widgets must be manually removed” - in the destroyScene.
[lua]
if pauseBtn then
   pauseBtn:removeSelf()
   pauseBtn = nil
end
[/lua]

-Saer

Edit: I am not entirely sure why I have to manually nil those things, considering they are added to the view’s group… maybe certain objects/modules interact differently with ‘Storyboard’.

I think you are thinking of Widgets 1 where the object was a table and inside the table was the “view” a display.newGroup() that held the visible items.  With those you had to hand remove them as :removeSelf() didn’t work.

With storyboard the only things you have to manually remove are native.* objects, Runtime event listeners, physics, cancelling any timer, transition or something with an onComplete that could execute after the scene is gone and disposing of audio loaded in the scene.

Rob

Thank you guys!

Oh Rob, can you clarify that I only have to remove runtime event listeners as in

Runtime:addEventListener

but not an image that I have added an event listener to it

imageOne:addEventListener

as imageOne has been added to the “group”, so that storyboard will manage it for me when it exits? Thanks!

That is correct.  

If you put it in “group” like you are doing, when the storyboard scene gets purged or removed, the objects will be removed.  Just make sure you’re it’s not global.

Rob

If ‘Storyboard’ did not handle removing and clearing objects, then it would be quite a hassle, especially if you’re talking about a project with hundreds of objects.

In some instances you will need to remove and nil objects, in the exitScene.
I am removing&nil-ing the camera module, ‘loader’ (loads levelHelper objects) and my joystick.
If I didn’t then I would get errors because there would be multiple instances of the joystick, loader would not know what to do etc…

Also, as stated in the docs, “widgets must be manually removed” - in the destroyScene.
[lua]
if pauseBtn then
   pauseBtn:removeSelf()
   pauseBtn = nil
end
[/lua]

-Saer

Edit: I am not entirely sure why I have to manually nil those things, considering they are added to the view’s group… maybe certain objects/modules interact differently with ‘Storyboard’.

I think you are thinking of Widgets 1 where the object was a table and inside the table was the “view” a display.newGroup() that held the visible items.  With those you had to hand remove them as :removeSelf() didn’t work.

With storyboard the only things you have to manually remove are native.* objects, Runtime event listeners, physics, cancelling any timer, transition or something with an onComplete that could execute after the scene is gone and disposing of audio loaded in the scene.

Rob

Thank you guys!

Oh Rob, can you clarify that I only have to remove runtime event listeners as in

Runtime:addEventListener

but not an image that I have added an event listener to it

imageOne:addEventListener

as imageOne has been added to the “group”, so that storyboard will manage it for me when it exits? Thanks!

That is correct.