<strong>introductionDesc是图片精灵;</strong>
float w = 500;
float h = 394;
int bonusIndex = 0;
float bonusDy = -38;
float bonusX = w / 2;
float bonusY = (ruleVec.size() + 1) * -bonusDy + introductionDesc->getContentSize().height * introductionDesc->getScale();<pre name="code" class="cpp"> float minY = 14;
float maxY = 300;
float ch = (bonusIndex) * -bonusDy + <span style="background-color: rgb(255, 0, 0);"><strong>introductionDesc</strong></span>->getContentSize().height * introductionDesc->getScale();
float vh = maxY - minY;
_scroll->setContentSize(CCSize(w,ch));
_scroll->setViewSize(CCSize(w,vh));
_scroll->setPosition(CCPoint(-w / 2, -h / 2 + minY));
_scroll->setContentOffset(CCPoint(0,vh-ch));
_scroll->setTouchPriority(kCCMenuHandlerPriority);
</pre>遮罩:<p></p><p style="margin-top:0px; margin-bottom:0px; font-family:Monaco"></p><p style="margin-top:0px; margin-bottom:0px; font-family:Monaco; color:rgb(49,89,93)"></p><pre name="code" class="cpp"><p style="margin-top: 0px; margin-bottom: 0px; font-family: Monaco; color: rgb(79, 129, 135);">CCSize <span style="color: rgb(49, 89, 93);">vsize = _cardBg->getPreferredSize();//设置要显示出来的尺寸</span></p> float xstep = vsize.width*0.5f*_cardBg->getScale()-8*UIResolution::getScale();
float ystep = vsize.height*0.5f*_cardBg->getScale();
CCPoint pointvec[4] = {ccp(-xstep, -ystep),ccp(xstep, -ystep),ccp(xstep, ystep),ccp(-xstep, ystep)};
auto stenclil = CCDrawNode::create();
stenclil->drawPolygon(pointvec, 4, {1.0f,1.0f,1.0f,1.0f}, 1, {1.0f,1.0f,1.0f,1.0f});
clip = CCClippingNode::create();
clip->setPosition(CCPoint(UIResolution::physical().width/2,UIResolution::physical().height/2-40*UIResolution::getScale()));
// clip->setPosition(CCPoint(_cardBg->getPositionX(),_cardBg->getPositionY()));
addChild(clip);
clip->setStencil(stenclil);
然后把需要遮罩的东西添加到clip上面:
clip->addChild(_pageBglayer);