[engine] 允许刚好符合动态图集尺寸的纹理加入动态图集,并修复动态图集 maxFrameSize 能设置为超出图集尺寸大小的问题

This commit is contained in:
SmallMain 2022-07-11 21:49:21 +08:00
parent acfede9096
commit 5fae478d4d
2 changed files with 40 additions and 0 deletions

View File

@ -123,6 +123,7 @@ let dynamicAtlasManager = {
return _maxFrameSize; return _maxFrameSize;
}, },
set maxFrameSize(value) { set maxFrameSize(value) {
if (value > _textureSize) value = _textureSize;
_maxFrameSize = value; _maxFrameSize = value;
}, },

View File

@ -273,6 +273,13 @@ export class Atlas {
let sx = rect.x, sy = rect.y; let sx = rect.x, sy = rect.y;
let width = texture.width, height = texture.height; let width = texture.width, height = texture.height;
// 如果纹理与图集尺寸一致则使用直接插入逻辑
if (this.rootRect.used === 0
&& width > this.rootRect.width
&& height > this.rootRect.height) {
return this.insertSpriteFrameMax(spriteFrame);
}
const result = this.insert(texture); const result = this.insert(texture);
if (!result) { if (!result) {
@ -316,6 +323,38 @@ export class Atlas {
} }
/**
* SpriteFrame
*/
insertSpriteFrameMax(spriteFrame: any) {
const rect = spriteFrame._rect;
const texture = spriteFrame._texture;
const original = this.rootRect;
original.uuid = texture._uuid;
original.used++;
if (original.parentRect) original.parentRect.used++;
cc.dynamicAtlasManager.rects[texture._uuid] = original;
this.removeFreeRect(0);
this._texture.drawTextureAt(texture, 0, 0);
this._count++;
original.spriteFrames.push(spriteFrame);
this._dirty = true;
let frame = {
x: rect.x,
y: rect.y,
texture: this._texture,
};
return frame;
}
/** /**
* *
*/ */