ClippingNode的简单使用
2015-11-29 21:49
597 查看
在游戏的某些场合,需要展现一些如圆形、椭圆形以及特定形状的图片,如果使用的地方比较多,需要美术逐个出图的话难免会造成空间浪费,如果使用ClippingNode剪裁节点,那么只需要特定形状的模板,那么便可将一张要展现的图片裁成需要的样子。而且ClippingNode还常用于新手引导。
这里有2张图片:
使用ClippingNode可以将第一张图片剪成第二张图的形状。
1.C++版
结果如图:
c_node->setInverted(true);
c_node->setAlphaThreshold(0.0f);时
c_node->setInverted(false);
c_node->setAlphaThreshold(1.0f);时
c_node->setInverted(true);
c_node->setAlphaThreshold(1.0f);时
2.Lua版
附几个链接,ClippingNode比较高端的使用方法以及做新手引导的思路,感谢大神们的分享:
http://www.cocos2dx.net/post/324
http://www.tuicool.com/articles/7ZfeMn
http://blog.csdn.net/lengxue789/article/details/41481329
这里有2张图片:
使用ClippingNode可以将第一张图片剪成第二张图的形状。
1.C++版
#include "2d/CCClippingNode.h" //模板 Sprite* stencil = Sprite::create("res/mark.png"); ClippingNode* c_node = ClippingNode::create(); c_node->setStencil(stencil); c_node->setInverted(false); c_node->setAlphaThreshold(0.0f); //需要剪裁的节点 Sprite* sp = Sprite::create("res/di.png"); c_node->addChild(sp); addChild(c_node); c_node->setPosition(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2);
结果如图:
c_node->setInverted(true);
c_node->setAlphaThreshold(0.0f);时
c_node->setInverted(false);
c_node->setAlphaThreshold(1.0f);时
c_node->setInverted(true);
c_node->setAlphaThreshold(1.0f);时
2.Lua版
local stencil= cc.Sprite:create('res/mark.png') local c_node = cc.ClippingNode:create() c_node:setStencil(stencil) c_node:setInverted(false) c_node:setAlphaThreshold(0) local sp = cc.Sprite:create('res/di.png') c_node:addChild(sp) layer:addChild(c_node) c_node:setPosition(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2)
附几个链接,ClippingNode比较高端的使用方法以及做新手引导的思路,感谢大神们的分享:
http://www.cocos2dx.net/post/324
http://www.tuicool.com/articles/7ZfeMn
http://blog.csdn.net/lengxue789/article/details/41481329
相关文章推荐
- nodejs学习路线图
- Nodejs学习笔记(一)——初识Nodejs
- Hadoop 启动节点Datanode失败解决
- HDFS学习笔记
- 用第三方框架GDataXMLNode解析XML数据:
- DOM----nodeType,nodeName,nodeValue笔记
- 《Node.js实战(第2季)》 读书笔记
- nodejs net模块实现socket
- nodeJs常用的一些地址
- [Nodejs入门]第四篇,用nodejs实现一个爬虫的功能
- [nodejs入门]第一篇,javascript基础(2)
- node.js和socket.io纯js实现的即时通讯实例分享
- 237. Delete Node in a Linked List
- Swap Nodes in Pairs
- ROS_hydro_catkin建立标准程序包_helloworld.h+helloworld.cpp+helloworldnode.cpp
- NodeManagerMetrics上精确化Container指标监控
- NodeJS中使用benchmark进行基准测试-@alsotang
- nodejs学习--子进程 child_process模块的基本介绍
- nodejs学习--util
- nodej-- Query String