I have a intermediary screen between rounds in my game, which counts down from 10 before advancing to the next scene. I want to allow the user to pause and resume here. The first time I reach this screen it works fine. Here is the code for it, the next time I use this screen and try to pause the timer I get this:
WARNING: timer.resume(timerID) ignored b/c timerID was not paused, what am I doing wrong
local storyboard = require( "storyboard" )
storyboard.removeAll()
storyboard.purgeOnSceneChange = true
local scene = storyboard.newScene()
---------------------------------------------------------------------------------
-- BEGINNING OF YOUR IMPLEMENTATION
---------------------------------------------------------------------------------
local image, image2
local gameIsActive = true;
local paused = false;
total = storyboard.num11 + storyboard.num10
-- Called when the scene's view does not exist:
function scene:createScene( event )
local widget = require( "widget" )
require("ice")
local scores = ice:loadBox("scores")
image = display.newImage( "images/Background(640x480).png", -20 ,0 )
text = display.newText("Round Complete - You won Coins ", 45, 80, "comic sans ms", 22)
text:setTextColor(255,250,250)
text4 = display.newText(storyboard.num11, 320, 80, "comic sans ms", 22)
text4:setTextColor( 0, 206, 209)
text2 = display.newText( " number of coins won so far is ", 100, 130, "comic sans ms", 22)
text2:setTextColor(255, 250,250)
text2 = display.newText( "Total", 45, 130, "comic sans ms", 22)
text2:setTextColor(255, 0,0)
text5 = display.newText(total, 420, 130, "comic sans ms", 22)
text5:setTextColor( 0, 206, 209)
text3 = display.newText( "Good Luck in Round 3, Starting in... ", 45, 180, "comic sans ms", 22)
text3:setTextColor(255, 250, 250)
print( "\n2: createScene event" )
local player1 = display.newRect( 0, 0, 0, 0 )
player1.text = display.newText("Coins: ", 10, 16, "comic sans ms", 20)
player1.score = display.newText( "0", 90, 16, "comic sans ms", 20)
player1.score:setTextColor(255,215,0)
player1.score.text = scores:retrieve("player1") or 0
local resumeBtn = display.newImage("pause\_button.png");
resumeBtn.x = 440;
resumeBtn.y = 40;
local pauseBtn = display.newImage("play\_button.png");
pauseBtn.x = 440;
pauseBtn.y = 40;
pauseBtn.alpha = 0
resumeBtn.alpha = 1
local countDown = 10
pauseTime = false;
resumeTime = true;
local timerText = display.newText( "", 420, 197, "comic sans ms", 22)
timerText:setTextColor( 255, 255, 255 )
local timeBut = display.newRect( 50, 50, 100, 50 );
timeBut.x = 440;
timeBut.y = 40;
timeBut.alpha = 0.01;
local function delay\_trans(event)
storyboard.gotoScene( "maths\_dif", "slideLeft", 1000)
end
function gameOver()
if countDown == 0 then
countDown = 0
currentTime = countDown
timerText.text = countDown
timer.performWithDelay(3000, delay\_trans)
end
timerText.text = countDown
currentTime = countDown
countDown = countDown - 1
end
Timer1 = timer.performWithDelay( 1000, gameOver, 11 )
local function timeButton( event )
if event.phase == "began" then
if resumeTime == true then
timer.pause( Timer1 )
pauseTime = true
resumeTime = false
pauseBtn.alpha = 1;
resumeBtn.alpha = 0;
elseif pauseTime == true then
timer.resume(Timer1)
pauseTime = false
resumeTime = true
pauseBtn.alpha = 0;
resumeBtn.alpha = 1;
end
end
end
timeBut:addEventListener( "touch", timeButton )
end
[import]uid: 208811 topic_id: 35004 reply_id: 335004[/import]