NodeManager.lua
3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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