Stop physics from start of game until button is pressed?

Hello, I’m using widget buttons, storyboard api as well as the physics engine. My question is how do i stop physics from the start then enable them when a button is pressed, in the case i want a ball to drop and start moving.

any help or referencing?

Maybe you could initially do:

physics:start()

physics:pause()

then when you press the button to make the ball drop, set:

physics:start()

That didn’t work sadly maybe some code will help so you can see how I’ve set it up.

Start Button widget (outside of implementation in storyboard)

local startBtn local function onStartBtnRelease() local function startPhysics(event) physics.start() return true -- indicates successful touch end end

Start button widget in create scene (yes its inserted into a group)

startBtn = widget.newButton{ label="Start", labelColor = { default={255}, over={128} }, defaultFile="play.png", overFile="play.png", width=120, height=60, onRelease = onStartBtnRelease -- event listener function } startBtn.x = 20 startBtn.y = 300 

Physics start and pause in enter scene

physics.start() physics.pause()

Remove widget in destroy scene

if startBtn then startBtn:removeSelf() -- widgets must be manually removed startBtn = nil end

1st and final bump

local startBtn local function onStartBtnRelease()     local function startPhysics(event)         physics.start()         return true    -- indicates successful touch     end end

you never call the startPhysics() function.   Also widget.newButton() I think has multiple phases like:

    event.phase == “ended”

that you need to test for or you’re likely to do your onStartBtnRelease() more than once.   You should probably consider rewriting that function:

local function onStartBtnRelease(event)     if event.phase == "ended" then         physics.start()     end     return true    -- indicates successful touch end

Maybe you could initially do:

physics:start()

physics:pause()

then when you press the button to make the ball drop, set:

physics:start()

That didn’t work sadly maybe some code will help so you can see how I’ve set it up.

Start Button widget (outside of implementation in storyboard)

local startBtn local function onStartBtnRelease() local function startPhysics(event) physics.start() return true -- indicates successful touch end end

Start button widget in create scene (yes its inserted into a group)

startBtn = widget.newButton{ label="Start", labelColor = { default={255}, over={128} }, defaultFile="play.png", overFile="play.png", width=120, height=60, onRelease = onStartBtnRelease -- event listener function } startBtn.x = 20 startBtn.y = 300 

Physics start and pause in enter scene

physics.start() physics.pause()

Remove widget in destroy scene

if startBtn then startBtn:removeSelf() -- widgets must be manually removed startBtn = nil end

1st and final bump

local startBtn local function onStartBtnRelease()     local function startPhysics(event)         physics.start()         return true    -- indicates successful touch     end end

you never call the startPhysics() function.   Also widget.newButton() I think has multiple phases like:

    event.phase == “ended”

that you need to test for or you’re likely to do your onStartBtnRelease() more than once.   You should probably consider rewriting that function:

local function onStartBtnRelease(event)     if event.phase == "ended" then         physics.start()     end     return true    -- indicates successful touch end