mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2024-12-25 11:18:30 +00:00
[engine] 允许刚好符合动态图集尺寸的纹理加入动态图集,并修复动态图集 maxFrameSize 能设置为超出图集尺寸大小的问题
This commit is contained in:
parent
acfede9096
commit
5fae478d4d
@ -123,6 +123,7 @@ let dynamicAtlasManager = {
|
||||
return _maxFrameSize;
|
||||
},
|
||||
set maxFrameSize(value) {
|
||||
if (value > _textureSize) value = _textureSize;
|
||||
_maxFrameSize = value;
|
||||
},
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 插入子函数
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user