标签:style blog http color java os strong io
--[[ 截屏测试 CaptureScreenTest ]]-- -- 获取屏幕大小 local winSize = cc.Director:getInstance():getWinSize() local kTagSprite = 1 local childTag = 119 -- 创建层 local function createLayer() -- 创建层 local layer = cc.Layer:create() local filename = ""-- 文件名 -- 标题 local title = cc.Label:createWithTTF("New Renderer", "fonts/arial.ttf", 36) title:setColor(cc.c3b(255,255,0)) -- 设置颜色为黄色 layer:addChild(title, 1, 10000) -- 第一个参数为node,第二个参数为zorder,第三个参数是tag title:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 30))-- 设置位置top,center -- 子标题 local subTitle = cc.Label:createWithTTF("Capture screen test, press the menu items to capture the screen", "fonts/arial.ttf", 12) subTitle:setColor(cc.c3b(255,255,0)) -- 设置为黄色 layer:addChild(subTitle, 1, 10001) -- 设置tag为10001 subTitle:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 60) )-- 设置位置 -- 左边位置 local left = cc.p(winSize.width / 4, winSize.height / 2) -- 右边位置 local right = cc.p(winSize.width / 4 * 3, winSize.height / 2) -- 精灵1 local sp1 = cc.Sprite:create("Images/grossini.png") sp1:setPosition(left)-- 设置初始位置在左边 local move1 = cc.MoveBy:create(1, cc.p(winSize.width/2, 0))--移动动作,持续1秒 -- 动作序列1 local seq1 = cc.RepeatForever:create(cc.Sequence:create(move1, move1:reverse())) layer:addChild(sp1)--添加精灵1 sp1:runAction(seq1)-- 执行动作序列 -- 精灵2 local sp2 = cc.Sprite:create("Images/grossinis_sister1.png") sp2:setPosition(right)-- 设置初始位置在右边 local move2 = cc.MoveBy:create(1, cc.p(-winSize.width/2, 0))-- 移动动作,持续1秒 -- 动作序列2 local seq2 = cc.RepeatForever:create(cc.Sequence:create(move2, move2:reverse())) layer:addChild(sp2)-- 添加精灵2 sp2:runAction(seq2) -- 执行动作序列2 --截屏回调方法 local function afterCaptured(succeed, outputFile) if succeed then local sp = cc.Sprite:create(outputFile) layer:addChild(sp, 0, childTag) sp:setPosition(winSize.width / 2, winSize.height / 2) sp:setScale(0.25) -- 显示缩放 fileName = outputFile else cclog("Capture screen failed.") end end -- 点击标签回调的方法 local function onCaptured(tag, sender) -- 移除纹理缓存 cc.Director:getInstance():getTextureCache():removeTextureForKey(fileName) layer:removeChildByTag(childTag) fileName = "CaptureScreenTest.png" -- 截屏 cc.utils:captureScreen(afterCaptured, fileName) end local ttfConfig = {} -- 字体配置表 ttfConfig.fontFilePath = "fonts/arial.ttf" -- 字体路径 ttfConfig.fontSize = 24 -- 字体大小 -- 创建一个标签,名为capture all local label1 = cc.Label:createWithTTF(ttfConfig, "capture all", cc.TEXT_ALIGNMENT_CENTER, winSize.width) -- 创建菜单项标签 local mi1 = cc.MenuItemLabel:create(label1) -- 注册点击回调方法 mi1:registerScriptTapHandler(onCaptured) -- 创建菜单 local menu = cc.Menu:create(mi1) -- 添加菜单到层中 layer:addChild(menu) -- 设置在宽的一半,高的1/4的位置上 menu:setPosition(winSize.width / 2, winSize.height / 4) return layer end -------------------------------- -- CaptureScreen -------------------------------- function CaptureScreenTestMain() -- 创建一个场景 local scene = cc.Scene:create() -- 添加场景到层中 scene:addChild(createLayer()) -- 添加Back菜单项 scene:addChild(CreateBackMenuItem()) return scene end
Cocos2d-x 3.2 Lua示例 CaptureScreen(截屏),布布扣,bubuko.com
Cocos2d-x 3.2 Lua示例 CaptureScreen(截屏)
标签:style blog http color java os strong io
原文地址:http://blog.csdn.net/wwj_748/article/details/38373849