(vivo引擎1041
以上版本,文本已不会出现问题)
vivo工程中egret.vivogame.js
,搜索WebGLRenderer.prototype.renderText
,修改此函数。
核心部分(里面的偏移数字可以根据实际效果调节,这里是0.9):
if (lowerVersion){
this.canvasRenderBuffer.context.$offsetX = canvasScaleX * (-x)*0.5 + canvasScaleX * canvasScaleX*0.5;
this.canvasRenderBuffer.context.$offsetY = canvasScaleY * (-y)*0.5 + canvasScaleY * canvasScaleY*0.5;
}
if (lowerVersion){
textureWidth *= canvasScaleX*0.9;
textureHeight *= canvasScaleY*0.9;
}
对应完整函数:
var lowerVersion = qg.getSystemInfoSync().platformVersionCode <= 1041;
WebGLRenderer.prototype.renderText = function (node, buffer) {
if (vivogame.textAtlasRenderEnable) {
this.___renderText____(node, buffer);
return;
}
var width = node.width - node.x;
var height = node.height - node.y;
if (width <= 0 || height <= 0 || !width || !height || node.drawData.length == 0) {
return;
}
var canvasScaleX = egret.sys.DisplayList.$canvasScaleX;
var canvasScaleY = egret.sys.DisplayList.$canvasScaleY;
var maxTextureSize = buffer.context.$maxTextureSize;
if (width * canvasScaleX > maxTextureSize) {
canvasScaleX *= maxTextureSize / (width * canvasScaleX);
}
if (height * canvasScaleY > maxTextureSize) {
canvasScaleY *= maxTextureSize / (height * canvasScaleY);
}
width *= canvasScaleX;
height *= canvasScaleY;
var x = node.x * canvasScaleX;
var y = node.y * canvasScaleY;
if (node.$canvasScaleX != canvasScaleX || node.$canvasScaleY != canvasScaleY) {
node.$canvasScaleX = canvasScaleX;
node.$canvasScaleY = canvasScaleY;
node.dirtyRender = true;
}
if (this.wxiOS10) {
if (!this.canvasRenderer) {
this.canvasRenderer = new egret.CanvasRenderer();
}
if (node.dirtyRender) {
this.canvasRenderBuffer = new vivogame.CanvasRenderBuffer(width, height);
}
}
else
{
if (!this.canvasRenderBuffer || !this.canvasRenderBuffer.context) {
this.canvasRenderer = new egret.CanvasRenderer();
this.canvasRenderBuffer = new vivogame.CanvasRenderBuffer(width, height);
}
else if (node.dirtyRender) {
this.canvasRenderBuffer.resize(width, height);
}
}
if (!this.canvasRenderBuffer.context) {
return;
}
if (canvasScaleX != 1 || canvasScaleY != 1) {
this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
}
if (x || y) {
if (node.dirtyRender) {
this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, -x, -y);
if (lowerVersion){
this.canvasRenderBuffer.context.$offsetX = canvasScaleX * (-x)*0.5 + canvasScaleX * canvasScaleX*0.5;
this.canvasRenderBuffer.context.$offsetY = canvasScaleY * (-y)*0.5 + canvasScaleY * canvasScaleY*0.5;
}
}
buffer.transform(1, 0, 0, 1, x / canvasScaleX, y / canvasScaleY);
}
else if (canvasScaleX != 1 || canvasScaleY != 1) {
this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
}
if (node.dirtyRender) {
var surface = this.canvasRenderBuffer.surface;
this.canvasRenderer.renderText(node, this.canvasRenderBuffer.context);
if (this.wxiOS10) {
surface["isCanvas"] = true;
node.$texture = surface;
}
else {
var texture = node.$texture;
if (!texture) {
texture = buffer.context.createTexture(surface);
node.$texture = texture;
}
else {
buffer.context.updateTexture(texture, surface);
}
}
node.$textureWidth = surface.width;
node.$textureHeight = surface.height;
}
var textureWidth = node.$textureWidth;
var textureHeight = node.$textureHeight;
if (lowerVersion){
textureWidth *= canvasScaleX*0.9;
textureHeight *= canvasScaleY*0.9;
}
buffer.context.drawTexture(node.$texture, 0, 0, textureWidth, textureHeight, 0, 0, textureWidth / canvasScaleX, textureHeight / canvasScaleY, textureWidth, textureHeight);
if (x || y) {
if (node.dirtyRender) {
this.canvasRenderBuffer.context.setTransform(canvasScaleX, 0, 0, canvasScaleY, 0, 0);
}
buffer.transform(1, 0, 0, 1, -x / canvasScaleX, -y / canvasScaleY);
}
node.dirtyRender = false;
};
网友评论