Thanks much for the info! Still trying to digest all of this information.
I used Tap for the button, but now I’m getting an error when I use the button to switch to the mainGame() scene… says that mainGame is a nil value. I’m getting the same error when I use collision to change scenes from the mainGame() scene to the tryAgain() scene. Not sure what I’m doing wrong there…
Here is the code, bolded where I get errors, able to see what I’m doing wrong?
Really appreciate the help!
display.setStatusBar(display.HiddenStatusBar)
local physics = require("physics")
physics.start()
physics.setDrawMode("hybrid")
physics.setGravity(0,0)
local W = display.contentWidth
local H = display.contentHeight
local asteroid
local frog
local background
local button
local text
local mRandom=math.random
**local function astCollision(self, event)
if event.phase == "began" then
if event.target.type == "asteroid" and event.other.type == "frog" then
tryAgain()
return true
end
end
end**
local function asteroids()
asteroid = display.newImage("Images/ast.png")
asteroid.width = 256
asteroid.height = 256
asteroid.x = mRandom(128,W-128)
asteroid.y = - 256
physics.addBody(asteroid, {0,0,0})
asteroid:setLinearVelocity(0,600)
asteroid.collision = astCollision
asteroid:addEventListener("collision", asteroid)
asteroid.type = "asteroid"
end
local function frog()
frog = display.newImage("Images/Frog6.png")
frog.x = W/2
frog.y = H/1.2
frog.width = 96
frog.height = 128
physics.addBody(frog, "static", {0,0,0})
frog.type = "frog"
end
local function background()
background = display.newImage("Images/Background.png")
background.x = W/2
background.y = H/2
background.width = W
background.height = H
end
**local function myTapListener(event)
if (event.target) then
MainGame()
return true
end
end**
local function button()
button = display.newImage("Images/bluebutton.png")
button.x = W/2
button.y = H/2
button:addEventListener("tap",myTapListener)
end
local function mainMenu()
background()
button()
text = display.newText("Play Game",W/2,H/2,nativesystemFont,64)
end
local function mainGame()
background()
frog()
timer.performWithDelay(1000,asteroids,0)
end
local function tryAgain()
background()
button()
text = display.newText("Try Again",W/2,H/2,nativesystemFont,64)
end
mainMenu()