MCPcopy Create free account
hub / github.com/esengine/esengine / TilemapAnimationSystem

Class TilemapAnimationSystem

packages/tilemap/src/TilemapAnimationSystem.ts:26–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 * 瓦片地图动画系统
25 */
26export class TilemapAnimationSystem {
27 /** Animation states keyed by "tilesetIndex:tileId" | 按"图块集索引:瓦片ID"索引的动画状态 */
28 private animationStates: Map<string, TileAnimationState> = new Map();
29
30 /** Cached animated tile metadata for quick lookup | 缓存的动画瓦片元数据用于快速查找 */
31 private animatedTiles: Map<string, ITileMetadata> = new Map();
32
33 /** Whether animations are playing | 动画是否正在播放 */
34 private _isPlaying: boolean = true;
35
36 /**
37 * Register a tileset's animated tiles
38 * 注册图块集的动画瓦片
39 */
40 registerTileset(tilesetIndex: number, tileset: ITilesetData): void {
41 if (!tileset.tiles) return;
42
43 for (const tile of tileset.tiles) {
44 if (tile.animation && tile.animation.frames.length > 0) {
45 const key = `${tilesetIndex}:${tile.id}`;
46 this.animatedTiles.set(key, tile);
47 this.animationStates.set(key, {
48 currentFrame: 0,
49 elapsedTime: 0
50 });
51 }
52 }
53 }
54
55 /**
56 * Unregister a tileset
57 * 注销图块集
58 */
59 unregisterTileset(tilesetIndex: number): void {
60 const keysToRemove: string[] = [];
61 for (const key of this.animationStates.keys()) {
62 if (key.startsWith(`${tilesetIndex}:`)) {
63 keysToRemove.push(key);
64 }
65 }
66 for (const key of keysToRemove) {
67 this.animationStates.delete(key);
68 this.animatedTiles.delete(key);
69 }
70 }
71
72 /**
73 * Clear all animation states
74 * 清除所有动画状态
75 */
76 clear(): void {
77 this.animationStates.clear();
78 this.animatedTiles.clear();
79 }
80
81 /**
82 * Update all animations
83 * 更新所有动画

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected