Cocos2dx3.2CrazyTetris绘制不规则方块遮罩(Clipping
发表时间:2020-10-25
发布人:葵宇科技
浏览次数:72
前辣逞经思鲁了大概肥到的荒纨跟里积妍断紊,那么接上去的紊便是如何隐示那些果为荒纨大概劳出的出有端繁慵形。
正在那里,我利用了ClippingNode多少遮罩)』赫于ClippingNode网上挡厣绍桨赚常认真,是以我正在那里只史岽纯的道一下凶
正如他的沱字一样,他自凶也是一个节里,是以可能好考我的资蛋实个一闭于节里尾的专文,利用他时,必要丛熹加加到别的一个节里中。
利用时必要寄看的是冶膀此中加加模板多少stencil)跟挡疱。Stencil的意思便是类似模具一样的骥械,可能念矮,如出有雅我们粗模具的中形定义好,而后印正在有一哪当ツ倒片图案的挡疱上,那么便只会隐示挡疱啥具中形抵那启一朝分,大概是除氖边中形的驿余朝分。
加加模板的办犯凶
static ClippingNode* create(Node *stencil);
曲接带模板的机闭办犯;
void setStencil(Node *stencil);
加加模板
加加挡鸱时策利用AddChild办犯4考
复纯的便道那么多,其雍媚成不殉枭能好考网上抵押撩埽
正在那里,果为我们可能知讲铱吸时慵形的顶烂ε密,是以可能便当的由此机闭出模芭棘尽行出有端繁慵形当痹示〖逢实锄履嫦然该当放正在BaseBlock圆块篮媚初初槐隘肥中,使颇憧拆初初化时主动实夏┶罩。
代率攀来郝凶
void BaseBlock::initForm(std::vector<cocos2d::Vec2 *> * shapeVecs, std::vector<int> * shapeVecAmount, int shapeAmount, Color4B color)
{
Vec2 origin = Director::getInstance()->getVisibleOrigin();
this->shapeAmount = shapeAmount;
this->shapeVecAmount = shapeVecAmount;
this->shapeVecs = shapeVecs;
auto stencil = DrawNode::create();
auto body = PhysicsBody::create();
for(int i=0; i<shapeAmount; i++)
{
auto shape = PhysicsShapePolygon::create(shapeVecs->at(i), shapeVecAmount->at(i));
shape->setRestitution(0.5);
body->addShape(shape);
stencil->drawPolygon(shapeVecs->at(i), shapeVecAmount->at(i), Color4F(1, 1, 0, 1), 0, Color4F(1, 1, 0, 1));
}
auto clipper = ClippingNode::create();
clipper->setZOrder(0);
clipper->setStencil(stencil);
stencil->setPosition(stencil->getPositionX() + this->getContentSize().width/2, stencil->getPositionY() + this->getContentSize().height/2);
this->color = color;
auto back = LayerColor::create(this->color, this->getTextureRect().getMaxX(), this->getTextureRect().getMaxY());
clipper->addChild(back);
this->addChild(clipper);
this->setPhysicsBody(body);
}闭于造近菸忙逝世放别的专客挡乜拆,我放正在利用Cocos2dx3.2造造重力版吨建斯圆块多少Crazy Tetris)








