本篇文章給大家分享的是有關(guān)使用cocos2dx怎么實現(xiàn)刮獎效果,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了永寧免費建站歡迎大家使用!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");--這個作為當(dāng)“油漆層” 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))
鼠標(biāo)移動代碼:
function shop.erasure(event) -- body print("erasure: ", event.name) --todo print("moved") local touchPoint = event.pos pEarse:setPosition(event.pos.x, event.pos.y); -- 設(shè)置混合模式 local blendFunc = { GL_ONE, GL_ZERO }; pEarse:setBlendFunc(blendFunc); -- 將橡皮擦的像素渲染到畫布上,與原來的像素進(jìn)行混合 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); //渲染紋理層需加入該父節(jié)點層 auto pBg = Sprite::create("potentiometerProgress.png"); //這個作為當(dāng)“油漆層” 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怎么實現(xiàn)刮獎效果,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。