I thought I had found a good tutorial on how to make a horizontal scrolling game at
https://www.youtube.com/watch?v=0GtUxdSeWzk
but I’m having a lot of problems caused by the fact that it was made with a previous version of Corona. In particular, I can not understand how to operate in new Corona version these few lines of code that moves a background.
[lua]
display.setDefault( “anchorX”, 0)
display.setDefault( “anchorY”, 0 )
local city1 = display.newImage( “city1.png” )
– city1:setReferencePoint( display.BottomLeftReferencePoint ) - only for graphics 1.0
city1.x = 0
city1.y = 0
function scrollCity(self,event)
self.x = self.target.x - 3
end
city1.enterFrame = scrollCity
Runtime:addEventListener( “enterFrame”,city1) [/lua]
After some attempts I managed to make it work in this way:
[lua]
display.setDefault( “anchorX”, 0)
display.setDefault( “anchorY”, 0 )
local city1 = display.newImage( “city1.png” )
city1.x = 0
city1.y = 0
local function scrollCity()
city1.x = city1.x - 1
end
Runtime:addEventListener( “enterFrame”,scrollCity)
[/lua]
but I’d like to pass a function with parameters rather than a defined object, except that I always get an error “listener cannot be nil”, something like:
[lua]
function onEachFrame(object)
object.x = object.x + 1
end
Runtime:addEventListener( “enterFrame”,onEachFrame(city1))
[/lua]