auto target = Sprite::create("Images/blocks.png");
target->setAnchorPoint(Vec2::ZERO);
target->setScale(3);
_outerClipper = ClippingNode::create();
_outerClipper->retain();
AffineTransform tranform = AffineTransform::IDENTITY;
tranform = AffineTransformScale(tranform,target->getScale(),target->getScale());
_outerClipper->setContentSize(SizeApplyAffineTransform(target->getContentSize(),tranform));
_outerClipper->setAnchorPoint(Vec2(0.5,0.5));
_outerClipper->setPosition(Vec2(300,300));
_outerClipper->runAction(RepeatForever::create(RotateBy::create(1,45)));
_outerClipper->setStencil(target);
auto holesClipper = ClippingNode::create();
holesClipper->setInverted(true);
holesClipper->setAlphaThreshold(0.05f);
holesClipper->addChild(target);
_holes = Node::create();
_holes->retain();
holesClipper->addChild(_holes);
_holesStencil = Node::create();
_holesStencil->retain();
holesClipper->setStencil(_holesStencil);
_outerClipper->addChild(holesClipper);
this->addChild(_outerClipper);
auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan,this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener,this);
void HelloWorld::onTouchesBegan(const std::vector<Touch*>& touches,Event* event){
Touch* touch = (Touch*)touches[0];
Vec2 point = _outerClipper->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView()));
auto rect = Rect(0,0,_outerClipper->getContentSize().width,_outerClipper->getContentSize().height);
if (!rect.containsPoint(point))
{
return;
}
this->pokeHoleAtPoint(point);
}
void HelloWorld::pokeHoleAtPoint(Vec2 point){
float scale = CCRANDOM_0_1()*0.2 + 0.9;
float rotation = CCRANDOM_0_1() * 360;
auto hole = Sprite::create("Images/hole_effect.png");
hole->setPosition(point);
hole->setRotation(rotation);
hole->setScale(scale);
_holes->addChild(hole);
auto holeStencil = Sprite::create("Images/hole_stencil.png");
holeStencil->setPosition(point);
holeStencil->setRotation(rotation);
holeStencil->setScale(scale);
_holesStencil->addChild(holeStencil);
_outerClipper->runAction(Sequence::createWithTwoActions(ScaleBy::create(0.05f,0.95f),ScaleTo::create(0.125f,1)));
}