Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

When removing scene with composer the scene does not get removed
Started by cableguyp Jan 02 2019 05:22 PM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

cableguyp

[GLOBAL: userInfoPane.html]
cableguyp
  • Observer

  • 3 posts
  • Corona SDK

Hi so I have three scenes currently. The main menu scene. The game scene and then the gameover scene.

 

Currently when you loose in my game you go to the gameover scene with

local options = {effect = "fromRight", time = 500, params = { score = points, highscore = highscore}}
composer.gotoScene( "endgame", options)

That works okay

But on the gameover scene when I click one of the buttons to go to the menu or retry the scene doesnt actually get deleted and stays on screen. I've been trying everything and cant figure it out.

 

This is my endgame.lua

local composer = require( "composer" )
local scene = composer.newScene()
local widget = require("widget")
local end_screen = display.newGroup()

local background

-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------

-- 'onRelease' event listener for retryButton
local function onRetryButtonRelease()
  composer.removeScene("endgame")
  composer.removeScene("map")
  composer.gotoScene("map", "fromRight", 500)
end

-- 'onRelease' event listener for menuButton
local function onMenuButtonRelease()
  composer.removeScene("endgame")
  composer.removeScene("map")
  composer.gotoScene("menu", "fromRight", 500)
end

-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------

-- create()
function scene:create( event )
    local sceneGroup = self.view
    -- Code here runs when the scene is first created but has not yet appeared on screen
    background = display.newRect( 59000, 2000, display.actualContentWidth, display.actualContentHeight )
    background:setFillColor(0.257, 0.57, 0.95)
  	background.anchorX = 0
  	background.anchorY = 0
  	background.x = 0 + display.screenOriginX
  	background.y = 0 + display.screenOriginY

    local score = event.params.score
    local highscore = event.params.highscore

    scoreText = display.newText( "SCORE", display.contentCenterX, 400, native.systemFontBold, 70)
    points = display.newText(score, display.contentCenterX, 500, native.systemFontBold, 70)
    highscoreText = display.newText("HIGHSCORE",display.contentCenterX, 620, native.systemFontBold, 70)
    highscorePoints = display.newText(highscore, display.contentCenterX, 720, native.systemFontBold, 70)
    gameoverText = display.newText( "GAMEOVER", display.contentCenterX, 200, native.systemFontBold, 70)
    gameoverText:setFillColor(0.9, 0, 0)

    behindBox = display.newRoundedRect(display.contentCenterX, 200, 500, 170, 35)
    behindBox:setFillColor(0, 0.6, 0.7)

    menuButton = widget.newButton{
      label="MENU",
      labelColor = { default={235}, over={128} },
      default="button.png",
      over="button-over.png",
      width=300, height=100,
      onRelease = onMenuButtonRelease	-- event listener function
    }
    menuButton.x = display.contentCenterX
    menuButton.y = 880
    menuButton._view._label.size = 70;

    retryButton = widget.newButton{
      label="RETRY",
      labelColor = { default={235}, over={128} },
      default="button.png",
      over="button-over.png",
      width=300, height=100,
      onRelease = onRetryButtonRelease	-- event listener function
    }
    retryButton.x = display.contentCenterX
    retryButton.y = 1040
    retryButton._view._label.size = 70;

    sceneGroup:insert( background )
    sceneGroup:insert(menuButton)
    sceneGroup:insert(retryButton)
    sceneGroup:insert(highscorePoints)
    sceneGroup:insert(highscoreText)
    sceneGroup:insert(points)
    sceneGroup:insert(behindBox)
    sceneGroup:insert(gameoverText)
    sceneGroup:insert(scoreText)


end


-- show()
function scene:show( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)

    elseif ( phase == "did" ) then
        -- Code here runs when the scene is entirely on screen

    end
end


-- hide()
function scene:hide( event )

    local sceneGroup = self.view
    local phase = event.phase

    if ( phase == "will" ) then
        -- Code here runs when the scene is on screen (but is about to go off screen)

    elseif ( phase == "did" ) then
        -- Code here runs immediately after the scene goes entirely off screen
        if (end_screen) then
        end_screen:insert(sceneGroup)

        end

    end
end


-- destroy()
function scene:destroy( event )
    print(phase)

      menuButton.y = 200000
      menuButton:removeSelf()
      menuButton = nil
    local sceneGroup = self.view
    sceneGroup:toBack()
    sceneGroup.isVisible = false
    -- Code here runs prior to the removal of scene's view
    if (end_screen) then
    end_screen:toBack()
      end_screen:removeSelf()
      end_screen = nil
      end
end


-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -----------------------------------------------------------------------------------

return scene

Some help would be appreciated



[TOPIC: post.html]
#2

Benzeliden

[GLOBAL: userInfoPane.html]
Benzeliden
  • Enthusiast

  • 79 posts
  • Corona SDK

As I remember you can't remove currently active scene

I usually use empty scene for this. Pass callback function as a parameter and execute it in will show phase


[topic_controls]
[/topic_controls]