11import { default as AssetsLoader } from './assets' ;
22import { default as AudioManager } from './audio' ;
33import { InputManager } from './input' ;
4- import { ICameraOptions , IEntityTransformOptions , IGameOptions , IMathObject } from './interface' ;
5- import { MatrixStack , Vec2 } from './math' ;
4+ import { IAnimation , ICameraOptions , IEntityTransformOptions , IGameOptions , ILabelEntityOptions , IMathObject , ISpriteOptions } from './interface' ;
5+ import { Color , MatrixStack , Vec2 } from './math' ;
66import { default as Rapid } from './render' ;
7- import { TextureCache } from './texture' ;
7+ import { Text , Texture , TextureCache } from './texture' ;
88import { EasingFunction , Timer , Tween } from './utils' ;
99/**
1010 * Base class for game entities with transform and rendering capabilities.
@@ -31,7 +31,7 @@ export declare class Entity {
3131 * @param options - Configuration options for position, scale, rotation, and tags.
3232 */
3333 constructor ( game : Game , options ?: IEntityTransformOptions ) ;
34- getRoot ( ) : Scene | null ;
34+ getScene ( ) : Scene | null ;
3535 /**
3636 * Gets the parent transform or the renderer's matrix stack if no parent exists.
3737 * @returns The transform matrix stack.
@@ -100,6 +100,8 @@ export declare class Entity {
100100 * Hook for custom cleanup logic before disposal.
101101 */
102102 protected postDispose ( ) : void ;
103+ getMouseLocalPosition ( ) : Vec2 ;
104+ getMouseGlobalPosition ( ) : Vec2 ;
103105}
104106/**
105107 * A layer that renders its children directly to the screen, ignoring any camera transforms.
@@ -109,7 +111,7 @@ export declare class Entity {
109111 * 非常适合用于UI元素,如HUD(状态栏)、菜单和分数显示。
110112 */
111113export declare class CanvasLayer extends Entity {
112- constructor ( game : Game ) ;
114+ constructor ( game : Game , options : IEntityTransformOptions ) ;
113115 updateTransform ( ) : void ;
114116}
115117/**
@@ -164,6 +166,7 @@ export declare class Game {
164166 private timers ;
165167 mainCamera : Camera | null ;
166168 renderQueue : Entity [ ] ;
169+ worldTransform : MatrixStack ;
167170 /**
168171 * Creates a new game instance.
169172 * @param options - Configuration options for the game.
@@ -247,3 +250,75 @@ export declare class Game {
247250 */
248251 private updateTweens ;
249252}
253+ /**
254+ * An entity that displays a texture (a "sprite") and can play animations.
255+ * Animations are defined as a sequence of textures.
256+ */
257+ export declare class Sprite extends Entity {
258+ /** The current texture being displayed. This can be a static texture or a frame from an animation. */
259+ texture : Texture | null ;
260+ /** Whether the sprite is flipped horizontally. */
261+ flipX : boolean ;
262+ /** Whether the sprite is flipped vertically. */
263+ flipY : boolean ;
264+ color : Color ;
265+ offset : Vec2 ;
266+ private animations ;
267+ private currentAnimation ;
268+ private currentFrame ;
269+ private frameTimer ;
270+ private isPlaying ;
271+ /**
272+ * Creates a new Sprite entity.
273+ * @param game - The game instance.
274+ * @param options - Configuration for the sprite's transform and initial texture.
275+ */
276+ constructor ( game : Game , options ?: ISpriteOptions ) ;
277+ setAnimations ( animations : IAnimation ) : void ;
278+ /**
279+ * Defines a new animation sequence.
280+ * @param name - A unique name for the animation (e.g., "walk", "jump").
281+ * @param frames - An array of Textures to use as frames.
282+ * @param fps - The playback speed in frames per second.
283+ * @param loop - Whether the animation should repeat.
284+ */
285+ addAnimation ( name : string , frames : Texture [ ] , fps ?: number , loop ?: boolean ) : void ;
286+ /**
287+ * Plays an animation that has been previously defined with `addAnimation`.
288+ * @param name - The name of the animation to play.
289+ * @param forceRestart - If true, the animation will restart from the first frame even if it's already playing.
290+ */
291+ play ( name : string , forceRestart ?: boolean ) : void ;
292+ /**
293+ * Stops the currently playing animation.
294+ * The sprite will remain on the current frame.
295+ */
296+ stop ( ) : void ;
297+ /**
298+ * Updates the animation frame based on the elapsed time.
299+ * @param deltaTime - Time in seconds since the last frame.
300+ * @override
301+ */
302+ onUpdate ( deltaTime : number ) : void ;
303+ /**
304+ * Renders the sprite's current texture to the screen.
305+ * @param render - The Rapid rendering instance.
306+ * @override
307+ */
308+ onRender ( render : Rapid ) : void ;
309+ }
310+ /**
311+ * An entity designed specifically to display text on the screen.
312+ * It encapsulates a `Text` texture, giving it position, scale, rotation,
313+ * and other entity-based properties.
314+ */
315+ export declare class Label extends Entity {
316+ text : Text ;
317+ constructor ( game : Game , options : ILabelEntityOptions ) ;
318+ onRender ( render : Rapid ) : void ;
319+ /**
320+ * Updates the displayed text. Re-renders the texture if the text has changed.
321+ * @param text - The new text to display.
322+ */
323+ setText ( text : string ) : void ;
324+ }
0 commit comments