Popup and physics?

Hello i used popup to make an pause menu, everything works fine so that i can pause the game get the popup up and pause the physics, but i don’t know how to unpause the physics then i am in my popup to return to the game?

because is local in my level.lua so can’t reach it from my popup.

Anyone know how to solve this?

Kind regards [import]uid: 90942 topic_id: 16735 reply_id: 316735[/import]

physics.start() and set gravity on resume. [import]uid: 52491 topic_id: 16735 reply_id: 62763[/import]

Hey Peach!

Thanks for the answer! What do you mean by setting gravity on resume?

[lua]physics.setGravity(0,5,0)[/lua]

like that?

kind regards
[import]uid: 90942 topic_id: 16735 reply_id: 62770[/import]

Got it resuming, however, i have some strange behavior, upon clicking resume to close the popup and resume the game it seems like i am clicking on booth the resume and the button that lies under everything and covers the entire screen(i use this button so the user can click anywhere on the screen and not on a certain button).so my ship goes up then the game resumes. Is there another way to make the screen clickable? like a big button? so the user don’t have to hit the right button?

It feels strange that then i click the popup and close it then the underlying button also gets clicked?

Here the function for the popup and the underlying button

[lua]–movement of the ship
function ufoMovement(event)

–An if that controls what happens then user hit anywhere on the screen and it goes up
if(event.target.name == “up” and crashed == false) then

–An if that fires an timer then touch began
if(event.phase == “began”) then

tmrUp = timer.performWithDelay(150, engines, 0)

–An elseif that checks then user stops to touch the button
elseif(event.phase == “ended”) then
timer.cancel(tmrUp)

spriteInstance.linearDamping = 0

–An elseif that checks if ufo has crashed then makes spriteInstance the crashedPos
elseif(crashed == true) then

spriteInstance.x = crashedPos

end

end

end

buttonUp:addEventListener(“touch”, ufoMovement)

–function for open the popup and pausing the physics
function pauseGame(event)

if(event.target.name == “pause”)then

physics.pause()
director:openPopUp(“options”, closed)
end

end

pause:addEventListener(“touch”, pauseGame)

–function for closing the popup and start physics
function menuTouch(event)

–An if that fires an timer then touch began
if(event.phase == “began”) then

director:closePopUp()
physics.start()
physics.setGravity(0,5,0)

end

end
options:addEventListener(“touch”, menuTouch)[/lua]

take care

Inkoqnito [import]uid: 90942 topic_id: 16735 reply_id: 62848[/import]

If you have two buttons on top of each other then pressing one often means pressing the other.

You can avoid that by using [lua]return true[/lua] at the end of the function :slight_smile:

Peach [import]uid: 52491 topic_id: 16735 reply_id: 63150[/import]

Hej Peach!

I am using at the end of my function however it still got problems, i have a giant button that covers the entire screen(its not visible) so the user can touch anywhere on the screen. And then i have a newRect as pauseMenu now have tested popup with the director class and gets the same problems.

As i posted in this post http://developer.anscamobile.com/forum/2011/10/24/attempt-index-nil-value#comment-63205 i get an error in the functions that moves the ship. But i don’t get why because i aint even touching that button but i know it is getting touched because if i make the pup button smaller and place it next to the pause menu i don’t get that kind of error, so it must be that the up button gets touched at the same time as the unPause.

Its getting really irritating! The game is working but i don’t like the error.

Kind regards

Inkoqnito [import]uid: 90942 topic_id: 16735 reply_id: 63326[/import]

The only reason that buttons below are gettin touched aswell is if you arent using the ‘return true’ correctly, like peach said.

In your above code you use:

 --function for closing the popup and start physics  
 function menuTouch(event)  
  
 --An if that fires an timer then touch began  
 if(event.phase == "began") then  
   
 director:closePopUp()  
 physics.start()  
 physics.setGravity(0,5,0)  
   
 end  
  
  
  
 end  

If you add ‘return true’ in there like so… it should work.

 --function for closing the popup and start physics  
 function menuTouch(event)  
  
 --An if that fires an timer then touch began  
 if(event.phase == "began") then  
   
 director:closePopUp()  
 physics.start()  
 physics.setGravity(0,5,0)  
   
 end  
  
  
 return true  
 end  

Have you already tried it like that? If your pause menu fills up the whole screen then the above should work just fine. [import]uid: 69826 topic_id: 16735 reply_id: 63329[/import]

Hi jimmydodger300

Thats the thing i am using return true like that, but it STILL continue to behave like that:S

The pause menu are more like an little popup in the middle of the screen, and i don’t see why it continues to touch the button behind then i am using that return statement.

it is really confusing:S

Kind regards [import]uid: 90942 topic_id: 16735 reply_id: 63331[/import]

I don’t know how to remove or mark this thread as solved but if anyone know how then do it please=)

I have made a solution to the problem and will be posting it here http://developer.anscamobile.com/forum/2011/10/24/attempt-index-nil-value#comment-63205

Kind regards

/Inkoqnito [import]uid: 90942 topic_id: 16735 reply_id: 63361[/import]