Help with refreshing a scene on storyboard

I have 3 scenes. A, B and C.
in Scene A I have an image of a lady Bug moving from point A to point B
(using transition.to)

now, the lady bug Image is in point B, in scene A.

when I go to scene B, then scene C everything is fine.

when I come back to scene A, the lady bug is ALREADY there in point B

and a new lady bug comes out and moves, from point A to point B, now I have 2 lady bugs.

I want to know how to refresh the scene, so every time I go back to that scene, the programs runs from scratch.

Thanks for your help.

http://www.youtube.com/watch?v=CKNr7Z8ak1w&feature=youtu.be

This is the complete code.


local storyboard = require( “storyboard” )
local widget = require “widget”
local scene = storyboard.newScene()
local wrongSound = audio.loadSound( “noteDo4.mp3”)
– --==******************[FUNCTIONS TO GO TO ANOTHER SCENE]**********************+±- –
local function buttonHome()
        storyboard.gotoScene( “sceneB”, “crossFade”, 1000 )    
    return true
end
– --==**************************[CREATE SCENE]**********************************+±- –
function scene:createScene( event )
    local group = self.view
    
    local background = display.newImage( “backgroundLevel1Q6.png” )

    buttonHome = widget.newButton{
        defaultFile=“buttonHome.png”,
        onRelease = buttonHome
    }
    buttonHome.x = 522
    buttonHome.y = 655
---------------------------------------------------------------------insert into group----    
    group:insert ( background )
    group:insert ( buttonHome )    
end
– --==***************************[ENTER SCENE]**********************************+±- –
function scene:enterScene( event )
    local group = self.view
    
    local ladyBug = display.newImage( “ladyBug.png” )
    ladyBug.x = 100
    ladyBug.y = 500
    transition.to(ladyBug, {x=700 , y=500, time=5000})
    
    group:insert ( ladyBug )        
end
– --==***************************[EXIT SCENE]**********************************+±- –
function scene:exitScene( event )
    local group = self.view    
end
– --==**************************[DESTROY SCENE]*********************************+±- –
function scene:destroyScene( event )
    local group = self.view    
        if buttonHome then
            buttonHome:removeSelf()
            buttonHome = nil
        end
end
– --==*************************[EVENT LISTENER]*********************************+±- –

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

return scene


Thanks

Victor

The easiest way is I can think of is:

In the scene:enterScene(event) function in scene B, call this function

storyboard.destroyScene("sceneA") --or storyboard.purgeScene("sceneA")

This will remove the scene from memory. The next time you back to sceneA, it will be reloaded from scratch.

If you don’t need scene A to remain in memory while in scenes B and C, you may as well free up the memory anyway, to improve performance.

AlanPlantPot the problem is solved! I tried the

storyboard.destroyScene(“sceneA”)
–or
storyboard.purgeScene(“sceneA”)

but I guess I didn’t do it right. It didn’t work.

But someone named “pavement907” on youtube tolde me the solution. only 3 lines of code and it works!!!

At the top of my program I write

local ladyBug

then on the enterScene I don’t have to use “local” so I just write

ladyBug = display.newImage( “ladyBug.png” )

anf finally in the exitScene I write

function scene:exitScene( event )
    local group = self.view
    
    display.remove(ladyBug)
    
end

That’s it – and it works perfect.!!!

I’m sharing this if someone else has the same problem.

Oh do you know how to put the “green” tag that says “answered” so I can put it on my questions?

Ah I think I see why my way didn’t work, it looks like you are not inserting the object into a display group. E.g. in enterScene do:

local group = self.view

local ladyBug = display.newImage(group, “ladyBug.png”)

I wouldn’t make the objects global unless you need to. It’s fine if this is a small project, but it’s bad habit to get into add you risk poor pose on bigger projects.

Thank you Alan, like you said, this is a small project. Is my first App, and I’m just learning.

It’s an app to teach kidz how to play piano and some music theory.

I’m reading a lot, on line, on corona docs, Dr. Burton book that I bought, and i’m learning, thanks for your advice.

Right now the app works fine as I want, simple, but fine.

Once I finish this app, I will start another one, and I can start from scratch and apply this

local group = self.view
local ladyBug = display.newImage(group, “ladyBug.png”)

So, why global is bad?

The easiest way is I can think of is:

In the scene:enterScene(event) function in scene B, call this function

storyboard.destroyScene("sceneA") --or storyboard.purgeScene("sceneA")

This will remove the scene from memory. The next time you back to sceneA, it will be reloaded from scratch.

If you don’t need scene A to remain in memory while in scenes B and C, you may as well free up the memory anyway, to improve performance.

AlanPlantPot the problem is solved! I tried the

storyboard.destroyScene(“sceneA”)
–or
storyboard.purgeScene(“sceneA”)

but I guess I didn’t do it right. It didn’t work.

But someone named “pavement907” on youtube tolde me the solution. only 3 lines of code and it works!!!

At the top of my program I write

local ladyBug

then on the enterScene I don’t have to use “local” so I just write

ladyBug = display.newImage( “ladyBug.png” )

anf finally in the exitScene I write

function scene:exitScene( event )
    local group = self.view
    
    display.remove(ladyBug)
    
end

That’s it – and it works perfect.!!!

I’m sharing this if someone else has the same problem.

Oh do you know how to put the “green” tag that says “answered” so I can put it on my questions?

Ah I think I see why my way didn’t work, it looks like you are not inserting the object into a display group. E.g. in enterScene do:

local group = self.view

local ladyBug = display.newImage(group, “ladyBug.png”)

I wouldn’t make the objects global unless you need to. It’s fine if this is a small project, but it’s bad habit to get into add you risk poor pose on bigger projects.

Thank you Alan, like you said, this is a small project. Is my first App, and I’m just learning.

It’s an app to teach kidz how to play piano and some music theory.

I’m reading a lot, on line, on corona docs, Dr. Burton book that I bought, and i’m learning, thanks for your advice.

Right now the app works fine as I want, simple, but fine.

Once I finish this app, I will start another one, and I can start from scratch and apply this

local group = self.view
local ladyBug = display.newImage(group, “ladyBug.png”)

So, why global is bad?