NodeManager.lua 3.56 KB
cc.exports.NodeManager=class("NodeManager")

local EffectSelected = require("app.views.effect.EffectSelected");

function NodeManager.setHighlight(node,bool,isBounce)
    if isBounce == nil then
        isBounce = true;
    end
    local _parent = node:getParent();
    local selected_box = _parent:getChildByName("buttonselected");

    if bool and node:isVisible() then
        SoundManager.playEffect("res/sound/effect_selected.mp3");
        local rect = node:getBoundingBox();
        if not selected_box then
            selected_box = EffectSelected:create(rect,node.type);
            selected_box:setName("buttonselected");
            _parent:addChild(selected_box);
        else
            selected_box:setVisible(true);
            selected_box:resize(rect,node.type);
        end
        if node.type == EnumNodeType.POKER or node.type == EnumNodeType.DDZ_POKER then
            selected_box:setLocalZOrder(node:getLocalZOrder());
        else
            selected_box:setLocalZOrder(100);
        end

        if node.type ~= EnumNodeType.POKER and node.type ~= EnumNodeType.DDZ_POKER and node.type ~= EnumNodeType.MJ and isBounce then
            EffectManager.bounceNode(node);
            EffectManager.bounceNode(selected_box);
        end

        local function updateSelectedPos()
            local anchor = node:getAnchorPoint();
            local _x,_y = node:getPosition();
            if node.type == EnumNodeType.LAYER then
                _x = _x + (anchor.x)*rect.width;
                _y = _y + (anchor.y)*rect.height;
            else
                _x = _x - (anchor.x-0.5)*rect.width;
                _y = _y - (anchor.y-0.5)*rect.height;
            end
            selected_box:setPosition(cc.p(_x,_y));
        end
        updateSelectedPos();
        if node.type == EnumNodeType.MJ or node.type == EnumNodeType.DDZ_POKER then
            node.posAction = schedule(node,updateSelectedPos,0);
        end
    else
        if selected_box then
            selected_box:setVisible(false);
        end
        if node.posAction then
            node:stopAction(node.posAction);
            node.posAction = nil;
        end
    end
end

--获取生成圆角头像
function NodeManager.getRoundedHead(headName,anchorPoint)
    anchorPoint = anchorPoint or cc.p(0.5,0.5);
    local sprite_mask = cc.Sprite:create("res/common/head_mask.png");
    local spriteBg = cc.Sprite:createWithSpriteFrameName(headName);
    local clipS = cc.ClippingNode:create();  ----创建ClippingNode
    clipS:setStencil(sprite_mask);
    if spriteBg then
        clipS:addChild(spriteBg);
    end

    sprite_mask:setAnchorPoint(anchorPoint);
    spriteBg:setAnchorPoint(anchorPoint);

    clipS:setInverted(false)   ---设置可视区为裁剪区域,还是裁剪剩余区域
    clipS:setAlphaThreshold(0.05)  ---根据alpha值控制显示
    return clipS;
end

--获取生成圆角头像
function NodeManager.getRoundedHeadBySprite(sp,anchorPoint)
    anchorPoint = anchorPoint or cc.p(0.5,0.5);
    local sprite_mask = cc.Sprite:create("res/common/head_mask.png");
    local clipS = cc.ClippingNode:create();  ----创建ClippingNode
    clipS:setStencil(sprite_mask);
    if sp then
        clipS:addChild(sp);
    end

    sprite_mask:setAnchorPoint(anchorPoint);
    sp:setAnchorPoint(anchorPoint);

    clipS:setInverted(false)   ---设置可视区为裁剪区域,还是裁剪剩余区域
    clipS:setAlphaThreshold(0.05)  ---根据alpha值控制显示
    return clipS;
end

function NodeManager.getHeadSprite(headName,scale)
    scale = scale or 1;
    local spriteBg = cc.Sprite:createWithSpriteFrameName(headName);
    spriteBg:setScale(scale);
    return spriteBg;
end

return NodeManager