Hendrix000007

autoImageFolder

Apr 22nd, 2015
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. --introClass.lua--------------
  2.  
  3. local lfs = require "lfs"
  4. local _M                = {}                       
  5.  
  6. local centerX           = display.contentCenterX
  7. local centerY           = display.contentCenterY
  8.  
  9. --Forward declaration of variables
  10. local splashFunction    = {}
  11. local splashCounter     = 1                        
  12. local pathForImages     = "ImageShow/"             
  13. local filenames         = {}
  14. local splashImage
  15. local baseDir
  16. local baseDirDevice
  17.  
  18. local environment = system.getInfo( "environment" )
  19.  
  20. _M.group                = display.newGroup()
  21. _G.doneSplash           = false                    
  22.  
  23. --FUNCTIONS--
  24. -- path is relative to the baseDirectory
  25. function _M.getFiles()  
  26. if environment == "simulator" then  
  27.     baseDir = system.pathForFile('main.lua'):gsub("main.lua", "")
  28.     for file in lfs.dir(baseDir .. pathForImages) do
  29.         if (file ~= '.' and file ~= '..' and file ~= ".DS_Store" ) then
  30.             table.insert(filenames, file)
  31.         end
  32.     end
  33. else
  34.     baseDir = system.ResourceDirectory
  35.     for file in lfs.dir(baseDir .. "/" .. pathForImages) do
  36.         if (file ~= '.' and file ~= '..' and file ~= ".DS_Store" ) then
  37.             table.insert(filenames, file)
  38.         end
  39.     end
  40.     if (#filenames == 0) then return false end
  41. end
  42.     return filenames
  43. end
  44.  
  45. function _M.printSplashImageFolderContent()        
  46.     for k,v in ipairs(filenames) do
  47.         print(k,v)
  48.     end
  49. end
  50.  
  51. function _M.playGame()                             
  52.     print("End of introFunction")                  
  53.     system.vibrate( )
  54.     system.openURL( "http://www.3claws.org" )
  55. end
  56.  
  57. function _M.splashFunction(self, event)
  58.     if event.phase == "began" then
  59.         if _G.doneSplash == false then
  60.             if splashCounter < #filenames then
  61.                
  62.                 splashImage = display.newImageRect( pathForImages .. filenames[splashCounter], 480, 320 )
  63.                 splashImage.x, splashImage.y = display.contentCenterX, display.contentCenterY
  64.                 splashImage.alpha = 1
  65.                 _M.group:insert(splashImage)
  66.                
  67.                 transition.to( splashImage, {time=500, alpha=0, onComplete= function()
  68.                 display.remove( splashImage )  
  69.                 splashImage = display.newImageRect( pathForImages .. filenames[splashCounter], 480, 320 )
  70.                 splashImage.x, splashImage.y = display.contentCenterX, display.contentCenterY
  71.                 splashImage.alpha = 0
  72.                 _M.group:insert(splashImage)                       
  73.                 transition.to( splashImage, {time=500, alpha=1})       
  74.                 return true end} )
  75.  
  76.             elseif splashCounter == #filenames then
  77.                 _G.doneSplash = true               
  78.                 _M.playGame()                      
  79.             end        
  80.             splashCounter = splashCounter + 1
  81.             return true
  82.         end
  83.     end
  84. end
  85.  
  86. function _M.removeMusic()
  87.     audio.stop()
  88.     audio.dispose(introTrackSnd)
  89.     introTrackSnd = nil
  90.     introChan = nil
  91.     return true
  92. end
  93.  
  94. function _M:new()          
  95.     splashImage = display.newImageRect( pathForImages .. filenames[splashCounter], 480, 320 )
  96.     splashImage.x, splashImage.y = display.contentCenterX, display.contentCenterY
  97.     splashImage.alpha = 1
  98.     _M.group:insert(splashImage)
  99.     splashImage.touch = _M.splashFunction
  100.     splashImage:addEventListener("touch", splashImage)
  101.     return splashImage
  102. end
  103.  
  104. _M.getFiles()
  105. _M:new()
  106. _M.printSplashImageFolderContent() 
  107. print( baseDir)
  108. return _M
  109.  
  110. --in main----------------
  111. display.setStatusBar( display.HiddenStatusBar )
  112. require( "introClass" )
Advertisement
Add Comment
Please, Sign In to add comment