diff --git a/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js b/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js index 1c2272d9..ecaf5558 100644 --- a/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js +++ b/engine/cocos2d/core/renderer/utils/dynamic-atlas/manager.js @@ -123,6 +123,7 @@ let dynamicAtlasManager = { return _maxFrameSize; }, set maxFrameSize(value) { + if (value > _textureSize) value = _textureSize; _maxFrameSize = value; }, diff --git a/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts b/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts index 9ba1adc9..76900799 100644 --- a/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts +++ b/engine/cocos2d/core/renderer/utils/dynamic-atlas/reusable-atlas.ts @@ -273,6 +273,13 @@ export class Atlas { let sx = rect.x, sy = rect.y; 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); 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; + } + + /** * 插入子函数 */