cocos2d-x技术群新群:117871561
c++技术交流群:593010226
--创建裁剪图片(要裁剪的形状,大小)
function HeadSprite:createClipImage(clippingfile,size )
local sp = HeadSprite.new()
local sprender = cc.Sprite:create("my.png")
sp.size = size
--创建裁剪
local strClip = "head_mask.png"
if nil ~= clippingfile then
strClip = clippingfile
end
local clipSp = nil
local frame = cc.SpriteFrameCache:getInstance():getSpriteFrame(strClip)
if nil ~= frame then
clipSp = cc.Sprite:createWithSpriteFrame(frame)
else
clipSp = cc.Sprite:create(strClip)
end
if nil ~= clipSp then
--裁剪
local clip = cc.ClippingNode:create()
clip:setStencil(clipSp)
clip:setAlphaThreshold(0)
clip:addChild(sprender)
local selfSize = sp:getContentSize()
clip:setPosition(cc.p(selfSize.width * 0.5, selfSize.height * 0.5))
sp:addChild(clip)
return sp
end
return nil
end
网友评论