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
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
Ok well I changed the - yOffset to + yOffset and that changes the direction but kills the infinite scrolling somehow. [import]uid: 21827 topic_id: 5215 reply_id: 17395[/import]
Thanks Carlos. As you can see, it scrolls infinitely from bottom to top but I’d like to have it scroll from top to bottom. I can make it work but then it breaks the infinite scrolling. [import]uid: 21827 topic_id: 5215 reply_id: 17487[/import]
I’m stuck in the same boat. Anyone with an answer for this? VidKid72 is absolutely correct, when you change the value to a - it scrolls correctly, but it’s no longer infinite. I tried it myself with single background, two backgrounds, etc… [import]uid: 10379 topic_id: 5215 reply_id: 23466[/import]
hi this one nice, but how can i change the horizontal directions? can u give one example on this? [import]uid: 40515 topic_id: 5215 reply_id: 28067[/import]
Thanks Sidasa but it still doesn’t work with what you suggested. 2 screens slide by and the scrolling stops. Believe me, I’ve tried many conditions but can’t get it to scroll down.
Carlos never got back to this thread either. I’m almost going to say there’s a bug somewhere within Corona to prevent this code from functioning. Almost.
I’ve certainly given up on Corona and returned to XCode. [import]uid: 21827 topic_id: 5215 reply_id: 28159[/import]
– Hide the iPhone status bar
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
Thanks Sidasa, that certainly works with the additional code and not just the conditions like you first posted.
I really appreciate you taking the time to look at this. Now that it works I might try Corona again. [import]uid: 21827 topic_id: 5215 reply_id: 28169[/import]