Hello
I recently moved to composer library from the director, so far all seem good, but one thing.
I inserted a couple of print commands in my code so i can track a certain problem with a transition beginning in one of the scenes. When i did that i realized the functions of the composer template are called more then once.
although the ‘will’ and ‘did’ inside them are called once. This happens in all scenes causing some functions i run at the ‘will’ part to perform some weird stuff.
When I try to ‘composer.removeScene(“scene name”)/composer.removeHidden()’ - it seem to have almost no effect. Any help will be appreciated.
Here is a sample code from one of my scenes:
------------------------------------------------------------------------------ local composer = require( "composer" )
local scene = composer.newScene()
local rank;
local hatTransition1 = 0;
local function startRank()
rank = display.newImage(“imageName”);
rank.x = rankBG.x;
rank.y = rankBG.y;
statsGroup:insert(rank);
local function sizeHatX()
local size = 0.9;
local function go()
hatTransition1 = transition.to(rank, {time=1400, xScale=1, transition=easing.inOutQuad, onComplete=sizeHatX} );
end
hatTransition1 = transition.to(rank, {time=1400, xScale=size, transition=easing.inOutQuad, onComplete=go} );
end
end
local bg = display.newImage(“imageName”);
bg .x = _W/2;
bg .y = _H/2;
skins[1] = display.newImage(“imageName”);
skins[1].x = bg.x - 100;
skins[1].y = bg.y - 135;
skins[2] = display.newImage(“imageName”);
skins[2].x = bg.x - 100;
skins[2].y = bg.y - 61;
local localGroup = display.newGroup();
localGroup:insert(bg);
localGroup:insert(skins[1]);
localGroup:insert(skins[2]);
function scene:create( event ) local sceneGroup = self.view sceneGroup:insert(localGroup); end – “scene:show()” function scene:show( event ) print(“there?”); local sceneGroup = self.view local phase = event.phase if ( phase == “will” ) then startRank(); elseif ( phase == “did” ) then end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase local parent = event.parent --reference to the parent scene object if ( phase == “will” ) then if(hatTransition1~=0) then transition.cancel(hatTransition1); end elseif(phase == “did”) then end end – Back button scene:addEventListener( “create”, scene ) scene:addEventListener( “show”, scene ) scene:addEventListener( “hide”, scene ) return scene
The ‘savedData = require(“savedData”);’ is called at the ‘main’ scene and is a global so i can access it from all scenes.