You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
991 B

  1. -- 截屏
  2. -- callback = function(fullPath, fileName)
  3. function ScreenShot(callback)
  4. local dateNow = os.date("*t", os.time())
  5. local timeString = string.format("%04d-%02d-%02d-%02d%-02d-%02d-%03d", dateNow.year, dateNow.month, dateNow.day, dateNow.hour, dateNow.min, dateNow.sec, math.random(100, 999));
  6. local fileName = "screenshot_"..tostring(timeString)..".jpg"
  7. local filePath = cc.FileUtils:getInstance():getWritablePath()..fileName
  8. cc.FileUtils:getInstance():screenToFile(filePath, function(ret)
  9. if 1 == tonumber(ret) then
  10. if callback then
  11. callback(filePath, fileName)
  12. end
  13. else
  14. if callback then
  15. callback()
  16. end
  17. end
  18. end );
  19. end
  20. -- 截屏并展示给玩家看
  21. function showScreenShot()
  22. ScreenShot(function(fullPath, fileName)
  23. if fullPath and fileName then
  24. local view = import("luaScript.Views.Room.ScreenView"):new(fileName)
  25. view:setAnchorPoint(cc.p(0.5, 0.5))
  26. app:showWaitDialog(view)
  27. else
  28. showTooltip("截图失败");
  29. end
  30. end)
  31. end