99 lines
2.0 KiB
JavaScript
99 lines
2.0 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '84017bg8wtFsJVjBK0ySDrY', 'cmp.message.marquee');
|
|
// Scripts/nx/cmp/message/cmp.message.marquee.js
|
|
|
|
"use strict";
|
|
|
|
/*******************************************************************************
|
|
*
|
|
* 跑马灯
|
|
*
|
|
*
|
|
*
|
|
* 2021.12.10
|
|
******************************************************************************/
|
|
|
|
cc.Class({
|
|
"extends": cc.Component,
|
|
properties: {
|
|
speed: {
|
|
"default": 200,
|
|
displayName: "速度(像素/秒)"
|
|
},
|
|
nodArea: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
tmpNode: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// 载入
|
|
onLoad: function onLoad() {
|
|
this.cur = null;
|
|
this.queue = [];
|
|
|
|
// 隐藏
|
|
this.node.opacity = 0;
|
|
this.tmpNode.x = -8000;
|
|
},
|
|
// 加入
|
|
push: function push(_msg, _times) {
|
|
if (_times === void 0) {
|
|
_times = 1;
|
|
}
|
|
if (nx.dt.strEmpty(_msg)) {
|
|
return;
|
|
}
|
|
for (var i = 0; i < _times; ++i) {
|
|
this.queue.push(_msg);
|
|
}
|
|
if (!this.cur) {
|
|
this.popNext();
|
|
}
|
|
},
|
|
// 弹出
|
|
popNext: function popNext() {
|
|
var _this = this;
|
|
// 空了
|
|
if (nx.dt.arrEmpty(this.queue)) {
|
|
this.cur = null;
|
|
nx.tween.fadeOut(this, "", 0.5);
|
|
this.node.opacity = 0;
|
|
return;
|
|
}
|
|
|
|
// 起步
|
|
if (!this.cur) {
|
|
nx.tween.fadeIn(this, "", 0.2);
|
|
}
|
|
|
|
// 计算弹窗起始位置
|
|
var sx = this.nodArea.width;
|
|
if (this.cur) {
|
|
var rt = this.cur.x + this.cur.rt._labelWidth * 0.8;
|
|
if (rt > sx) {
|
|
sx = rt;
|
|
}
|
|
}
|
|
|
|
// 弹出
|
|
var msg = this.queue.shift();
|
|
var item = cc.instantiate(this.tmpNode);
|
|
item.parent = this.nodArea;
|
|
item.y = 0;
|
|
item.x = sx;
|
|
item.rt = nx.gui.setString(item, "", msg);
|
|
this.cur = item;
|
|
var width = item.rt._labelWidth * 0.5;
|
|
var secs = (sx + width) / this.speed;
|
|
cc.tween(item).to(secs, {
|
|
x: -width
|
|
}).call(function () {
|
|
_this.popNext();
|
|
}).start();
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |