top down scrolling background

HI,

I have a background image that is 1120H, I can scroll it continuous from bottom to top. I just want to reverse it so it becomes scrolling top to bottom. Simple, I have messed with all the co-ords but I just cant grasp it.

I have it working fine top /bottom. Would somebody have a look at my code please and help me out.

function createWorld( layer ) -- scrollSpeedY = 0.3 local layer = layer or display.currentStage -- Default to top display group local scrollSpeed = 1.50 background1 = display.newImageRect(layer,"images/backgrounds/back1.jpg", 350, 1120) background1.x = display.contentWidth/2; background1.y = display.contentHeight/2; background2 = display.newImageRect(layer,"images/backgrounds/back1.jpg", 350, 1120) background2.x = display.contentWidth/2; background2.y = background1.y +1120 background3 = display.newImageRect(layer,"images/backgrounds/back1.jpg", 350, 1120) background3.x = display.contentWidth/2; background3.y = background2.y +1120 function moveBackground(event) background1.y = background1.y - scrollSpeed background2.y = background2.y - scrollSpeed background3.y = background3.y - scrollSpeed if (background1.y + background1.contentWidth) \< -560 then background1:translate( 0, 1120\*3 ) end if (background2.y + background2.contentWidth) \< -560 then background2:translate( 0, 1120\*3 ) end if (background3.y + background3.contentWidth) \< -560 then background3:translate( 0, 1120\*3 ) end end Runtime:addEventListener( "enterFrame", moveBackground ) end

Hi!

I’d recommend you to use transition library

Check the code:
 

[lua]local function moveUpAndDown(obj, params)
    
    local function toggleTransition(obj)
        if (not obj.currentDirection or obj.currentDirection == ‘up’) then            
            obj.currentDirection = ‘down’
            obj:moveDown()
        else            
            obj.currentDirection = ‘up’
            obj:moveUp()
        end
    end

    function obj:moveUp()
        transition.to(self, { y = (-1)*params.screenHeight, time = params.timeInMsec, delta = true, onComplete = toggleTransition })            
    end

    function obj:moveDown()
        transition.to(self, { y = params.screenHeight, time = params.timeInMsec, delta = true, onComplete = toggleTransition })
    end

    toggleTransition(obj);
end

background1 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background1.x = display.contentWidth/2;
background1.y = display.contentHeight/2;

moveUpAndDown(background1, {screenHeigh=display.contentHeight, timeInMsec=5000} )

background2 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background2.x = display.contentWidth/2;
background2.y = background1.y +1120

moveUpAndDown(background2, {screenHeigh=display.contentHeight, timeInMsec=5000} )

background3 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background3.x = display.contentWidth/2;
background3.y = background2.y +1120

moveUpAndDown(background3, {screenHeigh=display.contentHeight, timeInMsec=5000} )

[/lua]

I havent tested it but I hope you can get the idea.

Hope this helps!

Best regards,

Anton

Hi!

I’d recommend you to use transition library

Check the code:
 

[lua]local function moveUpAndDown(obj, params)
    
    local function toggleTransition(obj)
        if (not obj.currentDirection or obj.currentDirection == ‘up’) then            
            obj.currentDirection = ‘down’
            obj:moveDown()
        else            
            obj.currentDirection = ‘up’
            obj:moveUp()
        end
    end

    function obj:moveUp()
        transition.to(self, { y = (-1)*params.screenHeight, time = params.timeInMsec, delta = true, onComplete = toggleTransition })            
    end

    function obj:moveDown()
        transition.to(self, { y = params.screenHeight, time = params.timeInMsec, delta = true, onComplete = toggleTransition })
    end

    toggleTransition(obj);
end

background1 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background1.x = display.contentWidth/2;
background1.y = display.contentHeight/2;

moveUpAndDown(background1, {screenHeigh=display.contentHeight, timeInMsec=5000} )

background2 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background2.x = display.contentWidth/2;
background2.y = background1.y +1120

moveUpAndDown(background2, {screenHeigh=display.contentHeight, timeInMsec=5000} )

background3 = display.newImageRect(layer,“images/backgrounds/back1.jpg”, 350, 1120)
background3.x = display.contentWidth/2;
background3.y = background2.y +1120

moveUpAndDown(background3, {screenHeigh=display.contentHeight, timeInMsec=5000} )

[/lua]

I havent tested it but I hope you can get the idea.

Hope this helps!

Best regards,

Anton