how to remove the transition.to (line 39-48) so that it won’t give memory leaks?
As you can see the function animCloud( ) purpose is to make the cloud image running on top of the screen from right to left nonstop.
Can someone teach me how to remove it when we are leaving this current scene and go to next one (when menuPlayBtn is pressed/touched).
Thank you
[code]
– mainmenu.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– BEGINNING OF YOUR IMPLEMENTATION
local function onSceneTouch( self, event )
if event.phase == “began” then
storyboard.gotoScene( “gamescene”, “slideUp”, 800 )
return true
end
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local menuGroup = self.view
mainBg = display.newImageRect(“images/menubg.png”, 820, 960);
mainBg.x = _W/2;
mainBg.y = _H/2;
mainTitle = display.newImageRect(“images/title.png”, 624, 278);
mainTitle.x = _W/2;
mainTitle.y = _H/2 - 200;
mainCity = display.newImageRect(“images/city.png”, 1640, 450);
mainCity:setReferencePoint(display.BottomLeftReferencePoint);
mainCity.x = -40;
mainCity.y = 918;
mainCloud = display.newImageRect(“images/clouds.png”, 1640, 250);
mainCloud:setReferencePoint(display.TopLeftReferencePoint);
mainCloud.x = -40;
mainCloud.y = 0;
menuPlayBtn = display.newImageRect(“images/play.png”, 126, 50);
menuPlayBtn.x = _W/2 + 10;
menuPlayBtn.y = 580;
menuPlayBtn.touch = onSceneTouch;
function animCloud()
mainCloud.x = -40;
mainCloud.y = 0;
local anim;
anim = transition.to(mainCloud, {
time = 100000,
x = -40 - 820,
y = 0,
onComplete = animCloud})
end
animCloud();
menuGroup:insert(mainBg);
menuGroup:insert(mainTitle);
menuGroup:insert(mainCity);
menuGroup:insert(mainCloud);
menuGroup:insert(menuPlayBtn);
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
menuPlayBtn:addEventListener(“touch”, menuPlayBtn);
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
menuPlayBtn:removeEventListener(“touch”, menuPlayBtn)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
menuPlayBtn:removeEventListener(“touch”, menuPlayBtn)
end
– END OF YOUR IMPLEMENTATION
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene
[/code] [import]uid: 31508 topic_id: 32211 reply_id: 332211[/import]