I have some objects (2 sprites and some texts) that were created in the composer.newScene(), i declare it’s values(display.etc) in the scene:create(event) and i change it’s colors with setFillColor in a colision function declared in the composer:newScene, no problem here, when the objects make collision they change it’s colors normally,but when i exit the scene, return to the menu and enter again the scene, to replay the game, when it makes colision brings error: attempt to call method setFillColor a nil value, wich implies that the objects doesn’t exists, but they do, i think, the sprites appear in the screen but when the collision function tries to change it’s colors that’s all. It’s make me crazy so please help me figure it out.
The colision code look like this, and the objects like this in the scene = composer.newScene() and scene:create(event)
Colision Function
if (event.phase == "began") then
local obj1 = event.object1
local obj2 = event.object2
if ( obj2.myName == "blueP" and obj1.myName == "white") then
splash:setFillColor( 0.2, 0.16, 1 )
splash.x = obj2.x
splash.y = obj2.y
splash:play()
display.remove(obj2)
ball:setFillColor( 0.2, 0.16, 1 )
text:setFillColor( 0.2, 0.16, 1 )
count:setFillColor( 0.2, 0.16, 1 )
score:setFillColor( 0.2, 0.16, 1 )
pointsTxt:setFillColor( 0.2, 0.16, 1 )
clockText:setFillColor( 0.2, 0.16, 1 )
bonus:setFillColor( 0.2, 0.16, 1 )
audio.play(blipSound)
scene = composer.newScene()
local splash
local ball
scene:create(event)
splash = display.newSprite(mainGroup,sheetSplash,animSplash)
ball = display.newSprite(mainGroup,sheetBall,animBounce)
I repeat, it work fine the first time the scene it’s created, but when i change the scene and enter again doesn’t work, and i destroy the scene in scene:hide, phase == “did” with composer.removeScene