I hate to make a new post so soon, but I have been pulling my hair out all day with this. My debugger also does not work so I cant even debugg the issue with corona.
So I have this application which is basically the same as the balloon test but with different images etc etc. This works perfectly in the sim and on the device with tilt and all. I wanted to take this little beginner project a step further and add a menu screen.
So I used the Game Template available here:
http://developer.anscamobile.com/code/game-template
I modified it to my needs, and it also works perfectly. Buttons do what they should and it transitions into new scenes and back again correctly. So moving on I started to modify my current app that works alone, adding the Director class lines as needed.
The “play” button on the menu correctly changes scenes to my “game” physics work as expected and the object drop from gravity. However when I touch this screen Corona freezes and crashes. I have 3 objects (like the 3 balloons) and a pause button which when pressed would return you to the menu.lua.
I wish I could use the debugger but it just hangs and I have to force quit.
Here is the code for the original stand alone game, no menus or anything. It works like a charm.
local physics = require "physics"
physics.start()
physics.setGravity( 0, 9.8 )
physics.setDrawMode("standard")
system.setAccelerometerInterval( 100 )
function onTilt( event )
physics.setGravity( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ) )
end
Runtime:addEventListener( "accelerometer", onTilt )
system.activate( "multitouch" )
local background = display.newImage("bkg\_space.jpg")
local moon = display.newImage("moon.png")
moon.x = display.contentWidth/2
physics.addBody(moon, { bounce = 0.3, radius = 60, friction = 1.0 } )
local earth = display.newImage("earth.png")
earth.x = moon.x -180
physics.addBody(earth, { bounce = 0.2, radius = 115, friction = 1.0 } )
local mars = display.newImage("mars.png")
mars.x = moon.x +180
physics.addBody(mars, { bounce = 0.5, radius = 55, friction = 1.0 } )
local floor = display.newRect( 0, 960, display.contentWidth, 0 )
local ceiling = display.newRect( 0, 0, display.contentWidth, 0 )
local leftWall = display.newRect( 0, 0, 0, display.contentHeight )
local rightWall = display.newRect( 640, 0, 0, display.contentHeight )
physics.addBody(floor, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(ceiling, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(leftWall, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(rightWall, "static", { bounce = 0.2, friction = 1.0 } )
function moveMoon(event)
local moon = event.target
moon:applyLinearImpulse( 0, -0.5, event.x, event.y )
end
moon:addEventListener("touch", moveMoon)
earth:addEventListener("touch", moveMoon)
mars:addEventListener("touch", moveMoon)
display.setStatusBar(display.HiddenStatusBar)
Now using the Game Template linked above I ran through the other files and observed how everything was working and tried to modify my main.lua above for a pause button etc. It is accessed from the menu.lua via the “play” button and it executes. But as stated above when I try to interact with it Corona crashes.
module(..., package.seeall)
-- Main function - MUST return a display.newGroup()
function new()
local ui = require("ui")
local localGroup = display.newGroup()
-- Background
local background = display.newImage("images/bk-default.png")
localGroup:insert(background)
-- physics start
local physics = require "physics"
physics.start()
physics.setGravity( 0, 9.8 )
physics.setDrawMode("standard")
system.setAccelerometerInterval( 100 )
function onTilt( event )
physics.setGravity( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ) )
end
Runtime:addEventListener( "accelerometer", onTilt )
-- physics end
-- multitouch
system.activate( "multitouch" )
-- multitouch
-- pause button start
local pauseButton = nil
local function onPause ( event )
if event.phase == "release" and pauseButton.isActive then
director:changeScene("menu", "fade", 0,0,0)
end
end
pauseButton = ui.newButton{
defaultSrc = "images/btn-pause.png",
defaultX = 58,
defaultY = 58,
overSrc = "images/btn-pause.png",
overX = 58,
overY = 58,
onEvent = onPause,
id = "pauseButton",
text = "",
font = "Helvetica",
textColor = { 255, 255, 255, 255 },
emboss = false
}
pauseButton.x = 60
pauseButton.y = 60
pauseButton.isActive = true
localGroup:insert(pauseButton)
-- pause button end
-- physics objects start
local moon = display.newImage("images/moon.png")
localGroup:insert(moon)
moon.x = display.contentWidth/2
physics.addBody(moon, { bounce = 0.3, radius = 60, friction = 1.0 } )
local earth = display.newImage("images/earth.png")
localGroup:insert(earth)
earth.x = moon.x -180
physics.addBody(earth, { bounce = 0.2, radius = 115, friction = 1.0 } )
local mars = display.newImage("images/mars.png")
localGroup:insert(mars)
mars.x = moon.x +180
physics.addBody(mars, { bounce = 0.5, radius = 55, friction = 1.0 } )
local floor = display.newRect( 0, 960, display.contentWidth, 0 )
local ceiling = display.newRect( 0, 0, display.contentWidth, 0 )
local leftWall = display.newRect( 0, 0, 0, display.contentHeight )
local rightWall = display.newRect( 640, 0, 0, display.contentHeight )
physics.addBody(floor, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(ceiling, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(leftWall, "static", { bounce = 0.2, friction = 1.0 } )
physics.addBody(rightWall, "static", { bounce = 0.2, friction = 1.0 } )
function moveMoon(event)
local moon = event.target
moon:applyLinearImpulse( 0, -0.5, event.x, event.y )
end
moon:addEventListener("touch", moveMoon)
earth:addEventListener("touch", moveMoon)
mars:addEventListener("touch", moveMoon)
-- physics objects end
-- hide status bar
display.setStatusBar(display.HiddenStatusBar)
-- hide status bar
unloadMe = function()
end
-- MUST return a display.newGroup()
return localGroup
end
Any help, pointers, or insight would be greatly appreciated. Learned a lot so far!
Thanks again,
-Marc [import]uid: 20431 topic_id: 5274 reply_id: 305274[/import]