ClippingNode 实现类似子弹打穿纸片效果
来源:互联网 发布:mactype mac字体 编辑:程序博客网 时间:2024/05/01 11:19
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)));
}
- ClippingNode 实现类似子弹打穿纸片效果
- 遮罩clippingNode实现标题闪亮特效、类似机关枪瞄准效果、跑马灯效果
- cocos2dx ClippingNode实现stencil效果
- Unity 中实现子弹时间效果
- Cocos2d-x使用ClippingNode实现遮罩效果
- 用ClippingNode实现文字AVG游戏的对话字幕效果
- cocos2dx ClippingNode实现跑马灯效果和文字效果
- [WP7]实现类似tree效果
- viewgroup 实现类似viewpage效果
- oracle实现类似split效果
- 类似NumberPicker的效果实现
- 类似horizon效果的实现
- ClippingNode
- ClippingNode
- ClippingNode
- ClippingNode
- cocos2dx clippingNode的实现原理
- 类似Google Calendar效果的简单实现
- IncrediBuild 进行联合编译
- android布局属性详解
- IncrediBuild工具使用及设置
- 快递查询应用实例
- .net中连接Oracle 的两种方式:OracleClient,OleDb
- ClippingNode 实现类似子弹打穿纸片效果
- HDU 4709 三循环暴力
- Java 枚举实现单例
- IncrediBuild联合编译的使用
- 构建高性能服务(一)ConcurrentSkipListMap和链表构建高性能Java Memcached
- 【HDU 1019】Least Common Multiple —— LCM
- SVG图像动画鉴赏
- 给没有毕业的同学
- Jquery中的offset()和position()方法详解