Skip to content

Commit

Permalink
export Atlas (#16902)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo authored Apr 16, 2024
1 parent 72c8487 commit 5666146
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cocos/2d/utils/dynamic-atlas/atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -52,7 +52,7 @@ export class Atlas {

this._x = space;
this._y = space;
this._nexty = space;
this._nextY = space;

this._innerTextureInfos = {};
this._innerSpriteFrames = [];
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions cocos/2d/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 5666146

Please sign in to comment.