Getting error code

Hi, this error keeps on appearing after my scene changes from game to score scene . I know i posted a lot of code on here, but the error is between lines 110 and 130!!! If anyone can help, I would be extremely grateful!!

If your going to criticize my code, please keep in mind I’m new to corona sdk.

local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- local physics = require( "physics" ) physics.start() --physics.setDrawMode( "hybrid" ) physics.setGravity( 0,-.07 ) -- -------------------- local lives = 1 local score = 0 local died = false local ship local gameLoopTimer local scoreText -- set up display groups local backGroup local mainGroup local uiGroup sheetInfo = require("explosion") -- init the image sheet explosion = graphics.newImageSheet( "explosion.png", sheetInfo:getSheet() ) sequenceData = { -- set up anmiation { name="explosion", -- name of the animation (used with setSequence) explosion=myImageSheet, -- the image sheet start=sheetInfo:getFrameIndex("1"), -- name of the first frame count=10, -- number of frames time=2250, -- speed loopCount=1, -- repeat direction ="forward", }, } explosion = display.newSprite( explosion, sequenceData ) explosion.myName = "explosion" explosion.x = x explosion.y = y explosion:setSequence("explosion") explosion:play() explosion.isVisible = false ---------------------------------------------------------------------------------------- -- Drone Placement local droneInfo = require "drone" local droneSheet = graphics.newImageSheet( "drone.png", droneInfo:getSheet() ) local droneSeqData = { {name = "droe", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } local drone = display.newSprite( droneSheet, droneSeqData ) drone.x = display.contentWidth-570 drone.y = display.contentHeight-200 drone:setSequence( "idle" ) drone:play() drone.speed = math.random(6, 12) drone.initY = drone.y drone.amp = math.random(20,100) drone.angle = math.random(20,80) physics.addBody( drone,"static", {density=.1, bounce=0.1, }) local droneInfo = require "drone" local droneSheet = graphics.newImageSheet( "drone.png", droneInfo:getSheet() ) local droneSeqData = { {name = "droe2", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } local drone2 = display.newSprite( droneSheet, droneSeqData ) drone2.x = display.contentWidth-370 drone2.y = display.contentHeight-200 drone2:setSequence( "idle" ) drone2:play() drone2.speed = math.random(6, 12) drone2.initY = drone2.y drone2.amp = math.random(20,100) drone2.angle = math.random(20,80) physics.addBody( drone2 ,"static", {density=.1, bounce=0.1, }) ---------------------------------------------------------------------------------------- -- helicopter Working function moveHelicopters(self,event) if helicopter.x \<- 350 then helicopter.x = 550 helicopter.speed = math.random(6, 18) helicopter.amp = math.random(60,80) helicopter.angle = math.random(20,80) else helicopter.x = helicopter.x - helicopter.speed helicopter.angle = helicopter.angle + .05 helicopter.y = helicopter.amp\*math.sin(helicopter.angle)+helicopter.initY end end ---------------------------------------------------------------------------------------- local function updateText() scoreText.text = "Score: ".. score end function moveDrones(self,event) if drone.x \<- 180 then drone.x = 571 drone.speed = math.random(6, 18) drone.amp = math.random(80,120) drone.angle = math.random(60,80) else drone.x = drone.x - drone.speed drone.angle = drone.angle + .04 drone.y = drone.amp\*math.sin(drone.angle)+drone.initY end end drone.enterFrame = moveDrones Runtime:addEventListener("enterFrame", drone) -- ship Movements function activateShips(self, event) self:applyForce( 0, -02.1, ship.x, ship.y) end function touchScreen(event) if event.phase == "began" then ship.enterFrame = activateShips Runtime:addEventListener("enterFrame", ship) end if event.phase == "ended" then Runtime:removeEventListener("enterFrame", ship ) end end ---------------------------------------------------------------------------------------- -- explosion effect function explode() explosion.x = ship.x explosion.y = ship.y explosion.isVisible = true explosion:play() ship.isVisible = false end ---------------------------------------------------------------------------------------- -- Drones Working function moveDrones(self,event) if drone2.x \<- 180 then drone2.x = 571 drone2.speed = math.random(6, 18) drone2.amp = math.random(60,120) drone2.angle = math.random(60,80) else drone2.x = drone2.x - drone2.speed drone2.angle = drone2.angle + .03 drone2.y = drone2.amp\*math.sin(drone2.angle)+drone2.initY score = score + 1 scoreText.text = "Score: " .. score end end drone2.enterFrame = moveDrones Runtime:addEventListener("enterFrame", drone2) ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen physics.pause() -- Temporarily pause the physics engine -- Set up display groups backGroup = display.newGroup() -- Display group for the background image sceneGroup:insert( backGroup ) -- Insert into the scene's view group mainGroup = display.newGroup() -- Display group for the ship, asteroids, lasers, etc. sceneGroup:insert( mainGroup ) -- Insert into the scene's view group uiGroup = display.newGroup() -- Display group for UI objects like the score sceneGroup:insert( uiGroup ) -- -------------------------------------------------------------------------------------------------- local background = display.newImageRect( backGroup, "background.png", 740, 415 ) background.x = display.contentCenterX background.y = display.contentCenterY -- helicopter placement helicopterInfo = require "helicopter" helicopterSeqData = { {name = "heli", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } helicopterSheet = graphics.newImageSheet( "helicopter.png", helicopterInfo:getSheet() ) helicopter = display.newSprite( mainGroup ,helicopterSheet, helicopterSeqData ) physics.addBody( helicopter,"static",{density=.1, bounce=0.1, friction=.2, radius=30 } ) helicopter.x = display.contentWidth-570 helicopter.y = display.contentHeight-200 helicopter:setSequence( "idle" ) helicopter:play() helicopter.speed = math.random(8, 18) helicopter.initY = helicopter.y helicopter.amp = math.random(20,100) helicopter.angle = math.random(40,80) -- -------------------------------------------------------------------------------------------------- local city1 = display.newImageRect(backGroup, "city1.png", 720, 580 ) city1.x = 0 city1.y = display.contentHeight-280 -- -------------------------------------------------------------------------------------------------- local city2 = display.newImageRect(backGroup, "city1.png", 720, 580 ) city2.x = 780 city2.y = display.contentHeight-280 local top = display.newImageRect( mainGroup, "top.png", 130, 15 ) top.x = 60 top.y = -10 physics.addBody( top,"static", {} ) local bottom = display.newImageRect( mainGroup, "top.png", 130, 15 ) bottom.x = 60 bottom.y = 435 physics.addBody( bottom,"static", {} ) local bottom = display.newImageRect( mainGroup, "top.png", 130, 15 ) bottom.x = 60 bottom.y = 435 physics.addBody( bottom,"static", {} ) local gravityButtom = display.newImageRect(mainGroup, "GravityButton.png", 140, 140 ) gravityButtom.x = 400 gravityButtom.y = 350 -- -------------------------------------------------------------------------------------------------- local function endGame() composer.setVariable( "finalScore", score ) composer.gotoScene( "highscore", { time=800, effect="crossFade" } ) end -- collisiion function function onCollision(event) if event.phase == "began" then if ship.collided == false then ship.collided = true timer.performWithDelay( 2000, endGame ) ship.bodyType = "static" explode() else end end end Runtime:addEventListener("collision", onCollision) -- -------------------------------------------------------------------------------------------------- city1.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city1) city2.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city2) -- ---------------------------------------------------------------------------------------- ship = display.newImageRect( mainGroup, "alienship.png", 60, 45 ) ship.myName = "ship" ship.x = -400 ship.y = 195 ship.collided = false physics.addBody( ship, "static", { radius=20, bounce= 0}) function alienReady() ship.bodyType = ("dynamic") ship.gravityScale = -1085 end transition.to(ship,{time=1000, x=10, onComplete=alienReady}) gravityButtom:addEventListener( "touch" , touchScreen) scoreText = display.newText(uiGroup, "Score: " .. score, 400, 80, native.systemFont, 36) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen physics.start() Runtime:addEventListener("collision", onCollision) helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", moveHelicopters) end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen physics.start() Runtime:addEventListener("collision", onCollision) physics.pause() composer.removeScene( "game" ) end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view local function endGame() composer.setVariable( "finalScore", score ) composer.gotoScene( "highscore", { time=800, effect="crossFade" } ) composer.removeScene( "game" ) end end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

line 114 if helicopter.x <- 350 then

line 140 if drone.x <- 180 then

line 196 if drone2.x <- 180 then

You must change <- to <= for all sources.

p.s: Corona told you the problem very accurately. :smiley:

I’ve tried that before it doesn’t work!!!

Basically, this is an error that occurs because helicopter is nil.

It’s not accurate, but try the following:

[lua]

function helicopter:enterFrame()

    if self.x <= 350 then

 

    end

end

 

Runtime:addEventListener( “enterFrame”, helicopter )

[/lua]

Thanks, but no thanks!

What I don’t understand, are you guy’s not understanding? I’ve just stated that “I’m a new developer”! Meaning, that I don’t really understand, when you just tell my try this, you have to be a little more specific; it’s like when some comes to you to proof read their essay, you just don’t tell him fix you punctuation, capitalization or spelling you have to basically point at their mistakes and fix it!!!  IN OTHER WORDS REWRITE IT FOR THEM

Thanks for your effort, sincerely !!!

There are two ways to do enterFrame listeners. One is function based, the other is object based.  When you do:

helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", moveHelicopters)

You’re doing object-based and I believe you should probably do:

helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", helicopter)

But in doing so, the function “moveHelicopters” would use “self” to reference the object:

-- helicopter Working function moveHelicopters(self,event) if self.x \<= 350 then self.x = 550 --\<----- you might want to make sure this is right since you're testing against 350 above self.speed = math.random(6, 18) self.amp = math.random(60,80) self.angle = math.random(20,80) else self.x = self.x - self.speed self.angle = self.angle + .05 self.y = self.amp\*math.sin(self.angle)+self.initY end end

Or if you want to do the function based version, you can leave everything named helicopter and do:

Runtime:addEventListener(“enterFrame”, moveHelicopter") and the function continue’s to reference helicopter.

Rob

I just fixed error.

p.s: I gave up modifying the code in the middle. bcuz I can not make your game. @_@

p.s 2: Corona is the right engine for beginners. However, you should have basic knowledge.

Go to the bookstore and look at any book related to Lua.

Choose the thinnest book for beginners.

After reading the book and learning Lua language,

Corona API documentation will help you.

[lua]

local composer = require( “composer” )

local scene = composer.newScene()

local physics = require( “physics” )

physics.start()

–physics.setDrawMode( “hybrid” )

physics.setGravity( 0,-.07 )

local lives = 1

local score = 0

local died = false

local ship

local gameLoopTimer

local scoreText

– set up display groups

local backGroup

local mainGroup

local uiGroup

function activateShips(self, event)

    self:applyForce( 0, -02.1, ship.x, ship.y)

end

function touchScreen(event)

    if event.phase == “began” then

        ship.enterFrame = activateShips

        Runtime:addEventListener(“enterFrame”, ship)

    elseif event.phase == “ended” then

        Runtime:removeEventListener(“enterFrame”, ship )

    end

end

function explode()

    explosion.x = ship.x

    explosion.y = ship.y

    explosion.isVisible = true

    explosion:play()

    ship.isVisible = false

end

local function endGame()

    composer.setVariable( “finalScore”, score )

    composer.gotoScene( “highscore”, { time=800, effect=“crossFade” } )

    – composer.removeScene( “game” )

end

local function onCollision(event)

    if event.phase == “began” then

        if ship.collided == false then

            ship.collided = true

            timer.performWithDelay( 2000, endGame )

            ship.bodyType = “static”

            explode()

        else

        end

    end

end

local function moveDrone( self, event )

    if self.x == nil then return end

    if self.x <- 180 then

        self.x = 571

        self.speed = math.random(6, 18)

        self.amp = math.random(60,120)

        self.angle = math.random(20,80)

    else

        self.x = self.x - self.speed

        self.angle = self.angle + .03

        self.y = self.amp*math.sin(self.angle)+self.initY

        score = score + 1

        scoreText.text = "Score: " … score

    end

end

local function moveHelicopter( self, event )

    – if self.x == nil then return end

    self.x = 350

    if self.x <- 350 then

        self.x = 550

        self.speed = math.random(6, 18)

        self.amp = math.random(60,80)

        self.angle = math.random(20,80)

    else

        self.x = self.x - self.speed

        self.angle = self.angle + .05

        self.y = self.amp*math.sin(self.angle)+self.initY

    end

end

local function scrollCity( self, event )

end

function scene:create( event )

    local sceneGroup = self.view

    physics.pause()

    – Set up display groups

    backGroup = display.newGroup()  – Display group for the background image

    sceneGroup:insert( backGroup )  – Insert into the scene’s view group

    mainGroup = display.newGroup()  – Display group for the ship, asteroids, lasers, etc.

    sceneGroup:insert( mainGroup )  – Insert into the scene’s view group

    uiGroup = display.newGroup()    – Display group for UI objects like the score

    sceneGroup:insert( uiGroup )

    local background = newImageRect( backGroup, “background.png”, centerX, centerY, 740, 415 )

   

    local info = require(“explosion”)

    local sheet = graphics.newImageSheet( “explosion.png”, info:getSheet() )

    local seq =

    {

        { name=“explosion”, start=1, count=10, time=2250, loopCount=1, direction =“forward” },

    }

    explosion = newSprite( mainGroup, “explosion”, 0, 0, sheet, seq )

    explosion:play()

    explosion.isVisible = false

    local info = require(“drone”)

    local sheet = graphics.newImageSheet( “drone.png”, info:getSheet() )

    local seq = 

    {

        { name = “droe”, frames = {1,2,3}, time=150, loopCount=0, loopDirection = “forward” },

    }

    drone = newSprite( mainGroup, “idle”, scrW-570, scrH-200, sheet, seq )

    drone:play()

    drone.speed = math.random(6, 12)

    drone.amp = math.random(20,100)

    drone.angle = math.random(20,80)

    physics.addBody( drone,“static”, {density=.1, bounce=0.1, })

    drone2 = newSprite( mainGroup, “idle”, scrW-370, scrH-200, sheet, seq )

    drone2:play()

    drone2.speed = math.random(6, 12)

    drone2.amp = math.random(20,100)

    drone2.angle = math.random(20,80)

    physics.addBody( drone2,“static”, {density=.1, bounce=0.1, })

    local info = require(“helicopter”)

    local sheet = graphics.newImageSheet( “helicopter.png”, info:getSheet() )

    local seq =

    {

       { name = “heli”, frames = {1,2,3}, time=150, loopCount=0, loopDirection = “forward” },

    }

    helicopter = newSprite( mainGroup, “idle”, 350, scrH-200, sheet, seq )

    helicopter:play()

    helicopter.speed = math.random(8, 18)

    helicopter.amp = math.random(20,100)

    helicopter.angle = math.random(40,80)

    physics.addBody( helicopter,“static”,{density=.1, bounce=0.1, friction=.2, radius=30 } )

    

    local city1 = newImageRect(backGroup, “city1.png”, 0, scrH-280, 720, 580 )

    local city2 = newImageRect(backGroup, “city1.png”, 780, scrH-280, 720, 580 )

    

    local top = newImageRect( mainGroup, “top.png”, 60, -10, 130, 15 )

    physics.addBody( top,“static”, {} )

    local bottom = newImageRect( mainGroup, “top.png”, 60, 435, 130, 15 )

    physics.addBody( bottom,“static”, {} )

    

    local gravityButtom = newImageRect(mainGroup, “GravityButton.png”, 400, 350, 140, 140 )

    gravityButtom:addEventListener( “touch”, touchScreen )

    – city1.enterFrame = scrollCity

    – Runtime:addEventListener(“enterFrame”, city1)

    – city2.enterFrame = scrollCity

    – Runtime:addEventListener(“enterFrame”, city2)

    ship = newImageRect( mainGroup, “alienship.png”, -400, 195, 60, 45 )

    ship.myName = “ship”

    ship.collided = false

    physics.addBody( ship, “static”, {  radius=20, bounce= 0})

    function alienReady()

        ship.bodyType = (“dynamic”)

        ship.gravityScale = -1085

    end

    transition.to(ship, {time=1000, x=10, onComplete=alienReady})

    scoreText = newText( uiGroup, "Score: " … score, 400, 80, 0, 0, native.systemFont, 36 )

    drone.enterFrame = moveDrone

    drone2.enterFrame = moveDrone

    helicopter.enterFrame = moveHelicopter

    

    Runtime:addEventListener( “enterFrame”, drone )

    Runtime:addEventListener( “enterFrame”, drone2 )

    Runtime:addEventListener( “enterFrame”, helicopter )

end

function scene:show( event )

    local phase = event.phase

    if ( phase == “will” ) then

      

    elseif ( phase == “did” ) then

        physics.start()

        Runtime:addEventListener(“collision”, onCollision)

    end

end

function scene:hide( event )

    local phase = event.phase

    if ( phase == “will” ) then

      

    elseif ( phase == “did” ) then

        physics.pause()

        composer.removeScene( “game” )

    end

end

function scene:destroy( event )

end

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )

return scene

[/lua]

line 114 if helicopter.x <- 350 then

line 140 if drone.x <- 180 then

line 196 if drone2.x <- 180 then

You must change <- to <= for all sources.

p.s: Corona told you the problem very accurately. :smiley:

I’ve tried that before it doesn’t work!!!

Basically, this is an error that occurs because helicopter is nil.

It’s not accurate, but try the following:

[lua]

function helicopter:enterFrame()

    if self.x <= 350 then

 

    end

end

 

Runtime:addEventListener( “enterFrame”, helicopter )

[/lua]

Thanks, but no thanks!

What I don’t understand, are you guy’s not understanding? I’ve just stated that “I’m a new developer”! Meaning, that I don’t really understand, when you just tell my try this, you have to be a little more specific; it’s like when some comes to you to proof read their essay, you just don’t tell him fix you punctuation, capitalization or spelling you have to basically point at their mistakes and fix it!!!  IN OTHER WORDS REWRITE IT FOR THEM

Thanks for your effort, sincerely !!!

There are two ways to do enterFrame listeners. One is function based, the other is object based.  When you do:

helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", moveHelicopters)

You’re doing object-based and I believe you should probably do:

helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", helicopter)

But in doing so, the function “moveHelicopters” would use “self” to reference the object:

-- helicopter Working function moveHelicopters(self,event) if self.x \<= 350 then self.x = 550 --\<----- you might want to make sure this is right since you're testing against 350 above self.speed = math.random(6, 18) self.amp = math.random(60,80) self.angle = math.random(20,80) else self.x = self.x - self.speed self.angle = self.angle + .05 self.y = self.amp\*math.sin(self.angle)+self.initY end end

Or if you want to do the function based version, you can leave everything named helicopter and do:

Runtime:addEventListener(“enterFrame”, moveHelicopter") and the function continue’s to reference helicopter.

Rob

I just fixed error.

p.s: I gave up modifying the code in the middle. bcuz I can not make your game. @_@

p.s 2: Corona is the right engine for beginners. However, you should have basic knowledge.

Go to the bookstore and look at any book related to Lua.

Choose the thinnest book for beginners.

After reading the book and learning Lua language,

Corona API documentation will help you.

[lua]

local composer = require( “composer” )

local scene = composer.newScene()

local physics = require( “physics” )

physics.start()

–physics.setDrawMode( “hybrid” )

physics.setGravity( 0,-.07 )

local lives = 1

local score = 0

local died = false

local ship

local gameLoopTimer

local scoreText

– set up display groups

local backGroup

local mainGroup

local uiGroup

function activateShips(self, event)

    self:applyForce( 0, -02.1, ship.x, ship.y)

end

function touchScreen(event)

    if event.phase == “began” then

        ship.enterFrame = activateShips

        Runtime:addEventListener(“enterFrame”, ship)

    elseif event.phase == “ended” then

        Runtime:removeEventListener(“enterFrame”, ship )

    end

end

function explode()

    explosion.x = ship.x

    explosion.y = ship.y

    explosion.isVisible = true

    explosion:play()

    ship.isVisible = false

end

local function endGame()

    composer.setVariable( “finalScore”, score )

    composer.gotoScene( “highscore”, { time=800, effect=“crossFade” } )

    – composer.removeScene( “game” )

end

local function onCollision(event)

    if event.phase == “began” then

        if ship.collided == false then

            ship.collided = true

            timer.performWithDelay( 2000, endGame )

            ship.bodyType = “static”

            explode()

        else

        end

    end

end

local function moveDrone( self, event )

    if self.x == nil then return end

    if self.x <- 180 then

        self.x = 571

        self.speed = math.random(6, 18)

        self.amp = math.random(60,120)

        self.angle = math.random(20,80)

    else

        self.x = self.x - self.speed

        self.angle = self.angle + .03

        self.y = self.amp*math.sin(self.angle)+self.initY

        score = score + 1

        scoreText.text = "Score: " … score

    end

end

local function moveHelicopter( self, event )

    – if self.x == nil then return end

    self.x = 350

    if self.x <- 350 then

        self.x = 550

        self.speed = math.random(6, 18)

        self.amp = math.random(60,80)

        self.angle = math.random(20,80)

    else

        self.x = self.x - self.speed

        self.angle = self.angle + .05

        self.y = self.amp*math.sin(self.angle)+self.initY

    end

end

local function scrollCity( self, event )

end

function scene:create( event )

    local sceneGroup = self.view

    physics.pause()

    – Set up display groups

    backGroup = display.newGroup()  – Display group for the background image

    sceneGroup:insert( backGroup )  – Insert into the scene’s view group

    mainGroup = display.newGroup()  – Display group for the ship, asteroids, lasers, etc.

    sceneGroup:insert( mainGroup )  – Insert into the scene’s view group

    uiGroup = display.newGroup()    – Display group for UI objects like the score

    sceneGroup:insert( uiGroup )

    local background = newImageRect( backGroup, “background.png”, centerX, centerY, 740, 415 )

   

    local info = require(“explosion”)

    local sheet = graphics.newImageSheet( “explosion.png”, info:getSheet() )

    local seq =

    {

        { name=“explosion”, start=1, count=10, time=2250, loopCount=1, direction =“forward” },

    }

    explosion = newSprite( mainGroup, “explosion”, 0, 0, sheet, seq )

    explosion:play()

    explosion.isVisible = false

    local info = require(“drone”)

    local sheet = graphics.newImageSheet( “drone.png”, info:getSheet() )

    local seq = 

    {

        { name = “droe”, frames = {1,2,3}, time=150, loopCount=0, loopDirection = “forward” },

    }

    drone = newSprite( mainGroup, “idle”, scrW-570, scrH-200, sheet, seq )

    drone:play()

    drone.speed = math.random(6, 12)

    drone.amp = math.random(20,100)

    drone.angle = math.random(20,80)

    physics.addBody( drone,“static”, {density=.1, bounce=0.1, })

    drone2 = newSprite( mainGroup, “idle”, scrW-370, scrH-200, sheet, seq )

    drone2:play()

    drone2.speed = math.random(6, 12)

    drone2.amp = math.random(20,100)

    drone2.angle = math.random(20,80)

    physics.addBody( drone2,“static”, {density=.1, bounce=0.1, })

    local info = require(“helicopter”)

    local sheet = graphics.newImageSheet( “helicopter.png”, info:getSheet() )

    local seq =

    {

       { name = “heli”, frames = {1,2,3}, time=150, loopCount=0, loopDirection = “forward” },

    }

    helicopter = newSprite( mainGroup, “idle”, 350, scrH-200, sheet, seq )

    helicopter:play()

    helicopter.speed = math.random(8, 18)

    helicopter.amp = math.random(20,100)

    helicopter.angle = math.random(40,80)

    physics.addBody( helicopter,“static”,{density=.1, bounce=0.1, friction=.2, radius=30 } )

    

    local city1 = newImageRect(backGroup, “city1.png”, 0, scrH-280, 720, 580 )

    local city2 = newImageRect(backGroup, “city1.png”, 780, scrH-280, 720, 580 )

    

    local top = newImageRect( mainGroup, “top.png”, 60, -10, 130, 15 )

    physics.addBody( top,“static”, {} )

    local bottom = newImageRect( mainGroup, “top.png”, 60, 435, 130, 15 )

    physics.addBody( bottom,“static”, {} )

    

    local gravityButtom = newImageRect(mainGroup, “GravityButton.png”, 400, 350, 140, 140 )

    gravityButtom:addEventListener( “touch”, touchScreen )

    – city1.enterFrame = scrollCity

    – Runtime:addEventListener(“enterFrame”, city1)

    – city2.enterFrame = scrollCity

    – Runtime:addEventListener(“enterFrame”, city2)

    ship = newImageRect( mainGroup, “alienship.png”, -400, 195, 60, 45 )

    ship.myName = “ship”

    ship.collided = false

    physics.addBody( ship, “static”, {  radius=20, bounce= 0})

    function alienReady()

        ship.bodyType = (“dynamic”)

        ship.gravityScale = -1085

    end

    transition.to(ship, {time=1000, x=10, onComplete=alienReady})

    scoreText = newText( uiGroup, "Score: " … score, 400, 80, 0, 0, native.systemFont, 36 )

    drone.enterFrame = moveDrone

    drone2.enterFrame = moveDrone

    helicopter.enterFrame = moveHelicopter

    

    Runtime:addEventListener( “enterFrame”, drone )

    Runtime:addEventListener( “enterFrame”, drone2 )

    Runtime:addEventListener( “enterFrame”, helicopter )

end

function scene:show( event )

    local phase = event.phase

    if ( phase == “will” ) then

      

    elseif ( phase == “did” ) then

        physics.start()

        Runtime:addEventListener(“collision”, onCollision)

    end

end

function scene:hide( event )

    local phase = event.phase

    if ( phase == “will” ) then

      

    elseif ( phase == “did” ) then

        physics.pause()

        composer.removeScene( “game” )

    end

end

function scene:destroy( event )

end

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )

return scene

[/lua]