Hi I’m very new to corona SDK however i am familiar with programming but I’ve encountered a error that i have no idea how to solve.
I’m trying to make my town image move across the screen through the function moveTown but when i call the method “Runtime:addEventListener(“enterFrame”,moveTown)” the code doesn’t run. Without this line the code works
Please someone help me and explain to me what i’m doing wrong.
…BTW sorry if i posted this in the wrong place
–
– level1.lua
–
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “physics” library
local physics = require “physics”
physics.start(); physics.pause()
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
ship = display.newImage( “spaceship.png”)
ship.x = 60
ship.y = 140
physics.addBody( ship, “dynamic”, {density = .1,bounce = 0.1, friction=2, radius= 2 } )
town = display.newImage( “planet.png”)
town.x = 500
town.y = 140
town.speed = math.random(2,6)
physics.addBody( town, “static”, {density = .1,bounce = 0.1, friction=2, radius= 2 } )
town.enterFrame = moveTown
ground = display.newImage( “grass.png”)
ground:setReferencePoint( display.BottomLeftReferencePoint )
ground.x = 400
ground.y = 370
physics.addBody( ground, “static”, { friction=0.3 } )
bg = display.newImage( “background.png”)
floating = display.newImage( “ground1.png”)
floating.x = 0
floating.y = 300
physics.addBody( floating, “static”, {friction=0.5} )
– all display objects must be inserted into group
group:insert( bg )
group:insert( ground)
group:insert( ship )
group:insert( floating )
group:insert( town )
end
--Runtime:addEventListener(“enterFrame”, town )
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
physics.start()
end
function moveTown(self,event)
if self.x < -50 then
self.x = 500
else
self.x = self.x - self.speed
end
end
function flightRight(self,event)
self:applyForce(0,-0.05,self.x,self.y)
end
function touchScreen(event)
if event.phase == “began” then
ship.enterFrame = flightRight
Runtime:addEventListener(“enterFrame”, ship)
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, ship)
print(“ended”)
end
end
Runtime:addEventListener(“touch”, touchScreen)
Runtime:addEventListener(“enterFrame”,moveTown)
function scene:exitScene( event )
local group = self.view
physics.stop()
end
function scene:destroyScene( event )
local group = self.view
package.loaded[physics] = nil
physics = nil
end
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )
return scene