Advertisement
alestane

Loop listener

Jul 18th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mydata = require("mydata")
  2.  
  3. mydata.humanoids = {}
  4. local scrollSpeedX = 0
  5.  
  6.  
  7. function createHumanoid(layer)
  8.  
  9.     local layer = layer or display.currentStage
  10.  
  11.     for i = 1, 10 do
  12.  
  13.         local humanoid = display.newRect(0, 0, 10, 10)
  14.         humanoid.x = math.random(-1000, 1000)
  15.         humanoid.y = 260
  16.         physics.addBody(humanoid, { isSensor = true })
  17.         mydata.humanoids[#mydata.humanoids + 1] = humanoid
  18.     end
  19.  
  20.     function updateHumanoid()
  21.  
  22.         if switchTerrain == 0 then
  23.  
  24.             if player.x <= 100 then scrollSpeedX = 0
  25.             else scrollSpeedX = -player.x / 70
  26.             end
  27.  
  28.         elseif switchTerrain == 1 then
  29.  
  30.             if player.x <= 100 then scrollSpeedX = 0
  31.  
  32.             else scrollSpeedX = player.x / 70
  33.             end
  34.     end
  35.     for _, humanoid in ipairs(mydata.humanoids) do
  36.             if humanoid.x then
  37.                 humanoid.x = humanoid.x + scrollSpeedX
  38.             end
  39.     end
  40.     end
  41.  
  42.     Runtime:addEventListener("enterFrame", updateHumanoid)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement