From 56661467db61ebec2b47bf5795d3d3c3673266ca Mon Sep 17 00:00:00 2001 From: minggo Date: Tue, 16 Apr 2024 14:29:14 +0800 Subject: [PATCH] export Atlas (#16902) --- cocos/2d/utils/dynamic-atlas/atlas.ts | 20 ++++++++++---------- cocos/2d/utils/index.ts | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cocos/2d/utils/dynamic-atlas/atlas.ts b/cocos/2d/utils/dynamic-atlas/atlas.ts index cb1deade823..10ede680568 100644 --- a/cocos/2d/utils/dynamic-atlas/atlas.ts +++ b/cocos/2d/utils/dynamic-atlas/atlas.ts @@ -26,7 +26,7 @@ import { PixelFormat } from '../../../asset/assets/asset-enum'; import { ImageAsset } from '../../../asset/assets/image-asset'; import { Texture2D } from '../../../asset/assets/texture-2d'; import { BufferTextureCopy } from '../../../gfx'; -import { cclegacy } from '../../../core'; +import { cclegacy, warn } from '../../../core'; import { SpriteFrame } from '../../assets/sprite-frame'; const space = 2; @@ -37,12 +37,12 @@ export class Atlas { private _height: any; private _x: number; private _y: number; - private _nexty: number; + private _nextY: number; private _innerTextureInfos = {}; private _innerSpriteFrames: SpriteFrame[]; private _count: number; - constructor (width, height) { + constructor (width: number, height: number) { const texture = new DynamicAtlasTexture(); texture.initWithSize(width, height); this._texture = texture; @@ -52,7 +52,7 @@ export class Atlas { this._x = space; this._y = space; - this._nexty = space; + this._nextY = space; this._innerTextureInfos = {}; this._innerSpriteFrames = []; @@ -92,14 +92,14 @@ export class Atlas { if ((this._x + width + space) > this._width) { this._x = space; - this._y = this._nexty; + this._y = this._nextY; } - if ((this._y + height + space) > this._nexty) { - this._nexty = this._y + height + space; + if ((this._y + height + space) > this._nextY) { + this._nextY = this._y + height + space; } - if (this._nexty > this._height) { + if (this._nextY > this._height) { return null; } @@ -187,7 +187,7 @@ export class Atlas { public reset (): void { this._x = space; this._y = space; - this._nexty = space; + this._nextY = space; const frames = this._innerSpriteFrames; for (let i = 0, l = frames.length; i < l; i++) { @@ -254,7 +254,7 @@ export class DynamicAtlasTexture extends Texture2D { const gfxDevice = this._getGFXDevice(); if (!gfxDevice) { - console.warn('Unable to get device'); + warn('Unable to get device'); return; } diff --git a/cocos/2d/utils/index.ts b/cocos/2d/utils/index.ts index 9088895db8f..e52fbb36185 100644 --- a/cocos/2d/utils/index.ts +++ b/cocos/2d/utils/index.ts @@ -27,3 +27,4 @@ import './font-loader'; export * from './html-text-parser'; export * from './text-utils'; export * from './dynamic-atlas/atlas-manager'; +export { Atlas } from './dynamic-atlas/atlas';