--复制对象纹理
function g_CutPicture(pContainer)
local winSize = cc.Director:getInstance():getWinSize();
local aniSize = pContainer:getContentSize();
--aniSize = cc.size(120,200);
local aniAnchorPoint = cc.p( pContainer:getAnchorPoint() );
--print(aniAnchorPoint.x,aniAnchorPoint.y);
aniAnchorPoint.x = 0.5;
local worldPos = pContainer:getParent():convertToWorldSpace( cc.p( pContainer:getPosition() ) );
local cutSizeWidth = worldPos.x + aniSize.width*(1 - aniAnchorPoint.x);
local cutSizeHeight = worldPos.y + aniSize.height*(1 - aniAnchorPoint.y);
-- cutSizeWidth = cutSizeWidth > 0 and cutSizeWidth or -1;
-- cutSizeHeight = cutSizeHeight > 0 and cutSizeHeight or -1;
-- print(cutSizeWidth,cutSizeHeight);
local rt = nil;
if cutSizeWidth > 0 and cutSizeHeight > 0 then
rt = cc.RenderTexture:create( cutSizeWidth , cutSizeHeight );
else
print("-----------------------------------------");
print(pContainer:getPositionX(),pContainer:getPositionY());
print( "worldPos.x = "..worldPos.x.."; worldPos.y = "..worldPos.y );
print(cutSizeWidth,cutSizeHeight);
end
if rt then
rt:retain();
rt:beginWithClear(255,255,255,0);
--pContainer:visit();
--绘制所有节点
function drawAllNode( node )
if node:getChildrenCount() > 0 and node:isVisible() == true then
for k,v in pairs( node:getChildren() ) do
drawAllNode(v);
-- v:visit();
end
end
if node:isVisible() == true then
node:visit();
end
end
drawAllNode(pContainer);
rt:endToLua();
local texture = rt:getSprite():getTexture();
local cutX = worldPos.x - aniSize.width*aniAnchorPoint.x;
local maxX = aniSize.width ;
-- if cutX < 0 then
-- --maxX = maxX + cutX;
-- --cutX = 0;
-- end
local cutY = worldPos.y - aniSize.height*aniAnchorPoint.y;
local maxY = aniSize.height ;
-- if maxY < 0 then
-- --maxY = maxY + cutY;
-- --cutY = 0;
-- end
local texRect = cc.rect( cutX,
cutY,
maxX,
maxY );
-- for k,v in pairs(texRect) do
-- print(k,v)
-- end
if texture then
local pSprite = cc.Sprite:createWithTexture(texture,texRect );
pSprite:setFlippedY(true);
pSprite:setAnchorPoint( aniAnchorPoint );
return pSprite;
end
rt:release();
rt = nil
end
return nil;
end
复制对象纹理
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 在js中,我们经常复制一个对象,复制数据,那么就会有人问了,怎么复制? JS中对象分为基本类型和复合(引用)类型,...