Question

I've added a lifebar to my application, and it works well but once i quit the scene, the object is still visible. I've tried most of codes in tutorial, in vain.

lifeBar is declared in my function scene:enterScene(event) like this :

lifeBar = {}
lives = 12
maxLives = 12
lifeBar[0] = display.newImage("fuel_bar12.png")
lifeBar[1] = display.newImage("fuel_bar11.png")
lifeBar[2] = display.newImage("fuel_bar10.png")
lifeBar[3] = display.newImage("fuel_bar9.png")
lifeBar[4] = display.newImage("fuel_bar8.png")
lifeBar[5] = display.newImage("fuel_bar7.png")
lifeBar[6] = display.newImage("fuel_bar6.png")
lifeBar[7] = display.newImage("fuel_bar5.png")
lifeBar[8] = display.newImage("fuel_bar4.png")
lifeBar[9] = display.newImage("fuel_bar3.png")
lifeBar[10] = display.newImage("fuel_bar2.png")
lifeBar[11] = display.newImage("fuel_bar1.png")
lifeBar[12] = display.newImage("fuel_bar1.png")

livesValue = display.newText(string.format("%d", lives), 300,30,native.systemFontBold, 16)
livesValue:setTextColor(255,255,255)
screenGroup:insert(livesValue)

for i = 1, maxLives do
    lifeBar[i].anchorX=0
    lifeBar[i].anchorY=0.6
    lifeBar[i].x = fuel_title.x +114+15
    lifeBar[i].y = 37 -- start at 10,10
    lifeBar[i].isVisible=true

end

But i don't know how to put "off" this table in my function function scene:exitScene(event)

I've tried to create a group in the scene:createScene(event) :

controlpanel = display.newGroup()
controlpanel:insert(lifeBar)

and then in the

 scene:exitScene(event))

controlpanel=self.view

but it doesn't work :( any ideal about how to code this ?

By the way, it works with livesValue because it could be "inserted" in the groupe called screenGroup. My question is : is it possible to insert a table (in my case, called "lifeBar") in a group ?

Était-ce utile?

La solution

As posted your code does not show that you add all the different lifeBar objects to the scene group so they should remain visible on every scene (read about the default stage in corona). Once add them, you may have to removeSelf each one at scene exit or destroy can't verify right now.

Alternately you could add them all to the display group you tried but then don't forget to add that group to scene.view, and to removeSelf the group on exit or destroy event of scene.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top