Problem with sprite gravity when starting game again!

In my game, the menu functions correctly and transitions the user to the main game play.  When the user collides with the paparazzi, the game then transitions to the game over scene also correctly.  When starting the game again, without refreshing the corona simulator, the physics on the main character sprite doesn’t seem to be working!  I believe that the character is turning into a static object for some odd reason!

I have been trying to solve this for hours!  I am new to corona so any help would be appreciated! HELP!

I need the main character sprite to function normally with gravity just like the first round!

[lua] --menu.lua file

–remove status bar

display.setStatusBar(display.HiddenStatusBar)

–declare modules

local storyboard = require “storyboard”

local scene = storyboard.newScene()

local celebrityChoice

local game = require “game”

local saveValue = function( strFilename, strValue)

–specified value to specified file

local theFile = strFilename

local theValue = strValue

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “w+” )

if file then

–write game distance to the text file

file:write( theValue )

io.close( file )

end

end

local loadValue = function( strFilename )

–will load specified file, or create a new file if it doesn’t exist

local theFile = strFilename

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “r” )

if file then

–read ALL contents of file into a string 

local contents = file:read( “*a” )

io.close( file )

return contents

else

–create file because it doesn’t exist yet

file = io.open( path, “w” )

file:write( “0” )

io.close( file )

return “0”

end

end

–create scene

function scene:createScene( event )

local group = self.view

end

–enter scene

function scene:enterScene( event )

local group = self.view

local celebrityChoiceFilename = “celebrityChoice.text”

local loadedCelebrityChoice = 

loadValue( celebrityChoiceFilename )

local celebrityChoice = tostring( loadedCelebrityChoice ) 

local menuBG = display.newRect(100, 100, 1220, 840)

local celebrityDashLogo = display.newText(“Hollywood Hustle!”, 250, 50, “Helvetica”, 40)

celebrityDashLogo:setFillColor(0, 0, 255)

local characterSelection = display.newText(“Select a celebrity below…”, 250, 120, “Helvetica”, 35)

characterSelection:setFillColor(0, 0, 255)

local instructions = display.newText(“Tap To Avoid The Paparazzi!”, 250, 280, “Arial”, 20)

instructions:setFillColor(0, 0, 255)

local man = display.newImage(“imageedit_3_3764584809.gif”)

man.x = 230; man.y = 200

man:scale(.7, .7)

–local charactersText = display.newText(“More Characters Coming Soon!”, 400, 250, “Arial”, 15)

–charactersText:setFillColor(255, 0, 0)

local actress = display.newImage(“imageedit_4_4124479133.gif”)

actress.x = 110; actress.y = 200

actress:scale(.7, .7)

local rapper = display.newImage(“imageedit_5_6564493317.gif”)

rapper.x = 340; rapper.y = 200

rapper:scale(.6, .6)

–local businessman = display.newImage(“imageedit_1_2890287552.gif”)

–businessman.x = 400; businessman.y = 260

–businessman:scale(.57, .57)

–sprite information

local sheetData = {

width = 65,

height = 70,

numFrames = 4,

sheetContentWidth = 260,

sheetContentHeight = 70,

}

–restart game function

function restartGame()

storyboard.removeScene( “gameover” )

print(“remove scene gameover completed!”)

storyboard.gotoScene( “game” )

print(“go to scene game completed!”)

end

–choose character to use in game

function chooseMan(event)

if (event.phase == “began”) then

local manSprite = “imageedit_6_8353289250.gif”

celebrityChoice = “imageedit_6_8353289250.gif”

local celebrityChoiceFilename = “celebrityChoice.text”

saveValue( celebrityChoiceFilename, tostring(celebrityChoice))

restartGame()

man:removeEventListener(“touch”, chooseMan)

actress:removeEventListener(“touch”, chooseActress)

rapper:removeEventListener(“touch”, chooseRapper)

end

end

function chooseActress(event)

if (event.phase == “began”) then

local actressSprite = “imageedit_1_7432539712.gif”

celebrityChoice = “imageedit_1_7432539712.gif”

local celebrityChoiceFilename = “celebrityChoice.text”

saveValue( celebrityChoiceFilename, tostring(celebrityChoice))

restartGame()

actress:removeEventListener(“touch”, chooseActress)

man:removeEventListener(“touch”, chooseMan)

rapper:removeEventListener(“touch”, chooseRapper)

end

end

function chooseRapper(event)

if (event.phase == “began”) then

local rapperSprite = “imageedit_5_3020933657.gif”

celebrityChoice = “imageedit_5_3020933657.gif”

local celebrityChoiceFilename = “celebrityChoice.text”

saveValue( celebrityChoiceFilename, tostring(celebrityChoice))

restartGame()

rapper:removeEventListener(“touch”, chooseRapper)

actress:removeEventListener(“touch”, chooseActress)

man:removeEventListener(“touch”, chooseMan)

end

end

–function chooseBusinessman(event)

–if (event.phase == “began”) then

–local businessmanSprite = “imageedit_4_7784128043.gif”

–celebrityChoice = “imageedit_4_7784128043.gif”

–local celebrityChoiceFilename = “celebrityChoice.text”

–saveValue( celebrityChoiceFilename, tostring(celebrityChoice))

–storyboard.gotoScene( “game” )

–businessman:removeEventListener(“touch”, chooseBusinessman)

–end

–end

man:addEventListener(“touch”, chooseMan)

actress:addEventListener(“touch”, chooseActress)

rapper:addEventListener(“touch”, chooseRapper)

–businessman:addEventListener(“touch”, chooseBusinessman)

end

–exit scene

function scene:exitScene( event )

local group = self.view

end

–destroy scene

function scene:destroyScene( event )

local group = self.view

end

scene:addEventListener( “createScene”, scene)

scene:addEventListener( “enterScene”, scene)

scene:addEventListener( “exitScene”, scene)

scene:addEventListener( “destroyScene”, scene)

return scene  [/lua]

[lua] --game.lua

–remove status bar

display.setStatusBar(display.HiddenStatusBar)

–declare modules

local storyboard = require “storyboard”

local scene = storyboard.newScene()

local physics = require “physics”

physics.start()

physics.setGravity( 0, 100)

local stage = display.currentStage

local levelSpeed = 5

local gameIsActive = false

local saveValue = function( strFilename, strValue)

–specified value to specified file

local theFile = strFilename

local theValue = strValue

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “w+” )

if file then

–write game distance to the text file

file:write( theValue )

io.close( file )

end

end

local loadValue = function( strFilename )

–will load specified file, or create a new file if it doesn’t exist

local theFile = strFilename

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “r” )

if file then

–read ALL contents of file into a string 

local contents = file:read( “*a” )

io.close( file )

return contents

else

–create file because it doesn’t exist yet

file = io.open( path, “w” )

file:write( “0” )

io.close( file )

return “0”

end

end

–create scene

function scene:createScene( event )

local group = self.view

end

–enter scene

function scene:enterScene( event )

local group = self.view

local highDistanceFilename = “highDistance.text”

local loadedHighDistance = 

loadValue( highDistanceFilename )

local highScore = tonumber( loadedHighDistance )

local celebrityChoiceFilename = “celebrityChoice.text”

local loadedCelebrityChoice = 

loadValue( celebrityChoiceFilename )

local celebrityChoice = tostring( loadedCelebrityChoice ) 

–sprite information

local sheetData = {

width = 65,

height = 70,

numFrames = 4,

sheetContentWidth = 260,

sheetContentHeight = 70,

}

local celebrity = graphics.newImageSheet( “”…tostring(celebrityChoice), sheetData )

local sequenceData = {

{ name = “celebrityRun”,

frames = { 1,2,3,4},

time = 400,

loopCount = 1000000000000000000000000000000000000000000000000

}

}

–make sky background

local bg = display.newRect( 250, 100, 1220, 840)

bg:setFillColor(0,0,255)

–makes celebrity run animation

local celebrityRun = display.newSprite( celebrity, sequenceData )

celebrityRun.x = -10

celebrityRun.y = 270

physics.addBody(celebrityRun, “dynamic”, {friction = 0,bounce = 0})

celebrityRun:play()

celebrityRun.isFixedRotation = true --To stop it rotating when jumping etc

celebrityRun.isSleepingAllowed = false --To force it to update and fall off playforms correctly

–celebrity jump

local function celebrityJump( event )

if (event.numTaps == 1) then

celebrityRun.y = celebrityRun.y - 150

elseif(event.numTaps > 1) then

celebrityRun.y = celebrityRun.y - 200

return(true)

end

end

Runtime:addEventListener(“tap”, celebrityJump)

–first level

local firstLevel = display.newRect(165, 315, 1220, 10)

firstLevel:setFillColor(255, 0, 0)

physics.addBody( firstLevel, “static”, {friction = 0, density = 1, bounce = 0})

–levels

local secondLevel1 = display.newRect(220, 190, 100, 10)

secondLevel1:setFillColor(255, 0, 0)

local secondLevel2 = display.newRect(450, 190, 100, 10)

secondLevel2:setFillColor(255, 0, 0)

physics.addBody(secondLevel1, “static”, {friction = 0, density = 1, bounce = 0})

physics.addBody(secondLevel2, “static”, {friction = 0, density = 1, bounce = 0})

local thirdLevel1 = display.newRect(260, 100, 80, 10)

thirdLevel1:setFillColor(255, 0, 0)

local thirdLevel2 = display.newRect(490, 100, 80, 10)

thirdLevel2:setFillColor(255, 0, 0)

physics.addBody(thirdLevel1, “static”, {friction = 0, density = 1, bounce = 0})

physics.addBody(thirdLevel2, “static”, {friction = 0, density = 1, bounce = 0})

–paparazzi1

local paparazzi1 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi1.x = 800

paparazzi1.y = 283

physics.addBody(paparazzi1, “static”, {friction = 0, density = 0, bounce = 0})

–paparazzi2

local paparazzi2 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi2.x = math.random(350, display.contentWidth)

paparazzi2.y = 160

physics.addBody(paparazzi2, “static”, {friction = 0, density = 0, bounce = 0})

–paparazzi3

local paparazzi3 = display.newImage(“rsz_imageedit_1_8583966754.png”)

paparazzi3.x = math.random(450, display.contentWidth)

paparazzi3.y = 70

physics.addBody(paparazzi3, “static”, {friction = 0, density = 0, bounce = 0})

–wall to prevent character from being pushed off screen (left)

local wall = display.newRect(-45, 100, 5, 500)

physics.addBody(wall, “static”, {friction = 0, density = 1})

wall.alpha = 0

–current distance

local currentDistance = 0

–distance score

local distanceText = display.newText("Distance: ", 245, 20, “Arial”, 30) 

local objectGroup = display.newGroup()

–Main gameLoop function

function gameLoop( event )

if (gameIsActive == true) then

currentDistance = currentDistance + 1

distanceText.text = "Distance: "…currentDistance

–Move the other items and platforms. 

–If they are far left of the screen we remove them.

local i

for i = objectGroup.numChildren,1,-1 do

local object = objectGroup[i]

if object ~= nil and object.y ~= nil then

object:translate( -levelSpeed, 0)

if object.x < -175 then 

display.remove(object); object = nil;

end

end

end

–Move the background, ground, and levels

–We then check to see if they need to be replaced.

bg:translate(-(levelSpeed)*0.6,0)

secondLevel1:translate(-levelSpeed,0)

secondLevel2:translate(-levelSpeed,0)

thirdLevel1:translate(-levelSpeed,0)

thirdLevel2:translate(-levelSpeed,0)

paparazzi1:translate(-levelSpeed, 0)

paparazzi2:translate(-levelSpeed, 0)

paparazzi3:translate(-levelSpeed, 0)

if secondLevel1.x <= -100 then

secondLevel1.x = secondLevel1.x + 600 

end

if secondLevel2.x <= -100 then

secondLevel2.x = secondLevel2.x + 600 

end

if thirdLevel1.x <= -100 then

thirdLevel1.x = thirdLevel1.x + 600 

end

if thirdLevel2.x <= -100 then

thirdLevel2.x = thirdLevel2.x + 600 

end

if paparazzi1.x <= -75 then

paparazzi1.x = math.random(600,1000) 

end

if paparazzi2.x <= -75 then

paparazzi2.x = math.random(900,2000) 

end

if paparazzi3.x <= -75 then

paparazzi3.x = math.random(1000,1500) 

end

if bg.x <= -50 then bg.x = bg.x + 400 

end

end

end

gameIsActive = true

Runtime:addEventListener(“enterFrame”,gameLoop)

–make speed of game faster

function speedBoost( event )

if (currentDistance  >= 200) then

levelSpeed = 6

end

if (currentDistance  >= 450) then

levelSpeed = 8

end

if (currentDistance  >= 700) then

levelSpeed = 10

end

if (currentDistance  >= 1100) then

levelSpeed = 12

end

end

Runtime:addEventListener(“enterFrame”, speedBoost)

–collided

function gameOver()

storyboard.gotoScene(“gameover”, “fade”, 200)–go to game over scene

print(“go to scene gameover completed!”)

end

–paparazzi collision

local function onCollision(event)

if (event.phase == “began”) then

print(“collision began”)

levelSpeed = 0

celebrityRun.alpha = 0

paparazzi1:removeEventListener(“collision”, onCollision)

paparazzi2:removeEventListener(“collision”, onCollision)

paparazzi3:removeEventListener(“collision”, onCollision)

gameOver()

print(highScore)

print(currentDistance)

if currentDistance > highScore then

highScore = currentDistance

local highDistanceFilename = “highDistance.text”

saveValue( highDistanceFilename, tostring(highScore))

end

end

end 

paparazzi1:addEventListener(“collision”, onCollision)

paparazzi2:addEventListener(“collision”, onCollision)

paparazzi3:addEventListener(“collision”, onCollision)

end

–exit scene

function scene:exitScene( event )

local group = self.view

Runtime:removeEventListener(“tap”, celebrityJump)

Runtime:removeEventListener(“enterFrame”, speedBoost)

Runtime:removeEventListener(“enterFrame”,gameLoop)

end

–destroy scene

function scene:destroyScene( event )

local group = self.view

end

scene:addEventListener( “createScene”, scene)

scene:addEventListener( “enterScene”, scene)

scene:addEventListener( “exitScene”, scene)

scene:addEventListener( “destroyScene”, scene)

return scene  [/lua]

[lua] --gameover.lua

–declare modules

local storyboard = require “storyboard”

local scene = storyboard.newScene()

local game = require “game”

–create scene

function scene:createScene( event )

local group = self.view

end

–enter scenes

function scene:enterScene( event )

local group = self.view

local saveValue = function( strFilename, strValue)

–specified value to specified file

local theFile = strFilename

local theValue = strValue

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “w+” )

if file then

–write game distance to the text file

file:write( theValue )

io.close( file )

end

end

local loadValue = function( strFilename )

–will load specified file, or create a new file if it doesn’t exist

local theFile = strFilename

local path = system.pathForFile( theFile, system.DocumentsDirectory )

–io.open opens a file at path. returns nil if no file found

local file = io.open( path, “r” )

if file then

–read ALL contents of file into a string 

local contents = file:read( “*a” )

io.close( file )

return contents

else

–create file because it doesn’t exist yet

file = io.open( path, “w” )

file:write( “0” )

io.close( file )

return “0”

end

end

local highDistanceFilename = “highDistance.text”

local loadedHighDistance = 

loadValue( highDistanceFilename )

local highScore = tonumber( loadedHighDistance )

cameraSound = audio.loadStream(“camera-shutter-click-05.mp3”)–camera snap sound

audio.play(cameraSound)–play camera sound

display.newRect(250, 100, 1220, 840)

local gameOverText = display.newText(“Game Over!”, 250, 50, “Arial”, 35)

gameOverText:setFillColor(255, 0, 0)

local gameOverText2 = display.newText(“The paparazzi got you!”, 250, 100, “Arial”, 25)

gameOverText2:setFillColor(255, 0, 0)

local highDistanceText = display.newText("High Distance: "…tostring(highScore), 240, 150, “Arial”, 25)

highDistanceText:setFillColor(255, 0, 0)

local restartGameText = display.newText(“Click anywhere to run again !”, 240, 230, “Arial”, 30)

restartGameText:setFillColor(255, 0, 0)

function touchScreen(event)

if (event.phase == “began”) then

storyboard.removeScene( “game” )

print(“remove scene game completed!”)

storyboard.gotoScene( “menu” ) 

print(“go to scene menu completed!”)

end

end

Runtime:addEventListener(“touch”, touchScreen)

end

–exit scene

function scene:exitScene( event )

local group = self.view

Runtime:removeEventListener(“touch”, touchScreen)

end

–destroy scene

function scene:destroyScene( event )

local group = self.view

end

scene:addEventListener( “createScene”, scene)

scene:addEventListener( “enterScene”, scene)

scene:addEventListener( “exitScene”, scene)

scene:addEventListener( “destroyScene”, scene)

return scene  [/lua]