I have a pause menu with a retry button, that should allow a player to simply retry the level.
At present time, when the retry button has been pressed the game continues as normal but only the runtime stops.
I know I am missing obvious things such as deleting objects in destroy scene or something similar
I have tried numerous methods and have failed, here is my current code below, if someone could show me what I am missing and the best way to implement a fix.
I use classes in external files to create instances of each object, and I use external files to add certain items such as pause menu and controls, see below.
thank you.
ch 1 level 1.lua
[code]currentscene = “ch 1 level 1”
local storyboard = require (“storyboard”)
local scene = storyboard.newScene()
storyboard.purgeScene (“menu”)
display.setStatusBar( display.HiddenStatusBar )
local physics = require(“physics”)
physics.start()
physics.setDrawMode( “hybrid” )
physics.setGravity(0, 0)
function scene:createScene(event)
local group = self.view
local background = display.newGroup()
foreground = display.newGroup()
group:insert(background)
group:insert(foreground)
–BACKGROUND
backgroundimage = display.newImage(“image/galaxy background.png”)
background:insert(backgroundimage)
backgroundimage:setReferencePoint(display.TopLeftReferencePoint)
require “controls”
local rocket = require (“rocketclass”)
rocket1 = rocket.new()
rocket1:draw(150,3000,background,“rocket”)
background.y = -rocket1:y() + 440
local moon = require (“moonclass”)
local moon1 = moon.new()
moon1:draw(700,2900,background,“moon”)
local moon2 = moon.new()
moon2:draw(400,-750,background,“moon”)
local moon3 = moon.new()
moon3:draw(700,-1500,background,“moon”)
local platform = require (“platformclass”)
local platform1 = platform.new()
platform1:draw(0,3100,background,“platform”)
local platform2 = platform.new()
platform2:draw(760,-1800,background,“platform”)
local lpad = require (“Lpad”)
local lpad1 = lpad.new()
lpad1:draw(720,-1850,background,“Lpad”)
require “globalcollision”
function gameloop(event)
if (rocket1:y() > 320 and rocket1:y() < 2880) then
background.y = -rocket1:y() + 320
end
moon2:rotate(1)
moon1:rotate(-2)
moon3:rotate(5)
if (rocket1:x() > backgroundimage.contentWidth + 100) then
require “deathmenu”
end
if (rocket1:x() < backgroundimage.contentWidth - backgroundimage.contentWidth - 100) then
require “deathmenu”
end
if (rocket1:y() > backgroundimage.contentHeight + 100) then
require “deathmenu”
end
if (rocket1:y() < backgroundimage.contentHeight - backgroundimage.contentHeight - 100) then
require “deathmenu”
end
end
Runtime:addEventListener(“enterFrame”, gameloop)
end
– ENTER SCENE –
function scene:enterScene (event)
storyboard.purgeScene(storyboard.getPrevious())
end
– EXIT SCENE –
function scene:exitScene(event)
package.loaded[“controls”] = nil
Runtime:removeEventListener(“enterFrame”, gameloop)
end
function scene:destroyScene(event)
group = self.view
end
scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)
return scene [/code]
controls.lua (partial code to show pause button)
[code]function presspause(event)
physics.pause()
pause.isVisible = false
screenCap = display.captureScreen(false) --dont save to album
require “pausemenu”
end
pause:addEventListener(“touch”,presspause) [/code]
pausemenu.lua
local storyboard = require "storyboard"
local pauseretry = display.newImage("image/deathretry.png")
pauseretry.y = display.contentWidth/2.7
pauseretry.x = display.contentWidth/2.25
function pretry(event)
physics.start()
package.loaded["pausemenu"] = nil
display.remove(pausemenu)
display.remove(pauseplay)
display.remove(pauseretry)
display.remove(pauselevel)
display.remove(pausemainmenu)
display.remove(screenCap)
screenCap = nil
pause.isVisible = true
print (currentscene)
--storyboard.removeScene(currentscene)
storyboard.gotoScene(currentscene)
end
currentscene exists in main.lua [import]uid: 229931 topic_id: 37274 reply_id: 67274[/import]