cocos2dx刮奖效果实现

前端之家收集整理的这篇文章主要介绍了cocos2dx刮奖效果实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

刮奖效果其实挺简单的,需要用到RenderTexture来进行渲染,通过你所要渲染的图层,把该层的颜色进行设置混合就可以达到效果,具体看代码,我用的lua实现的。

    local winsize = cc.Director:sharedDirector():getWinSize();
    local dataSprite = cc.Sprite:create("Star.png")--要把这个图片刮出来
    dataSprite:setAnchorPoint(cc.p(0.5,0.5));
    dataSprite:move(winsize.width / 2.0,winsize.height / 2.0);
    self:addChild(dataSprite)

    pEarse = cc.DrawNode:create()
    pEarse:drawDot(cc.p(0,0),5,cc.c4f(1,1));
    pEarse:retain()

    pRTex = cc.RenderTexture:create(winsize.width,winsize.height);
    pRTex:setPosition(cc.p(winsize.width / 2,winsize.height / 2));
    --this:addChild(pRTex);
    pRTex:retain()

    local pBg = cc.Sprite:create("d1.png");--这个作为当“油漆层”
    pBg:setAnchorPoint(cc.p(0.5,0.5));
    pBg:move(winsize.width / 2.0,winsize.height / 2.0);

    pRTex:begin();
    dataSprite:visit();
    pBg:visit();
    pRTex:endToLua();
    local layer=cc.Layer:create()
    self:addChild(layer,1000)
    layer:addChild(pRTex);
    layer:setNodeTouch(handler(self,self.onTouchStart))
鼠标移动代码



function shop.erasure(event)
    -- body
    print("erasure: ",event.name)
    --todo
    print("moved")
    local touchPoint = event.pos
    pEarse:setPosition(event.pos.x,event.pos.y);
    -- 设置混合模式
    local blendFunc = { GL_ONE,GL_ZERO };
    pEarse:setBlendFunc(blendFunc);
    -- 将橡皮擦的像素渲染到画布上,与原来的像素进行混合
    pRTex:begin();
    pEarse:visit();
    pRTex:endToLua();
    
end
原文链接:/cocos2dx/342485.html

猜你在找的Cocos2d-x相关文章