I’m trying to remove an object during game play and I am pausing the physics. Below is the code.
QUESTION: What am I doing wrong or what am I not doing to get the physics restarted and the resume game button working? I am open to better idea’s if anyone would like to suggest a new approach.
This first function displays a hammer button that when pushed causes remove object buttons on top of objects that are available to be removed.
local function hammerCrush(event)
physics.stop()
if removeButton1.status == “Available” then
removeButton1.x=250; removeButton1.y=660
removeButton1.isVisible = true
removeButton1.isActive = true
end
if removeButton2.status == “Available” then
removeButton2.x=250; removeButton2.y=560
removeButton2.isVisible = true
removeButton2.isActive = true
end
hammerButton.isVisible = false
hammerButton.isActive = false
hammerButton.x = 0; hammerButton.y = 0
return true
end
hammerButton:addEventListener(“touch”, hammerCrush)
Then i have two of the following functions for the remove object buttons. When one of the buttons is pressed, the related bumper disappears and the Resume Game Button appears (works to this point).
local function removeBtn1(event)
physics.start()
local centerBumperGroup = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( centerBumperGroup )
centerBumperGroup.isFocus = true
centerBumper1.x=0; centerBumper1.y=0
centerBumper1.isVisible = false
centerBumper1.isActive = false
removeButton1.x=0; removeButton1.y = 0
removeButton1.isVisible = false
removeButton1.isActive = false
removeButton1.status = “Used”
removeButton2.x=0; removeButton2.y = 0
removeButton2.isVisible = false
removeButton2.isActive = false
removeButton2.status = “Available”
resumeGameButton.isVisible = true
resumeGameButton.isActive = true
resumeGameButton.status = true
end
return true
end
removeButton1:addEventListener(“touch”, removeBtn1)
--------------------------------------------------------------------------
local function removeBtn2(event)
physics.start()
local centerBumperGroup = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( centerBumperGroup )
centerBumperGroup.isFocus = true
centerBumper2.x=0; centerBumper2.y=0
centerBumper2.isVisible = false
centerBumper2.isActive = false
removeButton1.x=0; removeButton1.y = 0
removeButton1.isVisible = false
removeButton1.isActive = false
removeButton1.status = “Available”
removeButton2.x=0; removeButton2.y = 0
removeButton2.isVisible = false
removeButton2.isActive = false
removeButton2.status = “Used”
print (“removeButton2.status = USED”)
resumeGameButton.isVisible = true
resumeGameButton.isActive = true
resumeGameButton.status = true
end
return true
end
removeButton2:addEventListener(“touch”, removeBtn2)
It is at the point that I’m having trouble. The physics does not restart and the Resume Game button isn’t doing anything.
function restartPhysics( event )
if “began” == event.phase then
physics.start()
resumeGameButton.isVisible = false
resumeGameButton.isActive = false
resumeGameButton.status = false
end
return true
end
resumeGameButton:addEventListener(“touch”, restartPhysics)
Thanks
Lori