Advertisement
Rakoonic

parallax bg

Sep 8th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. local function setUpBG()
  2.  
  3.     local bgGroup = display.newGroup()
  4.     scene.view:insert( bgGroup )
  5.     bgGroup:toBack()
  6.    
  7.     local bgImages = {
  8.         { file = "filename1.png", width = width, height = height, x = x, y = y, speed = scalar },
  9.         { file = "filename2.png", width = width, height = height, x = x, y = y, speed = scalar },
  10.         { file = "filename3.png", width = width, height = height, x = x, y = y, speed = scalar },
  11.         { file = "filename4.png", width = width, height = height, x = x, y = y, speed = scalar },
  12.         { file = "filename5.png", width = width, height = height, x = x, y = y, speed = scalar },
  13.         { file = "filename6.png", width = width, height = height, x = x, y = y, speed = scalar },
  14.         { file = "filename7.png", width = width, height = height, x = x, y = y, speed = scalar },
  15.     }
  16.    
  17.     for i = 1, #bgImages do
  18.         local bgImage = bgImages[ i ]
  19.         local image   = display.newImageRect( bgGroup, bgImage.file, bgImage.width, bgImage.height )
  20.         image.data    = bgImage
  21.     end
  22.  
  23. end
  24.  
  25. local function drawBG( x, y, bgGroup )
  26.  
  27.     for i = 1, bgGroup.numChildren do
  28.         local child = bgGroup[ i ]
  29.         local data  = child.data
  30.         child.x     = data.x - x * data.speed
  31.         child.y     = data.y - y * data.speed
  32.     end
  33.    
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement