[Resolved] Continuous Vertically Flowing Background

Hey All,

I have been trying to make a Continuous Flowing Background flowing from the Top of the screen to the Bottom. It only seems to translate once then never see backgrounds again. Can anybody point me in the right direction here… has me baffled… Thank you all in advance… Code I have for this is below

Thanks Again

Andrew
[lua]
–Background
backg = display.newImage( “assets/graphics/backg.png” )
backg:setReferencePoint( display.CenterLeftReferencePoint )
backg.x = 0
backg.y = 0

backg2 = display.newImage( “assets/graphics/backg.png” )
backg2:setReferencePoint( display.CenterLeftReferencePoint )
backg2.x = 0
backg2.y = 320

–Initiate Moving Sequence (per-frame event to move the elements)
local tPrevious = system.getTimer()
local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time

–Speed
local yOffset = ( 0.10 * tDelta )

–Background Movement
if not backg.y then return end
backg.y = backg.y + yOffset
if not backg2.y then return end
backg2.y = backg2.y + yOffset

if (backg.y + backg.contentHeight) < 0 then
backg:translate( 0, -320 * 2)
end
if (backg2.y + backg2.contentHeight) < 0 then
backg:translate( 0, -320 * 2)
end
end

Runtime:addEventListener( “enterFrame”, move ); [import]uid: 165071 topic_id: 32960 reply_id: 332960[/import]

@skeezas,

Are you thinking somethink like this (but vertical of course):
http://www.youtube.com/watch?v=J2-hsogiN4U

If so, you can look at the code here: https://github.com/roaminggamer/SSKCorona/blob/master/sampler/ssk_sampler/mechanics/camera/scrolling1_logic.lua

Admittedly, this code may a bit confusing. So if you have questions or would like something simpler please write back here (in the forums), or write me here (put SSKCorona in the title of your email):

-Ed

[import]uid: 110228 topic_id: 32960 reply_id: 131276[/import]

In line 28 and 31, I think you want it to be a minus rather than a plus. With plus the number will always be greater than 0, thus it never excutes the translate code. [import]uid: 56820 topic_id: 32960 reply_id: 131288[/import]

@skeezas,

Are you thinking somethink like this (but vertical of course):
http://www.youtube.com/watch?v=J2-hsogiN4U

If so, you can look at the code here: https://github.com/roaminggamer/SSKCorona/blob/master/sampler/ssk_sampler/mechanics/camera/scrolling1_logic.lua

Admittedly, this code may a bit confusing. So if you have questions or would like something simpler please write back here (in the forums), or write me here (put SSKCorona in the title of your email):

-Ed

[import]uid: 110228 topic_id: 32960 reply_id: 131276[/import]

In line 28 and 31, I think you want it to be a minus rather than a plus. With plus the number will always be greater than 0, thus it never excutes the translate code. [import]uid: 56820 topic_id: 32960 reply_id: 131288[/import]

Hey There,

Thank you for your responses. Both very good answers. I looked into both :slight_smile: I ended up playing with the + and - signs and with a bit of tweeking GOT IT!! :slight_smile: The Amended code is below

This is simple and good for anyone to use in their game, you just have to adjust some values depending on the size of your background image :wink:

Thanks

Andrew

[lua]–Background
backg = display.newImage( “bg.png” )
backg:setReferencePoint( display.CenterLeftReferencePoint )
backg.x = 0
backg.y = -160

backg2 = display.newImage( “bg.png” )
backg2:setReferencePoint( display.CenterLeftReferencePoint )
backg2.x = 0
backg2.y = -3160

–Initiate Moving Sequence (per-frame event to move the elements)
local tPrevious = system.getTimer()

local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time

–Speed
local yOffset = ( 0.10 * tDelta )

–Background Movement
if not backg.y then return end
backg.y = backg.y + yOffset

if not backg2.y then return end
backg2.y = backg2.y + yOffset

if (backg.y + backg.contentHeight) > 5860 then
backg:translate( 0, -3000 * 2)
end

if (backg2.y + backg2.contentHeight) > 5860 then
backg2:translate( 0,-3000 * 2)
end

end

Runtime:addEventListener( “enterFrame”, move ); [import]uid: 165071 topic_id: 32960 reply_id: 131344[/import]

Hey There,

Thank you for your responses. Both very good answers. I looked into both :slight_smile: I ended up playing with the + and - signs and with a bit of tweeking GOT IT!! :slight_smile: The Amended code is below

This is simple and good for anyone to use in their game, you just have to adjust some values depending on the size of your background image :wink:

Thanks

Andrew

[lua]–Background
backg = display.newImage( “bg.png” )
backg:setReferencePoint( display.CenterLeftReferencePoint )
backg.x = 0
backg.y = -160

backg2 = display.newImage( “bg.png” )
backg2:setReferencePoint( display.CenterLeftReferencePoint )
backg2.x = 0
backg2.y = -3160

–Initiate Moving Sequence (per-frame event to move the elements)
local tPrevious = system.getTimer()

local function move(event)
local tDelta = event.time - tPrevious
tPrevious = event.time

–Speed
local yOffset = ( 0.10 * tDelta )

–Background Movement
if not backg.y then return end
backg.y = backg.y + yOffset

if not backg2.y then return end
backg2.y = backg2.y + yOffset

if (backg.y + backg.contentHeight) > 5860 then
backg:translate( 0, -3000 * 2)
end

if (backg2.y + backg2.contentHeight) > 5860 then
backg2:translate( 0,-3000 * 2)
end

end

Runtime:addEventListener( “enterFrame”, move ); [import]uid: 165071 topic_id: 32960 reply_id: 131344[/import]