使用cocos2dx怎么实现刮奖效果
本篇文章给大家分享的是有关使用cocos2dx怎么实现刮奖效果,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联公司-专业网站定制、快速模板网站建设、高性价比柏乡网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式柏乡网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖柏乡地区。费用合理售后完善,十年实体公司更值得信赖。
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, 0, 0, 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
C++代码:
void function() { //test code auto aPanelSprite = Sprite::create("potentiometerTrack.png"); aPanelSprite->setPosition(Vec2(s.width / 2, s.height / 2)); this->addChild(aPanelSprite); pEase = DrawNode::create(); pEase->retain(); pEase->drawDot(Point(0, 0), 4.0f, Color4F(255, 0, 0, 255)); pRender = RenderTexture::create(s.width, s.height); pRender->retain(); pRender->setPosition(Vec2(s.width / 2, s.height / 2)); this->addChild(pRender); //渲染纹理层需加入该父节点层 auto pBg = Sprite::create("potentiometerProgress.png"); //这个作为当“油漆层” pBg->setAnchorPoint(Point(0.5, 0.5)); pBg->setPosition(Vec2(s.width / 2, s.height / 2)); pRender->begin(); aPanelSprite->visit(); pBg->visit(); pRender->end(); auto listener = EventListenerTouchOneByOne::create(); listener->setSwallowTouches(true); listener->onTouchBegan = CC_CALLBACK_2(SpriteEaseBezier::onTouchBegan, this); listener->onTouchMoved = CC_CALLBACK_2(SpriteEaseBezier::onTouchMoved, this); auto _eventDispatcher = CCDirector::getInstance()->getEventDispatcher(); _eventDispatcher->addEventListenerWithFixedPriority(listener, -10); } bool SpriteEaseBezier::onTouchBegan(Touch *touch, Event *unused_event) { CCLOG("SpriteEaseBezier::onTouchBegan"); return true; } void SpriteEaseBezier::onTouchMoved(Touch *touch, Event *unused_event) { auto touchPoint = touch->getLocation(); pEase->setPosition(touchPoint.x, touchPoint.y); BlendFunc blendFunc = { GL_ONE, GL_ZERO }; pEase->setBlendFunc(blendFunc); pRender->begin(); pEase->visit(); pRender->end(); CCLOG("SpriteEaseBezier::onTouchMoved"); }
以上就是使用cocos2dx怎么实现刮奖效果,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
分享名称:使用cocos2dx怎么实现刮奖效果
本文链接:http://pwwzsj.com/article/jihdpj.html