So right now I have 2 levels and a main menu. When I press the home button on the 2nd level and then press play again it gives me this error.
Runtime error
bad argument #-2 to ‘insert’ (Proxy expected, got nil)
stack traceback:
[C]: ?
[C]: in function ‘insert’
?: in function ‘gotoScene’
c:\users\kelly\desktop\gravity guy\menu.lua:22: in function ‘onRelease’
?: in function <?:200>
?: in f [import]uid: 184688 topic_id: 33479 reply_id: 333479[/import]
Are you using Director or Storyboard for scene management? You aren’t showing any code. Please let us know and post some code so we can (hopefully) help you find the problem. [import]uid: 52491 topic_id: 33479 reply_id: 133029[/import]
I’m using storyboard. What do you need posted? [import]uid: 184688 topic_id: 33479 reply_id: 133036[/import]
We would need to see the scene you are going to as well as the place where you are calling gotoScene().
[import]uid: 19626 topic_id: 33479 reply_id: 133072[/import]
I’m getting the same error when I call this function:
local function gotoScene(scene)
loading.displayObject:toFront()
loading.displayObject.alpha = 1
local function listener()
storyboard.gotoScene( scene )
end
timer.performWithDelay( 200, listener)
end
Basically the idea is to show a Loading text before going to the next scene. If I call directly “storyboard.gotoScene(scene)” without performWithDelay it works. [import]uid: 46216 topic_id: 33479 reply_id: 133085[/import]
ok so here is the code for the second level which I am leaving:
[lua]----------------------------------------------------------------------------------
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local physics = require “physics”
physics.start()
local group2 = display.newGroup()
group2.x=0
physics.setGravity(0,20)
local background = display.newImageRect( “bg.png”, display.contentWidth, display.contentHeight )
group2:insert(background)
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
group2.x=0
–clouds
local cloud = display.newImage(“cloud 2.png”)
group2:insert(cloud)
cloud.x=900
local transLeft
local function transRight()
transition.to(cloud, {time=30000, x=-100, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=900, onComplete=transRight})
end
transRight()
local cloud = display.newImage(“cloud 3.png”)
group2:insert(cloud)
cloud.x=0
local transLeft
local function transRight()
transition.to(cloud, {time=30000, x=800, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=0, onComplete=transRight})
end
transRight()
local cloud = display.newImage(“cloud 1.png”)
group2:insert(cloud)
cloud.x=600
local transLeft
local function transRight()
group2.x=0
transition.to(cloud, {time=30000, x=-100, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=600, onComplete=transRight})
end
transRight()
–character
local mandown = display.newImage(“mandown.png”)
group2:insert(mandown)
mandown.isFixedRotation = true
mandown.y = 260
mandown.x = 90
function mandown:touch( event )
if event.phase == “began” then
self.markX = self.x – store x location of object
self.markY = self.y – store y location of object
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y – move object based on calculations above
end
return true
end
– make ‘myObject’ listen for touch events
mandown:addEventListener( “touch”, mandown )
physics.addBody(mandown,“dynamic”, {bounce=0.25, friction=.75})
–dangerous stuff
local ss= display.newImage(“ss.png”)
ss.y=700
physics.addBody(ss,“static”)
group2:insert(ss)
function sscollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
ss.collision = sscollision
ss:addEventListener( “collision”, ss )
local spikesl = display.newImage(“spikes.png”)
group2:insert(spikesl)
local spikesd = display.newImage(“spikes.png”)
group2:insert(spikesd)
physics.addBody( spikesd, “static”)
function spikesdcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
spikesd.collision = spikesdcollision
spikesd:addEventListener( “collision”, spikesd )
physics.addBody( spikesl, “static”)
function spikeslcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
spikesl.collision = spikeslcollision
spikesl:addEventListener( “collision”, spikesl )
– controls
local restart = display.newImage(“restart.png”)
group2:insert(restart)
restart.width=60
restart.height = 60
restart.x = 450
restart.y = 30
function restart:touch( event )
mandown.rotation = 0
physics.start()
mandown.y = 260
mandown.x = 90
physics.setGravity(0,20)
end
restart:addEventListener(“touch”)
local home = display.newImage(“home.png”)
group2:insert(home)
home.width=60
home.height = 60
home.x = 400
home.y = 30
function home:touch( event )
if event.phase == “ended” then
group2.x=450
storyboard.gotoScene( “menu”, “fade”, 500 )
physics.start()
end
return true – important.
end
home:addEventListener(“touch”, home)
local up = display.newImage(“up.png”)
group2:insert(up)
local down = display.newImage(“down.png”)
group2:insert(down)
up.x = 450
up.y = 280
up.width =75
up.height = 80
down.x = 30
down.y = 280
down.width =75
down.height = 80
function up:touch( event )
mandown.rotation = 180
physics.setGravity(0,-20)
mandown.rotation = 180
end
function down:touch( event )
mandown.rotation = 0
physics.setGravity(0,20)
mandown.rotation = 0
end
up : addEventListener(“touch”)
down : addEventListener(“touch”)
function onTilt(event)
mandown.x = mandown.x+17*-(event.yGravity)
print(event.yGravity)
end
Runtime:addEventListener (“accelerometer”, onTilt)
–platforms
local plat1 = display.newImage(“plat.png”)
group2:insert(plat1)
physics.addBody(plat1, “static”,{friction=10})
local plat2 = display.newImage(“plat.png”)
group2:insert(plat2)
physics.addBody(plat2, “static”,{friction=10})
local plat3 = display.newImage(“plat.png”)
group2:insert(plat3)
physics.addBody(plat3, “static”,{friction=10})
–arrows
local rightg = display.newImage(“right.png”)
group2:insert(rightg)
rightg.x=100
rightg.y = 400
rightg.height = 50
rightg.width = 50
physics.addBody( rightg , “static”, { density=10000.0, friction=10})
function rightgcollision (event)
physics.setGravity(10,-5)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
mandown.rotation =90
end
, 1)
end
rightg.collision = rightgcollision
rightg:addEventListener( “collision”, rightg )
local upg = display.newImage(“upg.png”)
upg.x=700
upg.y = 400
upg.height = 50
upg.width = 50
physics.addBody(upg , “static”, { density=10000.0, friction=10})
function upgcollision (event)
physics.setGravity(0,-15)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
mandown.rotation =180
end
, 1)
end
upg.collision = upgcollision
upg:addEventListener( “collision”, upg )
–walls
local wallleft = display.newRect(-10, -60, 10, 600 )
wallleft:setFillColor( 255 )
group2:insert(wallleft)
physics.addBody( wallleft , “static”, { density=10000.0, friction=10})
function wallleftcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallleft.collision = wallleftcollision
wallleft:addEventListener( “collision”, wallleft )
local wallright = display.newRect(480, -60, 10, 600 )
wallright:setFillColor( 255 )
group2:insert(wallright)
physics.addBody( wallright, “static”, { density=10000.0, friction=10} )
function wallrightcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallright.collision = wallrightcollision
wallright:addEventListener( “collision”, wallright )
local walltop = display.newRect(0, -10, 600, 10 )
walltop:setFillColor( 255 )
group2:insert(walltop)
physics.addBody( walltop , “static”, { density=10000.0, friction=10})
function walltopcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
walltop.collision = walltopcollision
walltop:addEventListener( “collision”, walltop )
local wallbottom = display.newRect(0, 320, 600, 10 )
wallbottom:setFillColor( 255 )
group2:insert(wallbottom)
physics.addBody( wallbottom, “static”, {friction=10})
function wallbottomcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallbottom.collision = wallbottomcollision
wallbottom:addEventListener( “collision”, wallbottom )
rightg.y = 150
plat1.x = 70
plat1.y =100
plat2.x = 103
plat2.y= 285
plat2.width = 80
plat3.x=330
plat3.y=285
plat3.width = 130
spikesd.x = 200
spikesd.y = 110
spikesd.width = 50
spikesd.height = 100
spikesd:rotate(270 )
spikesl.x =200
spikesl.y = 305
spikesl.width = 50
spikesl.height = 100
spikesl:rotate(90)
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group2 = self.view
group2.x=0
physics.start()
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group2 = self.view
package.loaded[physics] = nil
physics = nil
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
print( “Hello world!” )
group2.x=0
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
print( “Hello world!” )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
print( “Hello world!” )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene[/lua]
Here is what I’m going to, the main menu:
[lua]-----------------------------------------------------------------------------------------
– menu.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “widget” library
local widget = require “widget”
– forward declarations and other locals
local playBtn
– ‘onRelease’ event listener for playBtn
local function onPlayBtnRelease()
– go to level1.lua scene
storyboard.gotoScene( “level1”, “fade”, 500 )
return true – indicates successful touch
end
– BEGINNING OF YOUR IMPLEMENTATION
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– display a background image
local background = display.newImageRect( “bg.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
– create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( “logo.png”, 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 20
local alert = native.showAlert( “Gravity Man”, “Welcome To Gravity Man! Your goal is to get your eggs back by using your gravity switching powers. Tilt to move and tap up and down to switch the gravity!”, { “OK”})
– create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label=“Play Now”,
labelColor = { default={255}, over={128} },
default=“button.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 50
– all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
if playBtn then
playBtn:removeSelf() – widgets must be manually removed
playBtn = nil
end
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene
[import]uid: 184688 topic_id: 33479 reply_id: 133139[/import]
I didn’t see a createScene() function or event listener in the module you are going to.
Storyboard pretty much needs to have something in it’s scene.view which is created off screen then transitioned on screen. Typically this is done during the createScene() event which is called to setup the scene.
Most of that initialization code at the top needs to go into the createScene() function and at least one display object needs to be put into the scene view. This is the line:
local group = scene.view
and you need to do a
group:insert(someobject)
I’m pretty sure that’s what’s causing this error. [import]uid: 199310 topic_id: 33479 reply_id: 133148[/import]
OK so I got the menu figured out but now when I transition from menu to game to next level to menu and back to game it brings me back to level one which is what I want but it acts like there is objects behind the visible level so everything reacts weirdly. I have tried removing the group but that doesn’t allow me to go back to that level because everything is gone. I have spent about 4 hours on this and I can’t figure it out.
Please help
Avery [import]uid: 184688 topic_id: 33479 reply_id: 133164[/import]
I don’t use storyboards, but in general it sounds like display objects aren’t being removed/hidden…
When displaying one screen after another, some corona objects can behave, errr, unexpectedly if not made invisible, or entirely removed (scroll lists/widgets for example), even if they are behind newer display objects.
Perhaps making the offending objects invisible (the ones that are still active), or ensuring they are removed from the display system (display.remove, object:removeSelf, etc) would solve the issue.
How do you know which ones to deal with in this way you ask? They’re the ones that give you the errors 
[import]uid: 79933 topic_id: 33479 reply_id: 133165[/import]
Are you using Director or Storyboard for scene management? You aren’t showing any code. Please let us know and post some code so we can (hopefully) help you find the problem. [import]uid: 52491 topic_id: 33479 reply_id: 133029[/import]
I’m using storyboard. What do you need posted? [import]uid: 184688 topic_id: 33479 reply_id: 133036[/import]
You shouldn’t need to remove “group”. Storyboard manages that for you.
Can you describe in better details " but it acts like there is objects behind the visible level so everything reacts weirdly."?
Keep in mind that unless you tell it otherwise, storyboard keeps previous scenes in memory and depending on the transition, it could just be stacking the scenes on top of each other (though a fade or crossFade would render the scene invisible). You can do a storyboard.removeScene(“prevscenename”) to get rid of the previous scene.
Things that do not go into the “group” stay on top of everything. [import]uid: 199310 topic_id: 33479 reply_id: 133201[/import]
We would need to see the scene you are going to as well as the place where you are calling gotoScene().
[import]uid: 19626 topic_id: 33479 reply_id: 133072[/import]
I’m getting the same error when I call this function:
local function gotoScene(scene)
loading.displayObject:toFront()
loading.displayObject.alpha = 1
local function listener()
storyboard.gotoScene( scene )
end
timer.performWithDelay( 200, listener)
end
Basically the idea is to show a Loading text before going to the next scene. If I call directly “storyboard.gotoScene(scene)” without performWithDelay it works. [import]uid: 46216 topic_id: 33479 reply_id: 133085[/import]
do you need quotations around the scenes name? [import]uid: 184688 topic_id: 33479 reply_id: 133261[/import]
The code I posted before is quite more simple and I’m getting the same error. Maybe it’s something related.
The function storyboard.gotoScene should it work if it is inside a performWithDelay callback? Like this:
local function listener()
storyboard.gotoScene( scene )
end
timer.performWithDelay( 200, listener)
That’s what I’m doing to get this error. As I said, if I call directly gotoScene without performWithDelay, it works. It’s a bit weird, don’t? [import]uid: 46216 topic_id: 33479 reply_id: 133262[/import]
I finally figured mine out all I have to do is remove the scene previous to the wine I was in every time I enter the scene and it worked so I just put storyboard.removeScene(“prevscenename”) at the beginning of my code and now everything works. I have 1 more question is there a way to “unlock” levels as you beat them. [import]uid: 184688 topic_id: 33479 reply_id: 133263[/import]
The first parameter to the storyboard functions is a string. You can do:
storyboard.gotoScene( “somescene” )
or
scene = “somescene”
storyboard.gotoScene( scene )
[import]uid: 199310 topic_id: 33479 reply_id: 133305[/import]
ok so here is the code for the second level which I am leaving:
[lua]----------------------------------------------------------------------------------
– scenetemplate.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local physics = require “physics”
physics.start()
local group2 = display.newGroup()
group2.x=0
physics.setGravity(0,20)
local background = display.newImageRect( “bg.png”, display.contentWidth, display.contentHeight )
group2:insert(background)
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
group2.x=0
–clouds
local cloud = display.newImage(“cloud 2.png”)
group2:insert(cloud)
cloud.x=900
local transLeft
local function transRight()
transition.to(cloud, {time=30000, x=-100, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=900, onComplete=transRight})
end
transRight()
local cloud = display.newImage(“cloud 3.png”)
group2:insert(cloud)
cloud.x=0
local transLeft
local function transRight()
transition.to(cloud, {time=30000, x=800, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=0, onComplete=transRight})
end
transRight()
local cloud = display.newImage(“cloud 1.png”)
group2:insert(cloud)
cloud.x=600
local transLeft
local function transRight()
group2.x=0
transition.to(cloud, {time=30000, x=-100, onComplete=transLeft})
end
transLeft = function()
transition.to(cloud, {time=30000, x=600, onComplete=transRight})
end
transRight()
–character
local mandown = display.newImage(“mandown.png”)
group2:insert(mandown)
mandown.isFixedRotation = true
mandown.y = 260
mandown.x = 90
function mandown:touch( event )
if event.phase == “began” then
self.markX = self.x – store x location of object
self.markY = self.y – store y location of object
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y – move object based on calculations above
end
return true
end
– make ‘myObject’ listen for touch events
mandown:addEventListener( “touch”, mandown )
physics.addBody(mandown,“dynamic”, {bounce=0.25, friction=.75})
–dangerous stuff
local ss= display.newImage(“ss.png”)
ss.y=700
physics.addBody(ss,“static”)
group2:insert(ss)
function sscollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
ss.collision = sscollision
ss:addEventListener( “collision”, ss )
local spikesl = display.newImage(“spikes.png”)
group2:insert(spikesl)
local spikesd = display.newImage(“spikes.png”)
group2:insert(spikesd)
physics.addBody( spikesd, “static”)
function spikesdcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
spikesd.collision = spikesdcollision
spikesd:addEventListener( “collision”, spikesd )
physics.addBody( spikesl, “static”)
function spikeslcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
spikesl.collision = spikeslcollision
spikesl:addEventListener( “collision”, spikesl )
– controls
local restart = display.newImage(“restart.png”)
group2:insert(restart)
restart.width=60
restart.height = 60
restart.x = 450
restart.y = 30
function restart:touch( event )
mandown.rotation = 0
physics.start()
mandown.y = 260
mandown.x = 90
physics.setGravity(0,20)
end
restart:addEventListener(“touch”)
local home = display.newImage(“home.png”)
group2:insert(home)
home.width=60
home.height = 60
home.x = 400
home.y = 30
function home:touch( event )
if event.phase == “ended” then
group2.x=450
storyboard.gotoScene( “menu”, “fade”, 500 )
physics.start()
end
return true – important.
end
home:addEventListener(“touch”, home)
local up = display.newImage(“up.png”)
group2:insert(up)
local down = display.newImage(“down.png”)
group2:insert(down)
up.x = 450
up.y = 280
up.width =75
up.height = 80
down.x = 30
down.y = 280
down.width =75
down.height = 80
function up:touch( event )
mandown.rotation = 180
physics.setGravity(0,-20)
mandown.rotation = 180
end
function down:touch( event )
mandown.rotation = 0
physics.setGravity(0,20)
mandown.rotation = 0
end
up : addEventListener(“touch”)
down : addEventListener(“touch”)
function onTilt(event)
mandown.x = mandown.x+17*-(event.yGravity)
print(event.yGravity)
end
Runtime:addEventListener (“accelerometer”, onTilt)
–platforms
local plat1 = display.newImage(“plat.png”)
group2:insert(plat1)
physics.addBody(plat1, “static”,{friction=10})
local plat2 = display.newImage(“plat.png”)
group2:insert(plat2)
physics.addBody(plat2, “static”,{friction=10})
local plat3 = display.newImage(“plat.png”)
group2:insert(plat3)
physics.addBody(plat3, “static”,{friction=10})
–arrows
local rightg = display.newImage(“right.png”)
group2:insert(rightg)
rightg.x=100
rightg.y = 400
rightg.height = 50
rightg.width = 50
physics.addBody( rightg , “static”, { density=10000.0, friction=10})
function rightgcollision (event)
physics.setGravity(10,-5)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
mandown.rotation =90
end
, 1)
end
rightg.collision = rightgcollision
rightg:addEventListener( “collision”, rightg )
local upg = display.newImage(“upg.png”)
upg.x=700
upg.y = 400
upg.height = 50
upg.width = 50
physics.addBody(upg , “static”, { density=10000.0, friction=10})
function upgcollision (event)
physics.setGravity(0,-15)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
mandown.rotation =180
end
, 1)
end
upg.collision = upgcollision
upg:addEventListener( “collision”, upg )
–walls
local wallleft = display.newRect(-10, -60, 10, 600 )
wallleft:setFillColor( 255 )
group2:insert(wallleft)
physics.addBody( wallleft , “static”, { density=10000.0, friction=10})
function wallleftcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallleft.collision = wallleftcollision
wallleft:addEventListener( “collision”, wallleft )
local wallright = display.newRect(480, -60, 10, 600 )
wallright:setFillColor( 255 )
group2:insert(wallright)
physics.addBody( wallright, “static”, { density=10000.0, friction=10} )
function wallrightcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallright.collision = wallrightcollision
wallright:addEventListener( “collision”, wallright )
local walltop = display.newRect(0, -10, 600, 10 )
walltop:setFillColor( 255 )
group2:insert(walltop)
physics.addBody( walltop , “static”, { density=10000.0, friction=10})
function walltopcollision (event)
physics.setGravity(0,20)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
walltop.collision = walltopcollision
walltop:addEventListener( “collision”, walltop )
local wallbottom = display.newRect(0, 320, 600, 10 )
wallbottom:setFillColor( 255 )
group2:insert(wallbottom)
physics.addBody( wallbottom, “static”, {friction=10})
function wallbottomcollision (event)
timer.performWithDelay( 1, – 1 millisecond delay
function() – anonymous function to perform the update
physics.setGravity(0,20)
mandown.rotation = 0
mandown.y = 260
mandown.x = 90
end
, 1)
end
wallbottom.collision = wallbottomcollision
wallbottom:addEventListener( “collision”, wallbottom )
rightg.y = 150
plat1.x = 70
plat1.y =100
plat2.x = 103
plat2.y= 285
plat2.width = 80
plat3.x=330
plat3.y=285
plat3.width = 130
spikesd.x = 200
spikesd.y = 110
spikesd.width = 50
spikesd.height = 100
spikesd:rotate(270 )
spikesl.x =200
spikesl.y = 305
spikesl.width = 50
spikesl.height = 100
spikesl:rotate(90)
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group2 = self.view
group2.x=0
physics.start()
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group2 = self.view
package.loaded[physics] = nil
physics = nil
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
print( “Hello world!” )
group2.x=0
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
print( “Hello world!” )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
print( “Hello world!” )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene[/lua]
Here is what I’m going to, the main menu:
[lua]-----------------------------------------------------------------------------------------
– menu.lua
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “widget” library
local widget = require “widget”
– forward declarations and other locals
local playBtn
– ‘onRelease’ event listener for playBtn
local function onPlayBtnRelease()
– go to level1.lua scene
storyboard.gotoScene( “level1”, “fade”, 500 )
return true – indicates successful touch
end
– BEGINNING OF YOUR IMPLEMENTATION
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
– display a background image
local background = display.newImageRect( “bg.png”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.TopLeftReferencePoint )
background.x, background.y = 0, 0
– create/position logo/title image on upper-half of the screen
local titleLogo = display.newImageRect( “logo.png”, 264, 42 )
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 20
local alert = native.showAlert( “Gravity Man”, “Welcome To Gravity Man! Your goal is to get your eggs back by using your gravity switching powers. Tilt to move and tap up and down to switch the gravity!”, { “OK”})
– create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
label=“Play Now”,
labelColor = { default={255}, over={128} },
default=“button.png”,
over=“button-over.png”,
width=154, height=40,
onRelease = onPlayBtnRelease – event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 50
– all display objects must be inserted into group
group:insert( background )
group:insert( titleLogo )
group:insert( playBtn )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
if playBtn then
playBtn:removeSelf() – widgets must be manually removed
playBtn = nil
end
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene
[import]uid: 184688 topic_id: 33479 reply_id: 133139[/import]
I didn’t see a createScene() function or event listener in the module you are going to.
Storyboard pretty much needs to have something in it’s scene.view which is created off screen then transitioned on screen. Typically this is done during the createScene() event which is called to setup the scene.
Most of that initialization code at the top needs to go into the createScene() function and at least one display object needs to be put into the scene view. This is the line:
local group = scene.view
and you need to do a
group:insert(someobject)
I’m pretty sure that’s what’s causing this error. [import]uid: 199310 topic_id: 33479 reply_id: 133148[/import]