Pause/Resume Button --For some reason the image won't show up--

function new(func)

    local obj = display.newGroup()

        Scene.decorate(obj) – Control Transitions

function scene:createScene( event )

    group = self.view

     

    --define button dimensions

    local btnW, btnH = 100, 20

     

    --create pause button

    obj.pauseBtn = display.newImageRect( “button.png”, btnW, btnH )

     

    --place button in center

    obj.pasueBtn.anchorX = 0.5

    obj.pauseBtn.anchorY = 0.5

    obj.pauseBtn.x, obj.pauseBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2)

     

    --add event

    obj.pauseBtn:addEventListener( “touch”, pauseGame ) 

    group:insert( obj.pauseBtn )

     

    --create resume button

    obj.resumeBtn = display.newImageRect( “blockBlue1.png”, btnW, btnH )

     

    --put it on pause button

    obj.resumeBtn.anchorX = 0.5

    obj.resumeBtn.anchorY = 0.5

    obj.resumeBtn.x, obj.resumeBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2)

     

    --and hide it

    obj.resumeBtn.isVisible = false

     

    --add event

    obj.resumeBtn:addEventListener( “touch”, resumeGame ) 

    group:insert( obj.resumeBtn )

end

–pause game

function pauseGame(event)

    --if end of touch event

    if(event.phase == “ended”) then

        --pause the physics

        physics.pause()

        --make pause button invisible

        obj.pauseBtn.isVisible = false

        --make resume button visible

        obj.resumeBtn.isVisible = true

        – indicates successful touch

        return true

    end

end

–resume game

function resumeGame(event)

    --if end of touch event

    if(event.phase == “ended”) then

        --resume physics

        physics.start()

        --make pause button visible

        obj.pauseBtn.isVisible = true

        --make resume button invisible

        obj.resumeBtn.isVisible = false

        – indicates successful touch

        return true

    end

end

This is the code so far, but the problem is that when i start it, the buttons don’t show up so i can’t test if the code works. To add to this, there are no errors at all, so i’m having trouble identifying why it’s not working.

Hi @TechGuy,

The problem lies in the local obj = display.newGroup().

obj here is not display group but should be a table {}

Try this edited code.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require("physics") local obj = {}--display.newGroup() function pauseGame(event) --if end of touch event if(event.phase == "ended") then --pause the physics physics.pause() --make pause button invisible obj.pauseBtn.isVisible = false --make resume button visible obj.resumeBtn.isVisible = true -- indicates successful touch return true end end --resume game function resumeGame(event) --if end of touch event if(event.phase == "ended") then --resume physics physics.start() --make pause button visible obj.pauseBtn.isVisible = true --make resume button invisible obj.resumeBtn.isVisible = false -- indicates successful touch return true end end function scene:createScene( event ) group = self.view --define button dimensions local btnW, btnH = 100, 20 --create pause button obj.pauseBtn = display.newImageRect( "button.png", btnW, btnH ) --place button in center obj.pauseBtn.anchorX = 0.5 obj.pauseBtn.anchorY = 0.5 obj.pauseBtn.x, obj.pauseBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2) --add event obj.pauseBtn:addEventListener( "touch", pauseGame ) group:insert( obj.pauseBtn ) --create resume button obj.resumeBtn = display.newImageRect( "blockBlue1.png", btnW, btnH ) --put it on pause button obj.resumeBtn.anchorX = 0.5 obj.resumeBtn.anchorY = 0.5 obj.resumeBtn.x, obj.resumeBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2) --and hide it obj.resumeBtn.isVisible = false --add event obj.resumeBtn:addEventListener( "touch", resumeGame ) group:insert( obj.resumeBtn ) end

Good Luck!

burhan

Thank you again for the guidance burhan!

I tried that and got an error saying,

lua:94: attempt to call method ‘insert’ (a nill value)

stack traceback

[C]: in function ‘insert’

lua:94: in function 'new

lua:46: in function _listener

Hi,

I could not re produce your error.

Most probably because of storyboard. I assume you have all other storyboard functions setup.

If your code have additions from mine maybe you could type here.

burhan

Hi @TechGuy,

The problem lies in the local obj = display.newGroup().

obj here is not display group but should be a table {}

Try this edited code.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local physics = require("physics") local obj = {}--display.newGroup() function pauseGame(event) --if end of touch event if(event.phase == "ended") then --pause the physics physics.pause() --make pause button invisible obj.pauseBtn.isVisible = false --make resume button visible obj.resumeBtn.isVisible = true -- indicates successful touch return true end end --resume game function resumeGame(event) --if end of touch event if(event.phase == "ended") then --resume physics physics.start() --make pause button visible obj.pauseBtn.isVisible = true --make resume button invisible obj.resumeBtn.isVisible = false -- indicates successful touch return true end end function scene:createScene( event ) group = self.view --define button dimensions local btnW, btnH = 100, 20 --create pause button obj.pauseBtn = display.newImageRect( "button.png", btnW, btnH ) --place button in center obj.pauseBtn.anchorX = 0.5 obj.pauseBtn.anchorY = 0.5 obj.pauseBtn.x, obj.pauseBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2) --add event obj.pauseBtn:addEventListener( "touch", pauseGame ) group:insert( obj.pauseBtn ) --create resume button obj.resumeBtn = display.newImageRect( "blockBlue1.png", btnW, btnH ) --put it on pause button obj.resumeBtn.anchorX = 0.5 obj.resumeBtn.anchorY = 0.5 obj.resumeBtn.x, obj.resumeBtn.y = display.contentWidth-(btnW/2), display.contentHeight-(btnH/2) --and hide it obj.resumeBtn.isVisible = false --add event obj.resumeBtn:addEventListener( "touch", resumeGame ) group:insert( obj.resumeBtn ) end

Good Luck!

burhan

Thank you again for the guidance burhan!

I tried that and got an error saying,

lua:94: attempt to call method ‘insert’ (a nill value)

stack traceback

[C]: in function ‘insert’

lua:94: in function 'new

lua:46: in function _listener

Hi,

I could not re produce your error.

Most probably because of storyboard. I assume you have all other storyboard functions setup.

If your code have additions from mine maybe you could type here.

burhan