说明
在用egret移植flash游戏项目中文本常有下划线的显示效果,但是egret文本的下划线没有修改下划线的粗细大小不是很美观。
可以通过重写覆盖引擎代码egret.TextField.prototype["fillBackground"]修改下划线的粗细大小
默认效果:
 
修改后的效果效果:
 
重写文本的下划线
| 12
 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
 
 | module egretUtils {export module displayProperties {
 export function override() {
 
 
 
 
 egret.TextField.prototype["fillBackground"] = function (lines) {
 var graphics = this.$graphicsNode;
 if (graphics) {
 graphics.clear();
 }
 var values = this.$TextField;
 if (values[33 ] || values[31 ] || (lines && lines.length > 0)) {
 if (!graphics) {
 graphics = this.$graphicsNode = new egret.sys.GraphicsNode();
 if (!egret.nativeRender) {
 var groupNode = new egret.sys.GroupNode();
 groupNode.addNode(graphics);
 groupNode.addNode(this.textNode);
 this.$renderNode = groupNode;
 }
 else {
 this.$renderNode = this.textNode;
 }
 }
 var fillPath = void 0;
 var strokePath = void 0;
 
 if (values[33 ]) {
 fillPath = graphics.beginFill(values[34 ]);
 fillPath.drawRect(0, 0, this.$getWidth(), this.$getHeight());
 }
 
 if (values[31 ]) {
 strokePath = graphics.lineStyle(1, values[32 ]);
 
 strokePath.drawRect(0, 0, this.$getWidth() - 1, this.$getHeight() - 1);
 }
 
 if (lines && lines.length > 0) {
 var textColor = values[2 ];
 var lastColor = -1;
 var length_7 = lines.length;
 for (var i = 0; i < length_7; i += 4) {
 var x = lines[i];
 var y = lines[i + 1];
 var w = lines[i + 2];
 var color = lines[i + 3] || textColor;
 if (lastColor < 0 || lastColor != color) {
 lastColor = color;
 strokePath = graphics.lineStyle(1, color, 1, egret.CapsStyle.NONE);
 }
 strokePath.moveTo(x, y);
 strokePath.lineTo(x + w, y);
 }
 }
 }
 if (graphics) {
 var bounds = this.$getRenderBounds();
 graphics.x = bounds.x;
 graphics.y = bounds.y;
 graphics.width = bounds.width;
 graphics.height = bounds.height;
 egret.Rectangle.release(bounds);
 }
 };
 
 }
 }
 }
 
 | 
引用
在Main或者项目初始化的引入即可
如果是单独个别文本下划线需要修改粗细,单独文本修改即可
| 1
 | egretUtils.displayProperties.override();
 |