1- import AssetsLoader from "./assets" ;
2- import AudioManager from "./audio" ;
3- import { InputManager } from "./input" ;
4- import { IEntityTilemapLayerOptions , IEntityTransformOptions , IGameOptions , IMathObject , ISpriteRenderOptions , TilemapShape , YSortCallback } from "./interface" ;
5- import { MatrixStack , Vec2 } from "./math" ;
6- import Rapid from "./render" ;
7- import { TextureCache } from "./texture" ;
8- import { TileSet } from "./tilemap" ;
9- import { EasingFunction , Timer , Tween } from "./utils" ;
1+ import { default as AssetsLoader } from './assets' ;
2+ import { default as AudioManager } from './audio' ;
3+ import { InputManager } from './input' ;
4+ import { ICameraOptions , IEntityTransformOptions , IGameOptions , IMathObject } from './interface' ;
5+ import { MatrixStack , Vec2 } from './math' ;
6+ import { default as Rapid } from './render' ;
7+ import { TextureCache } from './texture' ;
8+ import { EasingFunction , Timer , Tween } from './utils' ;
109/**
1110 * Base class for game entities with transform and rendering capabilities.
1211 */
@@ -32,6 +31,7 @@ export declare class Entity {
3231 * @param options - Configuration options for position, scale, rotation, and tags.
3332 */
3433 constructor ( game : Game , options ?: IEntityTransformOptions ) ;
34+ getRoot ( ) : Scene | null ;
3535 /**
3636 * Gets the parent transform or the renderer's matrix stack if no parent exists.
3737 * @returns The transform matrix stack.
@@ -57,7 +57,7 @@ export declare class Entity {
5757 * Prepares the entity's transform before rendering.
5858 * @ignore
5959 */
60- beforOnRender ( ) : void ;
60+ beforeOnRender ( ) : void ;
6161 /**
6262 * Hook for custom rendering logic.
6363 * @param render - The rendering engine instance.
@@ -102,88 +102,42 @@ export declare class Entity {
102102 protected postDispose ( ) : void ;
103103}
104104/**
105- * Camera entity for managing the view transform in the game.
105+ * A layer that renders its children directly to the screen, ignoring any camera transforms.
106+ * Ideal for UI elements like HUDs, menus, and scores.
107+ *
108+ * CanvasLayer 是一个特殊的层,它会直接将其子节点渲染到屏幕上,忽略任何摄像机的变换。
109+ * 非常适合用于UI元素,如HUD(状态栏)、菜单和分数显示。
106110 */
107- export declare class Camera extends Entity {
108- /**
109- * Updates the camera's transform to center the view and apply transformations.
110- */
111+ export declare class CanvasLayer extends Entity {
112+ constructor ( game : Game ) ;
111113 updateTransform ( ) : void ;
112114}
113115/**
114- * Tilemap entity for rendering tiled maps .
116+ * Camera entity for managing the view transform in the game .
115117 */
116- export declare class Tilemap extends Entity {
117- static readonly DEFAULT_ERROR = 0 ;
118- static readonly EMPTY_TILE = - 1 ;
119- error : Vec2 ;
120- shape : TilemapShape ;
121- tileSet : TileSet ;
122- data : ( number | string ) [ ] [ ] ;
123- eachTile ?: ( tileId : string | number , mapX : number , mapY : number ) => ISpriteRenderOptions | undefined | void ;
124- ySortCallback : YSortCallback [ ] ;
125- /**
126- * Creates a tilemap entity.
127- * @param game - The game instance this tilemap belongs to.
128- * @param options - Configuration options for the tilemap.
129- */
130- constructor ( game : Game , options : IEntityTilemapLayerOptions ) ;
131- /**
132- * Collects renderable entities, excluding children unless they override onRender.
133- * @param queue - The array to collect renderable entities.
134- */
135- collectRenderables ( queue : Entity [ ] ) : void ;
136- /**
137- * Sets a tile at the specified map coordinates.
138- * @param x - The X coordinate (column) on the map.
139- * @param y - The Y coordinate (row) on the map.
140- * @param tileId - The tile ID to set (number or string).
141- * @returns True if the tile was set successfully, false if coordinates are out of bounds.
142- */
143- setTile ( x : number , y : number , tileId : number | string ) : boolean ;
144- /**
145- * Gets the tile ID at the specified map coordinates.
146- * @param x - The X coordinate (column) on the map.
147- * @param y - The Y coordinate (row) on the map.
148- * @returns The tile ID (number or string) or undefined if coordinates are out of bounds.
149- */
150- getTile ( x : number , y : number ) : number | string | undefined ;
151- /**
152- * Removes a tile at the specified map coordinates (sets it to EMPTY_TILE).
153- * @param x - The X coordinate (column) on the map.
154- * @param y - The Y coordinate (row) on the map.
155- * @returns True if the tile was removed successfully, false if coordinates are out of bounds.
156- */
157- removeTile ( x : number , y : number ) : boolean ;
158- /**
159- * Fills a rectangular area with a specified tile ID.
160- * @param tileId - The tile ID to use for filling.
161- * @param startX - The starting X coordinate.
162- * @param startY - The starting Y coordinate.
163- * @param width - The width of the fill area.
164- * @param height - The height of the fill area.
165- */
166- fill ( tileId : number | string , startX : number , startY : number , width : number , height : number ) : void ;
167- /**
168- * Replaces the entire tilemap data and updates dimensions.
169- * @param newData - The new 2D array of tile data.
170- */
171- setData ( newData : ( number | string ) [ ] [ ] ) : void ;
118+ export declare class Camera extends Entity {
119+ enable : boolean ;
120+ center : boolean ;
121+ positionSmoothingSpeed : number ;
122+ rotationSmoothingSpeed : number ;
123+ private _currentRenderPosition ;
124+ private _currentRenderRotation ;
172125 /**
173- * Converts local coordinates to map coordinates.
174- * @param local - The local coordinates to convert.
126+ * 设置此摄像机是否为当前场景的主摄像机。
127+ * @param isEnable
175128 */
176- localToMap ( local : Vec2 ) : void ;
129+ setEnable ( isEnable : boolean ) : void ;
130+ constructor ( game : Game , options ?: ICameraOptions ) ;
177131 /**
178- * Converts map coordinates to local coordinates.
179- * @param local - The map coordinates to convert.
132+ * 每帧更新,用于平滑摄像机的【局部】变换属性。
133+ * @param deltaTime
180134 */
181- mapToLocal ( local : Vec2 ) : void ;
135+ onUpdate ( deltaTime : number ) : void ;
182136 /**
183- * Renders the tilemap layer.
184- * @param render - The rendering engine instance.
137+ * 根据摄像机的【全局】变换计算最终的视图矩阵。
138+ * 这个方法现在正确地处理了父子关系。
185139 */
186- onRender ( render : Rapid ) : void ;
140+ updateTransform ( ) : void ;
187141}
188142/**
189143 * Scene class representing a game scene with entities.
@@ -208,12 +162,15 @@ export declare class Game {
208162 private lastTime ;
209163 private tweens ;
210164 private timers ;
165+ mainCamera : Camera | null ;
211166 renderQueue : Entity [ ] ;
212167 /**
213168 * Creates a new game instance.
214169 * @param options - Configuration options for the game.
215170 */
216171 constructor ( options : IGameOptions ) ;
172+ getMainScene ( ) : Scene | null ;
173+ setMainCamera ( camera : Camera | null ) : void ;
217174 /**
218175 * Switches to a new scene, disposing of the current one.
219176 * @param newScene - The new scene to switch to.
0 commit comments