Hi everyone, I figured I’d give Corona a shot today to see if it made life any easier. I’m slowly making decent progress and had an issue. I’m trying to make a scrolling background sprite and it works but not in the direction I want. Would any of you kind folk know what I’m doing wrong in order to get the direction to change?
Please be kind looking at my code as it’s my first attempt using Lua. I may even change the sprite size and tile it more if there’s a performance issue on the device but for now this works other than the direction I would like.
Thanks!
Here’s the code:
[code]
require “sprite”
display.setStatusBar( display.HiddenStatusBar )
– Background
– When one of the background images slides offscreen, we move it to the bottom of the next one.
local background = display.newImage( “Background.png” )
background:setReferencePoint( display.CenterLeftReferencePoint )
background.x = 0
background.y = 240
local background2 = display.newImage( “Background.png” )
background2:setReferencePoint( display.CenterLeftReferencePoint )
background2.x = 0
background2.y = -240
– A per-frame event to move the elements
local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time
local yOffset = ( 0.1 * tDelta )
background.y = background.y - yOffset
background2.y = background2.y - yOffset
if (background.y + background.stageHeight) < 240 then
background:translate( 0, 480 * 2)
end
if (background2.y + background2.stageHeight) < 240 then
background2:translate( 0, 480 * 2)
end
end
– Start everything moving
Runtime:addEventListener( “enterFrame”, move );[/code] [import]uid: 21827 topic_id: 5215 reply_id: 305215[/import]
