您的位置:首页 > Web前端 > Node.js

ClippingNode的简单使用

2015-11-29 21:49 597 查看
在游戏的某些场合,需要展现一些如圆形、椭圆形以及特定形状的图片,如果使用的地方比较多,需要美术逐个出图的话难免会造成空间浪费,如果使用ClippingNode剪裁节点,那么只需要特定形状的模板,那么便可将一张要展现的图片裁成需要的样子。而且ClippingNode还常用于新手引导。

这里有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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: