From 5fae478d4d8396feab1c789cae93fe1cae20a606 Mon Sep 17 00:00:00 2001 From: SmallMain Date: Mon, 11 Jul 2022 21:49:21 +0800 Subject: [PATCH] =?UTF-8?q?[engine]=20=E5=85=81=E8=AE=B8=E5=88=9A=E5=A5=BD?= =?UTF-8?q?=E7=AC=A6=E5=90=88=E5=8A=A8=E6=80=81=E5=9B=BE=E9=9B=86=E5=B0=BA?= =?UTF-8?q?=E5=AF=B8=E7=9A=84=E7=BA=B9=E7=90=86=E5=8A=A0=E5=85=A5=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=9B=BE=E9=9B=86=EF=BC=8C=E5=B9=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=9B=BE=E9=9B=86=20maxFrameSize=20=E8=83=BD?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E8=B6=85=E5=87=BA=E5=9B=BE=E9=9B=86?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E5=A4=A7=E5=B0=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../renderer/utils/dynamic-atlas/manager.js | 1 + .../utils/dynamic-atlas/reusable-atlas.ts | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) 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; + } + + /** * 插入子函数 */