Hey everyone, I am new to Corona (been using it for 3 weeks now) and I am having trouble getting a certain game mechanic to work in my code…
I want to change the background and redraw the main physics object when that object goes offscreen at the bottom. Unfortunately it doesn’t do that, the object just keeps falling.
What I want to accomplish is having a ball fall down from the sky and changing the backgrounds every time it reaches the bottom of the screen and then redrawing the object on top. I want to have 3-4 layers (bgs) until he hits the ground.
The way I coded it would have the screen change and not have it scroll with the actor. I would like to see if I can accomplish this method then maybe I will try to implement the other method.
Any help would be appreciated,
Here is my code:
[code]
module(…, package.seeall)
local localGroup = display.newGroup()
local physics = require(“physics”)
local levelstate = 1
physics.start()
physics.setGravity(0, 8.1)
–***************
–this new method is needed for the each screen!
–***************
function new()
display.setStatusBar( display.HiddenStatusBar )
startGame()
return localGroup
end
–*************
–End of New() Function–
–*************
–==
function startGame()
if (levelstate == 1) then
levelA()
end
if (levelstate == 2) then
levelB()
end
if (levelstate == 3) then
levelC()
end
if (levelstate == 4)then
endLevel()
end
end–end of startGame
function levelA()
local bg = display.newImage(“bg_leveloneA.png”)
local bob = display.newImage(“bob_sprite.png”)
bob.x = _W / 2
physics.addBody(bob)
–if bob exits screen, change levelstate to go to the
–next screen
if (bob.y < 300) then
levelstate = levelstate + 1
end–if
end–end of levelA()
function levelB()
local bg = display.newImage(“bg_leveloneB.png”)
local bob = display.newImage(“bob_sprite.png”)
localGroup:insert(bg)
localGroup:insert(bob)
bob.x = _W / 2
physics.addBody(bob)
end–end of levelB()
function levelC()
local bg = display.newImage(“bg_leveloneB.png”)
local bob = display.newImage(“bob_sprite.png”)
localGroup:insert(bg)
localGroup:insert(bob)
bob.x = _W / 2
physics.addBody(bob)
end–end of LevelC()
function endLevel()
bob.x = _W / 2
end
–=========
–end of page
[/code] [import]uid: 12540 topic_id: 11356 reply_id: 311356[/import]