MainScene
local MainScene = class("MainScene", function()
return display.newScene("MainScene")
end)
local winSize = {width=display.width,height=display.height}
local fileName = "CaptureScreenTest.png"
function MainScene:ctor()
self:addsp()
local function afterCaptured(succeed, fileName)
if succeed then
--switch
local PassScene=require("app.scenes.PassScene")
local passScene=PassScene.new(fileName)
cc.Director:getInstance():replaceScene(passScene)
else
cclog("Capture screen failed.")
end
end
cc.ui.UIPushButton.new("test/BlueButton.png", {scale9 = true})
:setButtonSize(200, 60)
:setButtonLabel(cc.ui.UILabel.new({text = "share", size = 20}))
:onButtonClicked(function(event)
--caputre
cc.utils:captureScreen(afterCaptured, fileName)
end)
:align(display.CENTER, display.cx , display.cy )
:addTo(self)
end
function MainScene:addsp()
--sp
--var
local left = cc.p(winSize.width / 4, winSize.height / 2)
local right = cc.p(winSize.width / 4 * 3, winSize.height / 2)
--sp
local sp1 = cc.Sprite:create("test/BlueButton.png")
sp1:setPosition(left)
--action
local move1 = cc.MoveBy:create(1, cc.p(winSize.width/2, 0))
local seq1 = cc.RepeatForever:create(cc.Sequence:create(move1, move1:reverse()))
self:addChild(sp1)
sp1:runAction(seq1)
end
return MainScene
PassScene
local PassScene = class("PassScene", function()
return display.newScene("PassScene")
end)
function PassScene:ctor(outputFile)
local sp = cc.Sprite:create(outputFile)
sp:setPosition(display.cx,display.cy)
self:addChild(sp)
cc.ui.UILabel.new({
UILabelType = 2, text = "PassScene", size = 64})
:align(display.CENTER, display.cx, display.top-100)
:addTo(self)
end
return PassScene