Game Over Screen?

How do I make my game get a Game Over screen pop up. Such at Game Over and a button next to it, that restarts the level.
Heres what I’m using atm

function ball:collision(event)
print(“here”)
self.alive = false
if(event.phase == “began”)then
if(event.other.name == “ground”)then
print(“Game Over”)
event.other:setFillColor(255,0,0)
EndGame()
end
end
end [import]uid: 134147 topic_id: 24533 reply_id: 324533[/import]

Are you using director?

We can’t see what your function EndGame() does from the above.

Also, please post code inside < lua > and < /lua > tags :slight_smile: [import]uid: 52491 topic_id: 24533 reply_id: 99340[/import]

No I’m not using director :o

It’s like this.

[lua]local background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0

local ground = display.newImage( “ground.png” )
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x, ground.y = 0, 530
ground.name = “ground”

physics.addBody( ground, “static”, { friction=1.0, density=1.0, bounce=0 } )

local statue = display.newImageRect( “statue.png”, 74, 104 )
statue.x, statue.y = 160, 300
physics.addBody( statue, { density=1.0, friction=0.3, bounce=0.3 } )

function statue:collision(event)
print(“here”)
self.alive = false
if(event.phase == “began”)then
if(event.other.name == “ground”)then
print(“Game Over”)
event.other:setFillColor(255,0,0)
EndGame()
end
end
end
statue:addEventListener(“collision”, statue)

local crate = display.newImageRect( “cement.png”, 220, 40 )
crate.x, crate.y = 160, 380
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

local crate = display.newImageRect( “wood.png”, 50, 60 )
crate.x, crate.y = 60, 430
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

function crate:touch(event)
print(“Destroy”)
if (event.phase == “began”) then
timer.performWithDelay(1, function()
self:removeEventListener(“touch”,self)
self:removeSelf()
end)
end
end
crate:addEventListener(“touch”, crate)

local crate = display.newImageRect( “wood.png”, 50, 60 )
crate.x, crate.y = 260, 430
physics.addBody( crate, { density=1.0, friction=0.3, bounce=0.3 } )

function crate:touch(event)
print(“Destroy”)
if (event.phase == “began”) then
timer.performWithDelay(1, function()
self:removeEventListener(“touch”,self)
self:removeSelf()
end)
end
end
crate:addEventListener(“touch”, crate)
– all display objects must be inserted into group
group:insert( background )
group:insert( ground)
group:insert( crate)
end[/lua] [import]uid: 134147 topic_id: 24533 reply_id: 99342[/import]

You don’t actually have EndGame() defined as a function in the code above, isn’t it throwing errors?

Is there a reason you aren’t using Director or Storyboard? It would be easier.

If you want to do this write an EndGame function that;

  • Creates a group, eg, endGroup = display.newGroup()
  • Creates a rectangle for the popup background
  • Creates the text, buttons, etc. for the popup

And add a function to the close button to remove endGroup when pressed. [import]uid: 52491 topic_id: 24533 reply_id: 99443[/import]