cc.Node.prototype.addClippingCircleRect = function(str, attr){
var size = attr.size || this.getContentSize();
var clipSize = attr.clipSize || this.getContentSize();
var offsetX = attr.offsetX || 0;
var offsetY = attr.offsetY || 0;
var radius = attr.radius || 10;
//圆角层实现代码
var stencil = new cc.DrawNode();
stencil.drawRect(cc.p((size.width-clipSize.width)/2+offsetX,(size.height-clipSize.height)/2+offsetY+radius),cc.p((size.width+clipSize.width)/2+offsetX,(size.height+clipSize.height)/2+offsetY-radius),cc.color(0,0,0),1,cc.color(0,0,0));
stencil.drawRect(cc.p((size.width-clipSize.width)/2+offsetX+radius,(size.height-clipSize.height)/2+offsetY),cc.p((size.width+clipSize.width)/2+offsetX-radius,(size.height+clipSize.height)/2+offsetY),cc.color(0,0,0),1,cc.color(0,0,0));
stencil.drawCircle(cc.p((size.width-clipSize.width)/2+offsetX+radius,(size.height-clipSize.height)/2+offsetY+radius),radius/3,0,100,false,radius,cc.color(0,0,0));
stencil.drawCircle(cc.p((size.width+clipSize.width)/2+offsetX-radius,(size.height-clipSize.height)/2+offsetY+radius),radius/3,0,100,false,radius,cc.color(0,0,0));
stencil.drawCircle(cc.p((size.width+clipSize.width)/2+offsetX-radius,(size.height+clipSize.height)/2+offsetY-radius),radius/3,0,100,false,radius,cc.color(0,0,0));
stencil.drawCircle(cc.p((size.width-clipSize.width)/2+offsetX+radius,(size.height+clipSize.height)/2+offsetY-radius),radius/3,0,100,false,radius,cc.color(0,0,0));
var layer = new cc.LayerColor(cc.color(0,0,0),clipSize.width, clipSize.height);
layer.x = (size.width-clipSize.width)/2+offsetX;
layer.y = (size.height-clipSize.height)/2+offsetY;
//层透明度
layer.opacity = 0;
var clippingPanel = new cc.ClippingNode();
clippingPanel.stencil = stencil;
clippingPanel.addChild(layer);
this.addChild(clippingPanel);
var spImg = new cc.Sprite(str);
//spImg.getTexture().setAliasTexParameters();
spImg.setAnchorPoint(cc.p(0.5, 0.5));
spImg.setPosition(cc.p(attr.clipSize.width/2, attr.clipSize.height/2));
layer.addChild(spImg);
return spImg;
};
裁剪圆角矩形模板
最新推荐文章于 2024-04-24 01:05:01 发布