Marquee.js
4.84 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
106
107
108
109
110
111
112
113
//用于做动态添加文字滚动效果
var Common = require('Common');
cc.Class({
extends: cc.Component,
properties: {
},
init: function (strText, aStrLabel) {
this._aStrLabel = aStrLabel;
this._iCurrent = 0;
let nodeTitleText = this.node.getChildByName("TitleText");
let nodeTitleText1;
let nodeTitleText2;
this.labelTitleText1;
this.labelTitleText2;
if (!nodeTitleText) {
nodeTitleText = new cc.Node("TitleText");
nodeTitleText1 = new cc.Node("TitleText1");
nodeTitleText2 = new cc.Node("TitleText2");
this.labelTitleText1 = nodeTitleText1.addComponent(cc.Label);
this.labelTitleText2 = nodeTitleText2.addComponent(cc.Label);
nodeTitleText.addChild(nodeTitleText1);
nodeTitleText.addChild(nodeTitleText2);
nodeTitleText.parent = this.node;
this.labelTitleText1.fontSize = 22;
this.labelTitleText2.fontSize = 22;
this.labelTitleText1.lineHeight = 24;
this.labelTitleText2.lineHeight = 24;
nodeTitleText1.anchorX = 0;
nodeTitleText2.anchorX = 0;
let layoutTitleText = nodeTitleText.addComponent(cc.Layout);
layoutTitleText.type = cc.Layout.Type.HORIZONTAL;
layoutTitleText.resizeMode = cc.Layout.ResizeMode.CONTAINER;
layoutTitleText.spacingX = 60;
this.node.addComponent(cc.Mask);
} else {
nodeTitleText1 = nodeTitleText.getChildByName("TitleText1");
nodeTitleText2 = nodeTitleText.getChildByName("TitleText2");
this.labelTitleText1 = nodeTitleText1.getComponent(cc.Label);
this.labelTitleText2 = nodeTitleText2.getComponent(cc.Label);
}
nodeTitleText.anchorX = 0;
this.node.anchorX = 0;
this.labelTitleText1.string = strText;
this.labelTitleText2.string = strText;
if (aStrLabel.length > 0 && aStrLabel[0]) {
this.labelTitleText1.string = aStrLabel[0];
this.labelTitleText2.string = aStrLabel[0];
this._iCurrent++;
}
this.labelTitleText1._forceUpdateRenderData(true);
this.labelTitleText2._forceUpdateRenderData(true);
this.node.x = -this.node.width / 2;
nodeTitleText2.opacity = 0;
nodeTitleText.x = 0;
nodeTitleText.y = -1;
nodeTitleText.x = 0;
this.node.opacity = 255;
},
setUIWithFocus: function () {
var self = this;
//转起来 这部分以后要尽量放到Cell里去
let nodeTitleMask = this.node;
let nodeTitleContainer = nodeTitleMask.getChildByName('TitleText');
let nodeTitleText1 = nodeTitleContainer.getChildByName("TitleText1");
let nodeTitleText2 = nodeTitleContainer.getChildByName("TitleText2");
let fOriginalX = nodeTitleContainer.x;
let fOriginalY = nodeTitleContainer.y;
if (nodeTitleText1.width > nodeTitleMask.width) { //字超出长度才滚动
nodeTitleText2.opacity = 255;
let fEndPositionDelta = nodeTitleText1.width / 2 + nodeTitleText2.width / 2 + 50;
//下方时长和字有关系,才能速度一样h
var ftaTitleMoveToTarget = cc.moveTo(10, fOriginalX - fEndPositionDelta, fOriginalY);
var ftaTitleMoveToBack = cc.moveTo(0, fOriginalX, fOriginalY);
var sequenceTitle = cc.sequence(ftaTitleMoveToTarget, ftaTitleMoveToBack);
var finished = cc.callFunc(function () {
if (self._aStrLabel.length > 0) {
self.labelTitleText1.string = self._aStrLabel[this._iCurrent % self._aStrLabel.length];
self.labelTitleText2.string = self._aStrLabel[this._iCurrent % self._aStrLabel.length];
this._iCurrent++;
self.labelTitleText1._forceUpdateRenderData(true);
self.labelTitleText2._forceUpdateRenderData(true);
self.setUIWithFocus();
}
}, this, null);
var repeatTitle = cc.repeat(cc.sequence(sequenceTitle, finished), 10);
repeatTitle.setTag(Common.OVERLENGTH_MOVING);
nodeTitleContainer.stopAction(nodeTitleContainer.getActionByTag(Common.OVERLENGTH_MOVING));
nodeTitleContainer.runAction(repeatTitle);
}
},
setUIWithoutFocus: function () {
let nodeTitleMask = this.node;
let nodeTitleContainer = nodeTitleMask.getChildByName('TitleText');
nodeTitleContainer.stopAction(nodeTitleContainer.getActionByTag(Common.OVERLENGTH_MOVING));
let nodeTitleText2 = nodeTitleContainer.getChildByName("TitleText2");
nodeTitleText2.opacity = 0;
nodeTitleContainer.x = 0;
},
prohibit: function () {
this.setUIWithoutFocus();
this.node.opacity = 0;
},
});