const {ccclass, property} = cc._decorator;
@ccclass
export class Toast extends cc.Component {
@property(cc.Node)
bg: cc.Node = null;
@property(cc.Label)
label: cc.Label = null;
public constructor() {
super();
}
onLoad() {
}
** init(text: string) {**
** this.label.overflow = cc.Label.Overflow.NONE;**
** this.label.string = text;**
** let labelWidth = this.label.node.width;**
** this.bg.width = labelWidth + 45;**
** }**
public show(text: string, delay?: number) {
this.init(text);
let delayTime = 3;
if (delay) {
delayTime = delay;
}
this.node.opacity = 150;
this.node.runAction(cc.sequence(
cc.fadeIn(0.5),
cc.delayTime(delayTime),
cc.fadeOut(1),
cc.callFunc(this.dismiss, this)
));
}
private dismiss(): void {
this.node.destroy();
}
}
为啥背景不会随文字长度变化而改变长度了呢?感觉有点懵,不知道问题出在哪里,之前是可以的,希望大神们给点意见
