本文代码适用于Cocos2d-x Quick-Community3.6
local TestScene = class("TestScene", function()
return display.newScene("TestScene")
end)
function TestScene:ctor()
end
function TestScene:onEnter()
self:initUI()
end
function TestScene:initUI()
--刮刮卡底层容器
local scratchLayer = display.newLayer()
scratchLayer:setContentSize(self:getBoundingBox())
self:addChild(scratchLayer)
scratchLayer:setTouchEnabled(true)
scratchLayer:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE)
--创建RenderTexture
local scratch = cc.RenderTexture:create(scratchLayer:getBoundingBox().width,scratchLayer:getBoundingBox().height)
scratch:setPosition(scratchLayer:getBoundingBox().width/2,scratchLayer:getBoundingBox().height/2)
scratch:retain()
--需要被挂掉的精灵 本文以纯白背景代替
local bg = cc.Sprite:createWithTexture(nil, cc.rect(0,0 , scratchLayer:getBoundingBox().width,scratchLayer:getBoundingBox().height))
bg:setColor(cc.c3b(255,255,255))
bg:setPositi