欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

cocos2dx+lua實現(xiàn)橡皮擦功能

 更新時間:2018年12月20日 11:58:16   作者:夢醒-時分  
這篇文章主要為大家詳細(xì)介紹了cocos2dx+lua實現(xiàn)橡皮擦功能,類似刮刮樂效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

游戲中刮刮樂是怎么實現(xiàn)的?做了一個小例子看了一下。

實現(xiàn)原理:隨著觸摸點的移動,通過setBlendFunc函數(shù)設(shè)置部分區(qū)域的顏色混合(將上層圖片透明度為0,底層我們想要的圖片就顯示出來)

--橡皮擦功能測試
local function initInfo()
 local scene = CCScene:create()
 
 local layer = CCLayer:create()
 scene:addChild(layer)
 --擦除后要顯示的圖片
 local tupian = CCSprite:create(ROOT_RES .. "set/tip.png")
 tupian:setPosition(ccp(WinSizeWidth / 2, WinSizeHeight / 2))
 layer:addChild(tupian)
 --涂層
 local tu = CCSprite:create(ROOT_RES..'set/user/BG.png')
 tu:setPosition(ccp(WinSizeWidth/2,WinSizeHeight/2))
 --layer:addChild(tu)
 --將圖層遍歷到texture,再將texture加入當(dāng)前層
 local ptex = CCRenderTexture:create(1280,720)
 ptex:setPosition(ccp(WinSizeWidth/2,WinSizeHeight/2))
 layer:addChild(ptex)
 ptex:begin()
 tu:visit()
 ptex:endToLua()
 --橡皮擦CCDrawNode
 --point = CCDrawNode:create()
 --point:drawDot(ccp(0,0),10,ccc4f(0,0,0,0))
 local point = CCSprite:create(ROOT_RES..'set/labBtn.png')
 layer:addChild(point)
 --[[local blend = ccBlendFunc()
 blend.src = 0
 blend.dst = 1
 tu:setBlendFunc(blend)--]]
 --local blend = tu:getBlendFunc()
 layer:registerScriptTouchHandler(function (eventType,x,y)
 if eventType == "began" then
  cclog("began")
  return true
 elseif eventType == "moved" then
  cclog("move")
  point:setPosition(x,y)
  local blend = ccBlendFunc()
  blend.src = 1
  blend.dst = 0
  point:setBlendFunc(blend)
  ptex:begin()
  point:visit()
  ptex:endToLua()
 elseif eventType == "ended" then
  cclog("end")
 elseif eventType == "cancelled" then
  
 end
 end,false,-1000,true)
 layer:setTouchEnabled(true)
 return scene
end

function getInfoLayer()
 CCDirector:sharedDirector():replaceScene(initInfo())
end

完成后效果如下:(圖片都是游戲中隨便找的,有點差強(qiáng)人意)


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論