iOS may be hiding the error better than Android is. Can you post your whole scene so I can see the relationship of where you’re creating/defining background and where you’re cleaning it?
here is the entire scene: i am posting it all because i have no idea what is going wrong…sorry it is so long
[lua]
module(…, package.seeall)
local localGroup
function clean ( event )
--physics.stop()
local ads = require “ads”
ads.init( “inneractive”, “NaBrOStudios_CavemanCrawl_iPhone” )
ads.show( “banner”, { x=0, y=0, interval=60 } )
– Some time later …
ads.hide()
print(“cleaned”)
end
function new()
localGroup = display.newGroup()
local physics = require(“physics”)
physics.start()
–> Set gravity to act “down” (ie towards the bottom of the phone)
physics.setGravity( 0, 9.8 ) – initial gravity points downwards
–physics.setDrawMode(“hybrid”)
– 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
director:changeScene( “level1”, “moveFromLeft”)
return true – indicates successful touch
end
local function onCredsBtnRelease(event)
– go to level1.lua scene
director:changeScene( “creds”, “moveFromLeft”)
return true – indicates successful touch
end
–ADS
local ads = require “ads”
local function adListener( event )
if event.isError then
– Failed to receive an ad.
print(“ads failed to load”)
end
end
ads.init( “inneractive”, “myAppId”, adListener )
ads.show( “banner”, { x=0, y=0, interval=60 } )
local leftWall = display.newRect(-64, 0, 1, display.contentHeight)
localGroup:insert(leftWall)
physics.addBody(leftWall, “static”, { bounce = 0.2 } )
–>Add background
background = display.newImage(“building1.png”, 0, 50, true)
background.xScale = 1.3
background.yScale = 1.3
localGroup:insert(background)
background2 = display.newImage(“building2.png”, 1475, 50, true)
background2.xScale = 1.3
background2.yScale = 1.3
localGroup:insert(background2)
background3 = display.newImage(“building3.png”, 2975, 50, true)
background3.xScale = 1.3
background3.yScale = 1.3
localGroup:insert(background3)
background4 = display.newImage(“brickbuilding.png”, 4476, 50, true)
background4.xScale = 1.3
background4.yScale = 1.3
localGroup:insert(background4)
–ADDING BRICKS(FLAMEBALLS)
bricks = {}
local function updateBlocks()
local check = math.random(1000)
local zuzu = graphics.newImageSheet( “fireballwitHit.png”, {width = 512, height= 512, numFrames = 15} )
– play 15 frames every 500 ms
local sequenceData = {
{ name=“regular”, frames={1, 2, 3, 7, 8, 13}, count = 6 , time=400, loopCount = 0 },
{ name = “exploder”, frames ={4, 5, 6, 9, 10, 11, 14, 15}, count =8, time = 1300, loopCount = 1 }
}
brick = display.newSprite( zuzu, sequenceData )
brick.x = check
brick.y = -500
brick.rotation = 90
brick.xScale = 0.6
brick.yScale = 0.6
brick.type = “brick”
localGroup:insert(brick)
brick:setSequence(“regular”)
brick:play()
table.insert(bricks, brick)
transition.to(brick, { time = 7000, y = 1100} )
end
timer.performWithDelay(4000, updateBlocks, -1)
–localGroup:insert(brick)
floor = display.newImage(“sidewalk.png”, -150, 690, true)
floor.xScale = 1.5
localGroup:insert(floor)
floor2 = display.newImage(“sidewalk4.png”, 1150, 690, true)
floor2.xScale = 1.5
localGroup:insert(floor2)
physics.addBody(floor, “static”, {bounce = 0} )
physics.addBody(floor2, “static”, {bounce = 0} )
–FALLING BRICKS–> Make bricks appear at top
brick3 = display.newImage(“1brick.png”, 100, -1200)
brick3.xScale = 0.5
brick3.yScale = 0.5
localGroup:insert(brick3)
brick4 = display.newImage(“1brick.png”, 400, -24000)
brick4.xScale = 0.5
brick4.yScale = 0.5
localGroup:insert(brick4)
brick5 = display.newImage(“1brick.png”, 650, -12000)
brick5.xScale = 0.5
brick5.yScale = 0.5
localGroup:insert(brick5)
brick6 = display.newImage(“1brick.png”, 800, -6000)
brick6.xScale = 0.5
brick6.yScale = 0.5
localGroup:insert(brick6)
brick7 = display.newImage(“1brick.png”, 950, -3000)
brick7.xScale = 0.5
brick7.yScale = 0.5
localGroup:insert(brick7)
–> Add face to stage and position
local hello = graphics.newImageSheet( “caveman.png”, { width=1077, height=1000.75, numFrames=12 } )
local face = display.newSprite( hello, { name=“hi”, frames={1, 3, 6, 7, 10, 8, 11, 9, 12, 4, 2, 5}, count = 12 , time=970, loopCount = 0 } )
face.x = 100
face.y = 0
face:play()
face.xScale = 0.4
face.yScale = 0.4
physics.addBody(face, { radius = 150, bounce = 0, friction = 0} )
face.angularDamping = 100
local w,h = display.contentWidth, display.contentHeight
transition.to( face, { time=5000, x=(w-95)} )
transition.to( face, { time=1500, delay=3500} )
backgroundSpeed = 6
floorSpeed = 8
function updateBackgrounds()
background.x = background.x - backgroundSpeed
if(background.x < -3900) then
background.x = 2050
end
background2.x = background2.x - (backgroundSpeed)
if(background2.x < -3900) then
background2.x = 2050
end
background3.x = background3.x - (backgroundSpeed)
if(background3.x < -3900) then
background3.x = 2050
end
background4.x = background4.x - (backgroundSpeed)
if(background4.x < -3900) then
background4.x = 2050
end
floor.x = floor.x - (floorSpeed)
if(floor.x < -1100) then
floor.x = 1850
end
floor2.x = floor2.x - (floorSpeed)
if(floor2.x < -1100) then
floor2.x = 1850
end
–Bricks
brick3.y = brick3.y + 5
brick3.rotation = brick3.rotation + 3
if(brick3.y > 1000) then
brick3.y = -1000
end
brick4.y = brick4.y + 6
brick4.rotation = brick4.rotation + 2
if(brick4.y > 1200) then
brick4.y = -3000
end
brick5.y = brick5.y + 5
brick5.rotation = brick5.rotation + 5
if(brick5.y > 1000) then
brick5.y = -7000
end
brick6.y = brick6.y + 5
brick6.rotation = brick6.rotation + 3
if(brick6.y > 1000) then
brick6.y = -13000
end
brick7.y = brick7.y + 5
brick7.rotation = brick7.rotation + 3
if(brick7.y > 1000) then
brick7.y = -21000
end
end
timer.performWithDelay(1, updateBackgrounds, -1)
local status = pcall( updateBackgrounds, background )
print( "pcall status is ", status )
local status = pcall( updateBackgrounds, backgroundSpeed )
print( "pcall status is ", status )
–Make player jump over whole(in floor) periodically
local function updateJump(event)
face:applyLinearImpulse( 0, -8, face.x, face.y )
end
timer.performWithDelay(6100, updateJump, -1)
– create a widget button (which will loads level1.lua on release)
playBtn = widget.newButton{
--label=“Play Now”,
--labelColor = { default={255}, over={128} },
default=“CAVE1.png”,
over=“CAVE2.png”,
width=400, height=113,
onRelease = onPlayBtnRelease – event listener function
}
playBtn:setReferencePoint( display.CenterReferencePoint )
playBtn.x = display.contentWidth*0.5
playBtn.y = display.contentHeight - 545
playBtn.xScale = 2.5
playBtn.yScale = 2.5
localGroup:insert(playBtn)
credsBtn = widget.newButton{
default=“CREDS1.png”,
over=“CREDS2.png”,
width=150, height=42,
onRelease = onCredsBtnRelease – event listener function
}
credsBtn:setReferencePoint( display.CenterReferencePoint )
credsBtn.x = display.contentWidth*0.5
credsBtn.y = display.contentHeight - 350
credsBtn.xScale = 2.5
credsBtn.yScale = 2.5
localGroup:insert(credsBtn)
localGroup:insert(face)
local function updateup(event)
playBtn:toFront()
credsBtn:toFront()
floor:toFront()
floor2:toFront()
face:toFront()
end
timer.performWithDelay(4001, updateup, -1)
return localGroup
end
[/lua]
Thanks for all of your help
Okay, here is what I think is happening. Your background is a global variable. I don’t see where you’re putting a “local” in front if it. You are, per Director’s requirements, putting it into localGroup.
If you are doing the same thing in your next scene, your background is overwriting this one and after the scene is transitioned on, it goes through and cleans up the old scene which means removing everything in localGroup, which includes your background.
Yes that is what i am trying to do (switch scenes and remove the “menu” scene which is coded above). When I build it for an iOS device it works fine, but when I build it for an android device and it goes to the “menu” scene, I get the director error “failed to execute new params”. Is there any reason why this may be happening?
Its very likely you are getting the error on iOS too, just that something there is letting you go on. What build of Corona are you using?
Whichever build is the most recent.
Can you make your background local and not a global?