介绍
本篇文章为大家展示了如何在cocos2dx中使用lua实现橡皮擦功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
<强>实现原理:>强随着触摸点的移动,通过setBlendFunc函数设置部分区域的颜色混合(将上层图片透明度为0,底层我们想要的图片就显示出来)
——橡皮擦功能测试 local function  initInfo () ,local scene =, CCScene:创建() , ,local layer =, CCLayer:创建() ,场景:addChild(层) ,——擦除后要显示的图片 ,local tupian =, CCSprite:创建(ROOT_RES …,“设置/tip.png") ,图皮人的:setPosition (ccp(时间/WinSizeWidth 2, WinSizeHeight /, 2)) ,层:addChild(图皮人的) ,——涂层 ,local tu =, CCSprite:创建(ROOT_RES…& # 39;设置/user/BG.png& # 39;) ,你:setPosition (ccp (WinSizeWidth/2, WinSizeHeight/2)) ,——层:addChild(图) ,——将图层遍历到质地,再将纹理加入当前层 ,local ptex =, CCRenderTexture:创建(1280、720) ,ptex: setPosition (ccp (WinSizeWidth/2, WinSizeHeight/2)) ,层:addChild (ptex) ,ptex:开始() ,你:访问() ,ptex: endToLua () ,——橡皮擦CCDrawNode ,——point =, CCDrawNode:创建() ,- - -点:drawDot (ccp (0, 0) 10 ccc4f (0, 0, 0, 0)) ,local point =, CCSprite:创建(ROOT_RES…& # 39;设置/labBtn.png& # 39;) ,层:addChild(点) ,——[[local blend =, ccBlendFunc () blend.src =, 0 blend.dst =, 1 ,你:setBlendFunc(混合)]]=,- local blend 你:getBlendFunc () ,层:registerScriptTouchHandler (function (eventType, x, y)==,if eventType “began"然后 cclog才能(“began") return 才能正确==,elseif eventType “moved"然后 cclog才能(“move") 点才能:setPosition (x, y) local 才能;blend =, ccBlendFunc () blend.src 才能=1 blend.dst 才能=0 点:才能setBlendFunc(混合) ptex才能:开始() 点:才能访问() ptex才能:endToLua ()==,elseif eventType “ended"然后 cclog才能(“以何种)==,elseif eventType “cancelled"然后 ,, ,结束 ,最后,假的,-1000年,真的) ,层:setTouchEnabled(真正的) return 场景 结束 function getInfoLayer () ,CCDirector: sharedDirector (): replaceScene (initInfo ()) 结束
上述内容就是如何在cocos2dx中使用lua实现橡皮擦功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。