Scroll Moving Clouds

This sample shows you that with just two images, you could have a nice and smooth scrolling moving clouds.
(notice how I call 'bGroup'; this is if you want to use director, otherwise, just take it off)
 

Simply add this to your main.lua file and you're set:

          local clouds1 = display.newImageRect( "images/clouds.png", 395, 121)

      clouds1:setReferencePoint( display.CenterLeftReferencePoint )

      clouds1.x = 0

      clouds1.y = 86

      bGroup:insert(clouds1)

    

      local clouds2 = display.newImageRect( "images/clouds2.png", 395, 121)

      clouds2:setReferencePoint( display.CenterLeftReferencePoint )

      clouds2.x = 480

      clouds2.y = 66

      bGroup:insert(clouds2)

    

    -- MOVE CLOUDS SLOWLY

          local cloudMoveSpeed = 0.5 -- control speed (less than 1 makes it move slower)


          local function fnClouds(event)

                  clouds1.x = clouds1.x - cloudMoveSpeed

                  clouds2.x = clouds2.x - cloudMoveSpeed

    

                  if (clouds1.x + clouds1.contentWidth) < 0 then
                     clouds1:translate( 480 * 2, 0)
                  end
    

                  if (clouds2.x + clouds2.contentWidth) < 0 then
                     clouds2:translate( 480 * 2, 0)
                 end

          end

          -- END CLOUD MOVEMENT

          Runtime:addEventListener( "enterFrame", fnClouds )

 

And that's it!