emeraldengine 2.2.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2198 -968
- package/dist/types/index.d.ts +75 -32
- package/dist/types/src/Animator.d.ts +50 -0
- package/dist/types/{BitmapText.d.ts → src/BitmapText.d.ts} +19 -21
- package/dist/types/src/Camera.d.ts +122 -0
- package/dist/types/src/CameraController.d.ts +107 -0
- package/dist/types/src/CanvasText.d.ts +91 -0
- package/dist/types/src/CollisionLayers.d.ts +58 -0
- package/dist/types/{Color.d.ts → src/Color.d.ts} +6 -6
- package/dist/types/src/Coroutine.d.ts +111 -0
- package/dist/types/src/DebugOverlay.d.ts +86 -0
- package/dist/types/src/Drawable.d.ts +271 -0
- package/dist/types/src/Easing.d.ts +22 -0
- package/dist/types/src/Emerald.d.ts +420 -0
- package/dist/types/src/EmeraldDB.d.ts +159 -0
- package/dist/types/{FPSCounter.d.ts → src/FPSCounter.d.ts} +1 -3
- package/dist/types/src/GLUtils.d.ts +4 -0
- package/dist/types/{Instance.d.ts → src/Instance.d.ts} +37 -15
- package/dist/types/{InstancedTexture.d.ts → src/InstancedTexture.d.ts} +75 -23
- package/dist/types/src/Interpolator.d.ts +66 -0
- package/dist/types/src/Material.d.ts +87 -0
- package/dist/types/src/MathUtils.d.ts +81 -0
- package/dist/types/src/ParticleEmitter.d.ts +131 -0
- package/dist/types/src/Physics.d.ts +337 -0
- package/dist/types/src/Pool.d.ts +53 -0
- package/dist/types/src/PostEffects.d.ts +68 -0
- package/dist/types/src/PostProcessor.d.ts +124 -0
- package/dist/types/src/RenderTarget.d.ts +56 -0
- package/dist/types/src/Scene.d.ts +62 -0
- package/dist/types/src/ScreenEffects.d.ts +111 -0
- package/dist/types/src/Serializer.d.ts +86 -0
- package/dist/types/src/Shaders.d.ts +2 -0
- package/dist/types/{Shapes.d.ts → src/Shapes.d.ts} +4 -6
- package/dist/types/src/SpatialGrid.d.ts +50 -0
- package/dist/types/src/SpriteBatch.d.ts +89 -0
- package/dist/types/src/StateMachine.d.ts +59 -0
- package/dist/types/src/Storage.d.ts +89 -0
- package/dist/types/{Texture.d.ts → src/Texture.d.ts} +3 -4
- package/dist/types/src/TextureAtlas.d.ts +55 -0
- package/dist/types/src/Tilemap.d.ts +91 -0
- package/dist/types/src/Time.d.ts +53 -0
- package/dist/types/src/Timer.d.ts +54 -0
- package/dist/types/src/Transform.d.ts +94 -0
- package/dist/types/src/Tween.d.ts +81 -0
- package/dist/types/src/UI.d.ts +121 -0
- package/dist/types/src/components/Behaviour.d.ts +71 -0
- package/dist/types/{components → src/components}/BoxCollider.d.ts +14 -14
- package/dist/types/src/components/BoxColliderDebug.d.ts +15 -0
- package/dist/types/{components → src/components}/CircleCollider.d.ts +14 -12
- package/dist/types/src/components/CircleColliderDebug.d.ts +15 -0
- package/dist/types/src/components/Collider.d.ts +102 -0
- package/dist/types/src/components/GameObject.d.ts +135 -0
- package/dist/types/src/components/PolygonCollider.d.ts +33 -0
- package/dist/types/src/components/RigidBody.d.ts +456 -0
- package/dist/types/src/importers/Aseprite.d.ts +79 -0
- package/dist/types/src/importers/ForgeLevel.d.ts +97 -0
- package/dist/types/src/importers/TiledMap.d.ts +62 -0
- package/dist/types/{lights → src/lights}/DirectionalLight.d.ts +7 -9
- package/dist/types/{lights → src/lights}/PointLight.d.ts +6 -9
- package/dist/types/src/managers/AssetManager.d.ts +116 -0
- package/dist/types/src/managers/AudioManager.d.ts +259 -0
- package/dist/types/{managers → src/managers}/CameraManager.d.ts +8 -8
- package/dist/types/{managers → src/managers}/EventManager.d.ts +46 -32
- package/dist/types/src/managers/GLManager.d.ts +84 -0
- package/dist/types/src/managers/GLState.d.ts +37 -0
- package/dist/types/src/managers/Gamepad.d.ts +102 -0
- package/dist/types/src/managers/IDManager.d.ts +31 -0
- package/dist/types/src/managers/InputManager.d.ts +381 -0
- package/dist/types/src/managers/NetworkManager.d.ts +93 -0
- package/dist/types/src/managers/RenderStats.d.ts +34 -0
- package/dist/types/src/managers/SceneManager.d.ts +44 -0
- package/dist/types/src/managers/ShaderManager.d.ts +55 -0
- package/dist/types/src/managers/TextureManager.d.ts +102 -0
- package/dist/types/src/particlesystem/Particle.d.ts +64 -0
- package/dist/types/{particlesystem → src/particlesystem}/ParticleSettings.d.ts +32 -24
- package/dist/types/{particlesystem → src/particlesystem}/Particles.d.ts +20 -12
- package/dist/types/src/physics/AABB.d.ts +92 -0
- package/dist/types/src/physics/Body.d.ts +435 -0
- package/dist/types/src/physics/BodyType.d.ts +6 -0
- package/dist/types/src/physics/BroadPhase.d.ts +210 -0
- package/dist/types/src/physics/Collision.d.ts +102 -0
- package/dist/types/src/physics/Contact.d.ts +206 -0
- package/dist/types/src/physics/ContactSolver.d.ts +108 -0
- package/dist/types/src/physics/Distance.d.ts +54 -0
- package/dist/types/src/physics/DistanceJoint.d.ts +90 -0
- package/dist/types/src/physics/Fixture.d.ts +221 -0
- package/dist/types/src/physics/Island.d.ts +52 -0
- package/dist/types/src/physics/Joint.d.ts +59 -0
- package/dist/types/src/physics/Math2D.d.ts +371 -0
- package/dist/types/src/physics/RevoluteJoint.d.ts +119 -0
- package/dist/types/src/physics/Settings.d.ts +22 -0
- package/dist/types/src/physics/Shapes.d.ts +207 -0
- package/dist/types/src/physics/TimeOfImpact.d.ts +22 -0
- package/dist/types/src/physics/World.d.ts +274 -0
- package/dist/types/src/physics/index.d.ts +34 -0
- package/index.js +78 -0
- package/package.json +73 -60
- package/src/Animator.js +95 -0
- package/src/BitmapText.js +6 -5
- package/src/Camera.js +183 -0
- package/src/CameraController.js +192 -0
- package/src/CanvasText.js +281 -0
- package/src/CollisionLayers.js +86 -0
- package/src/Color.js +26 -18
- package/src/Coroutine.js +259 -0
- package/src/DebugOverlay.js +246 -0
- package/src/Drawable.js +842 -582
- package/src/Easing.js +57 -0
- package/src/Emerald.js +1150 -459
- package/src/EmeraldDB.js +328 -0
- package/src/FPSCounter.js +43 -43
- package/src/GLUtils.js +60 -67
- package/src/Instance.js +41 -5
- package/src/InstancedTexture.js +308 -127
- package/src/Interpolator.js +124 -0
- package/src/Material.js +202 -0
- package/src/MathUtils.js +134 -0
- package/src/ParticleEmitter.js +284 -0
- package/src/Physics.js +431 -40
- package/src/Pool.js +85 -0
- package/src/PostEffects.js +296 -0
- package/src/PostProcessor.js +304 -0
- package/src/RenderTarget.js +134 -0
- package/src/Scene.js +115 -83
- package/src/ScreenEffects.js +266 -0
- package/src/Serializer.js +131 -0
- package/src/Shaders.js +150 -165
- package/src/Shapes.js +118 -129
- package/src/SpatialGrid.js +111 -0
- package/src/SpriteBatch.js +299 -0
- package/src/StateMachine.js +82 -0
- package/src/Storage.js +175 -47
- package/src/Texture.js +58 -67
- package/src/TextureAtlas.js +96 -0
- package/src/Tilemap.js +274 -0
- package/src/Time.js +51 -6
- package/src/Timer.js +99 -0
- package/src/Transform.js +100 -7
- package/src/Tween.js +160 -0
- package/src/UI.js +394 -0
- package/src/components/Behaviour.js +90 -0
- package/src/components/BoxCollider.js +29 -12
- package/src/components/BoxColliderDebug.js +3 -4
- package/src/components/CircleCollider.js +26 -12
- package/src/components/CircleColliderDebug.js +25 -24
- package/src/components/Collider.js +150 -34
- package/src/components/GameObject.js +130 -21
- package/src/components/PolygonCollider.js +55 -0
- package/src/components/RigidBody.js +556 -8
- package/src/importers/Aseprite.js +142 -0
- package/src/importers/ForgeLevel.js +581 -0
- package/src/importers/TiledMap.js +158 -0
- package/src/lights/DirectionalLight.js +6 -15
- package/src/lights/PointLight.js +4 -4
- package/src/managers/AssetManager.js +239 -0
- package/src/managers/AudioManager.js +565 -146
- package/src/managers/EventManager.js +488 -477
- package/src/managers/GLManager.js +57 -0
- package/src/managers/GLState.js +70 -0
- package/src/managers/Gamepad.js +126 -0
- package/src/managers/IDManager.js +24 -2
- package/src/managers/InputManager.js +905 -0
- package/src/managers/NetworkManager.js +178 -0
- package/src/managers/RenderStats.js +34 -0
- package/src/managers/SceneManager.js +30 -0
- package/src/managers/ShaderManager.js +0 -2
- package/src/managers/TextureManager.js +218 -0
- package/src/particlesystem/Particle.js +82 -7
- package/src/particlesystem/ParticleSettings.js +21 -3
- package/src/particlesystem/Particles.js +80 -31
- package/src/physics/AABB.js +207 -0
- package/src/physics/Body.js +862 -0
- package/src/physics/BodyType.js +16 -0
- package/src/physics/BroadPhase.js +641 -0
- package/src/physics/Collision.js +534 -0
- package/src/physics/Contact.js +500 -0
- package/src/physics/ContactSolver.js +526 -0
- package/src/physics/Distance.js +403 -0
- package/src/physics/DistanceJoint.js +227 -0
- package/src/physics/Fixture.js +346 -0
- package/src/physics/Island.js +203 -0
- package/src/physics/Joint.js +78 -0
- package/src/physics/Math2D.js +573 -0
- package/src/physics/RevoluteJoint.js +278 -0
- package/src/physics/Settings.js +78 -0
- package/src/physics/Shapes.js +549 -0
- package/src/physics/TimeOfImpact.js +87 -0
- package/src/physics/World.js +731 -0
- package/src/physics/index.js +79 -0
- package/dist/types/Drawable.d.ts +0 -157
- package/dist/types/Emerald.d.ts +0 -73
- package/dist/types/GLUtils.d.ts +0 -6
- package/dist/types/Physics.d.ts +0 -139
- package/dist/types/Scene.d.ts +0 -39
- package/dist/types/Shaders.d.ts +0 -4
- package/dist/types/Storage.d.ts +0 -46
- package/dist/types/Time.d.ts +0 -22
- package/dist/types/Transform.d.ts +0 -41
- package/dist/types/components/BoxColliderDebug.d.ts +0 -19
- package/dist/types/components/CircleColliderDebug.d.ts +0 -19
- package/dist/types/components/Collider.d.ts +0 -53
- package/dist/types/components/GameObject.d.ts +0 -72
- package/dist/types/components/RigidBody.d.ts +0 -104
- package/dist/types/managers/AudioManager.d.ts +0 -60
- package/dist/types/managers/GLManager.d.ts +0 -47
- package/dist/types/managers/IDManager.d.ts +0 -21
- package/dist/types/managers/SceneManager.d.ts +0 -22
- package/dist/types/particlesystem/Particle.d.ts +0 -42
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default Scene;
|
|
2
|
+
/**
|
|
3
|
+
* @class Scene
|
|
4
|
+
* @description Represents a scene
|
|
5
|
+
* @param {Array} objects - The objects in the scene
|
|
6
|
+
*/
|
|
7
|
+
declare class Scene {
|
|
8
|
+
constructor(objects?: any[]);
|
|
9
|
+
objects: any[];
|
|
10
|
+
/**
|
|
11
|
+
* @method add
|
|
12
|
+
* @description Adds an object to the scene
|
|
13
|
+
* @param {GameObject} object - The object to add
|
|
14
|
+
*/
|
|
15
|
+
add(object: GameObject): void;
|
|
16
|
+
/**
|
|
17
|
+
* @method remove
|
|
18
|
+
* @description Removes an object from the scene. By default the object's GPU
|
|
19
|
+
* resources stay alive so it can be re-added later; pass { dispose: true }
|
|
20
|
+
* to also destroy it (free GL buffers/textures, physics bodies) when it is
|
|
21
|
+
* being removed for good.
|
|
22
|
+
* @param {GameObject} object - The object to remove
|
|
23
|
+
* @param {Object} [options] - { dispose = false }
|
|
24
|
+
*/
|
|
25
|
+
remove(object: GameObject, options?: any): void;
|
|
26
|
+
/**
|
|
27
|
+
* @method dispose
|
|
28
|
+
* @description Destroys every object in the scene (freeing their GPU
|
|
29
|
+
* resources and physics bodies) and empties it. Call when a level/screen is
|
|
30
|
+
* torn down for good; removing objects without disposing leaks GL buffers
|
|
31
|
+
* over repeated scene swaps.
|
|
32
|
+
*/
|
|
33
|
+
dispose(): void;
|
|
34
|
+
/**
|
|
35
|
+
* @method update
|
|
36
|
+
* @description Ticks every active object's component lifecycle. Call once per
|
|
37
|
+
* frame (before or after drawScene) to drive Behaviour components.
|
|
38
|
+
* @param {number} deltaTime - Seconds since the previous frame
|
|
39
|
+
*/
|
|
40
|
+
update(deltaTime: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* @method setIsActive
|
|
43
|
+
* @description Sets the active state of the scene
|
|
44
|
+
* @param {boolean} bool - The active state
|
|
45
|
+
*/
|
|
46
|
+
setIsActive(bool: boolean): void;
|
|
47
|
+
/**
|
|
48
|
+
* @method setActiveRecursive
|
|
49
|
+
* @description Sets the active state of the scene recursively
|
|
50
|
+
* @param {Object} object - The object to set the active state of
|
|
51
|
+
* @param {boolean} bool - The active state
|
|
52
|
+
*/
|
|
53
|
+
setActiveRecursive(object: any, bool: boolean): void;
|
|
54
|
+
forEach(callback: any): void;
|
|
55
|
+
[Symbol.iterator](): {
|
|
56
|
+
next: () => {
|
|
57
|
+
value: any;
|
|
58
|
+
done: boolean;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
import GameObject from "./components/GameObject.js";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export default ScreenEffects;
|
|
2
|
+
/**
|
|
3
|
+
* @class ScreenEffects
|
|
4
|
+
* @description In-engine full-screen camera/transition effects: fade to/from a
|
|
5
|
+
* color, screen flash, and cinematic letterbox bars. Everything is drawn with
|
|
6
|
+
* the engine's own screen-space quads (no DOM/CSS overlay), so it survives
|
|
7
|
+
* resolution changes, post-processing, and split-screen (the quads overfill
|
|
8
|
+
* every viewport and are clipped per camera).
|
|
9
|
+
*
|
|
10
|
+
* Add it to your scene's update loop by calling `update(dt)` each frame.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const fx = new ScreenEffects(scene, { layer: 100000 });
|
|
14
|
+
* await fx.fadeOut(0.4, new Color(0,0,0,255)); // to black
|
|
15
|
+
* loadNextLevel();
|
|
16
|
+
* await fx.fadeIn(0.4);
|
|
17
|
+
* // bumps:
|
|
18
|
+
* fx.flash(new Color(255,255,255,255), 0.15);
|
|
19
|
+
* // in the loop, before drawScene: fx.update(dt);
|
|
20
|
+
*/
|
|
21
|
+
declare class ScreenEffects {
|
|
22
|
+
/**
|
|
23
|
+
* @param {Scene} scene - The scene to draw the overlays into
|
|
24
|
+
* @param {Object} [options] - { layer = 100000, size = 5000 }
|
|
25
|
+
*/
|
|
26
|
+
constructor(scene: Scene, options?: any);
|
|
27
|
+
scene: Scene;
|
|
28
|
+
/** @private */
|
|
29
|
+
private _fade;
|
|
30
|
+
/** @private */
|
|
31
|
+
private _flashQuad;
|
|
32
|
+
/** @private */
|
|
33
|
+
private _barTop;
|
|
34
|
+
/** @private */
|
|
35
|
+
private _barBottom;
|
|
36
|
+
/** @private */
|
|
37
|
+
private _letterboxHeight;
|
|
38
|
+
/** @private */
|
|
39
|
+
private _letterboxTarget;
|
|
40
|
+
/** @private */
|
|
41
|
+
private _barHalf;
|
|
42
|
+
/** @private */
|
|
43
|
+
private _fadeAnim;
|
|
44
|
+
/** @private */
|
|
45
|
+
private _flashAnim;
|
|
46
|
+
/** @private */
|
|
47
|
+
private _makeQuad;
|
|
48
|
+
/** @private */
|
|
49
|
+
private _shapeOf;
|
|
50
|
+
/** @private */
|
|
51
|
+
private _setColor;
|
|
52
|
+
/**
|
|
53
|
+
* @method fadeOut
|
|
54
|
+
* @description Fades the screen to a solid color (opacity 0 -> 1).
|
|
55
|
+
* @param {number} duration - Seconds
|
|
56
|
+
* @param {Color} [color] - Target color (default black)
|
|
57
|
+
* @param {Function} [easing] - Easing function (default linear)
|
|
58
|
+
* @returns {Promise<void>} - Resolves when the fade completes
|
|
59
|
+
*/
|
|
60
|
+
fadeOut(duration?: number, color?: Color, easing?: Function): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* @method fadeIn
|
|
63
|
+
* @description Fades the screen back in from the current overlay (opacity -> 0).
|
|
64
|
+
* @param {number} duration - Seconds
|
|
65
|
+
* @param {Function} [easing] - Easing function (default linear)
|
|
66
|
+
* @returns {Promise<void>}
|
|
67
|
+
*/
|
|
68
|
+
fadeIn(duration?: number, easing?: Function): Promise<void>;
|
|
69
|
+
/** @private */
|
|
70
|
+
private _startFade;
|
|
71
|
+
/**
|
|
72
|
+
* @method flash
|
|
73
|
+
* @description Flashes a color that ramps to full then fades out.
|
|
74
|
+
* @param {Color} [color] - Flash color (default white)
|
|
75
|
+
* @param {number} duration - Total seconds for the flash
|
|
76
|
+
* @returns {Promise<void>}
|
|
77
|
+
*/
|
|
78
|
+
flash(color?: Color, duration?: number): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* @method transition
|
|
81
|
+
* @description Fades the screen out to a color, runs a swap callback at the
|
|
82
|
+
* darkest point (e.g. tear down the old scene and build the new one), then
|
|
83
|
+
* fades back in. Requires `update(dt)` to be pumped each frame by your loop.
|
|
84
|
+
* @param {Function} swap - Called (and awaited) while the screen is covered
|
|
85
|
+
* @param {Object} [options] - { duration = 0.4, color = black, outDuration,
|
|
86
|
+
* inDuration, easing }
|
|
87
|
+
* @returns {Promise<void>} - Resolves after the fade-in completes
|
|
88
|
+
*/
|
|
89
|
+
transition(swap: Function, options?: any): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* @method setLetterbox
|
|
92
|
+
* @description Animates cinematic black bars to the given height (in pixels,
|
|
93
|
+
* per bar). Pass 0 to retract them.
|
|
94
|
+
* @param {number} heightPx - Target bar height in pixels
|
|
95
|
+
*/
|
|
96
|
+
setLetterbox(heightPx: number): void;
|
|
97
|
+
/**
|
|
98
|
+
* @method update
|
|
99
|
+
* @description Advances all active transitions. Call once per frame.
|
|
100
|
+
* @param {number} dt - Seconds since last frame
|
|
101
|
+
*/
|
|
102
|
+
update(dt: number): void;
|
|
103
|
+
/** @private */
|
|
104
|
+
private _screenHalfHeight;
|
|
105
|
+
/**
|
|
106
|
+
* @method destroy
|
|
107
|
+
* @description Removes all overlay objects from the scene.
|
|
108
|
+
*/
|
|
109
|
+
destroy(): void;
|
|
110
|
+
}
|
|
111
|
+
import Color from "./Color.js";
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export default Serializer;
|
|
2
|
+
/**
|
|
3
|
+
* @class Serializer
|
|
4
|
+
* @description Saves/loads a scene to/from plain JSON. Because components hold
|
|
5
|
+
* live GL/physics handles that can't be serialized generically, reconstruction
|
|
6
|
+
* goes through registered factories keyed by a `prefabType`. Each object's
|
|
7
|
+
* transform, layer, opacity and an optional `serialize()` payload are captured.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* Serializer.register("coin", (data) => makeCoin(data.value));
|
|
11
|
+
* coin.prefabType = "coin";
|
|
12
|
+
* coin.serialize = () => ({ value: 5 });
|
|
13
|
+
*
|
|
14
|
+
* const json = Serializer.toJSON(scene); // save
|
|
15
|
+
* Serializer.fromJSON(json, new Scene()); // load
|
|
16
|
+
*/
|
|
17
|
+
declare class Serializer {
|
|
18
|
+
/**
|
|
19
|
+
* @method register
|
|
20
|
+
* @description Registers a factory that rebuilds an object from its data.
|
|
21
|
+
* @param {string} type - The prefabType
|
|
22
|
+
* @param {(data:any, entry:any) => Object} factory - Returns a GameObject
|
|
23
|
+
*/
|
|
24
|
+
static register(type: string, factory: (data: any, entry: any) => any): void;
|
|
25
|
+
/**
|
|
26
|
+
* @method serializeObject
|
|
27
|
+
* @description Captures a single object's serializable state.
|
|
28
|
+
*/
|
|
29
|
+
static serializeObject(obj: any): {
|
|
30
|
+
type: any;
|
|
31
|
+
name: any;
|
|
32
|
+
layer: any;
|
|
33
|
+
opacity: any;
|
|
34
|
+
screenSpace: boolean;
|
|
35
|
+
transform: {
|
|
36
|
+
position: {
|
|
37
|
+
x: any;
|
|
38
|
+
y: any;
|
|
39
|
+
z: any;
|
|
40
|
+
};
|
|
41
|
+
rotation: any;
|
|
42
|
+
scale: {
|
|
43
|
+
x: any;
|
|
44
|
+
y: any;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
data: any;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* @method serializeScene
|
|
51
|
+
* @description Returns a plain object describing the scene.
|
|
52
|
+
*/
|
|
53
|
+
static serializeScene(scene: any): {
|
|
54
|
+
objects: any;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* @method applyState
|
|
58
|
+
* @description Applies a serialized entry's transform/layer/opacity to an object.
|
|
59
|
+
*/
|
|
60
|
+
static applyState(obj: any, entry: any): void;
|
|
61
|
+
/**
|
|
62
|
+
* @method deserializeObject
|
|
63
|
+
* @description Rebuilds an object from an entry via its registered factory.
|
|
64
|
+
* @returns {Object|null}
|
|
65
|
+
*/
|
|
66
|
+
static deserializeObject(entry: any): any | null;
|
|
67
|
+
/**
|
|
68
|
+
* @method deserializeScene
|
|
69
|
+
* @description Rebuilds objects into the given scene.
|
|
70
|
+
* @returns {Scene} - The populated scene
|
|
71
|
+
*/
|
|
72
|
+
static deserializeScene(json: any, scene: any): Scene;
|
|
73
|
+
/**
|
|
74
|
+
* @method toJSON
|
|
75
|
+
* @description Serializes a scene to a JSON string.
|
|
76
|
+
*/
|
|
77
|
+
static toJSON(scene: any): string;
|
|
78
|
+
/**
|
|
79
|
+
* @method fromJSON
|
|
80
|
+
* @description Loads a scene from a JSON string into the given scene.
|
|
81
|
+
*/
|
|
82
|
+
static fromJSON(str: any, scene: any): Scene;
|
|
83
|
+
}
|
|
84
|
+
declare namespace Serializer {
|
|
85
|
+
let factories: Map<any, any>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const STANDARD_VERTEX_SHADER: "\n attribute vec4 aVertexPosition;\n attribute vec2 aTextureCoord;\n\n attribute vec4 aInstanceMatrix0;\n attribute vec4 aInstanceMatrix1;\n attribute vec4 aInstanceMatrix2;\n attribute vec4 aInstanceMatrix3;\n\n attribute vec2 aInstanceTexCoord0;\n attribute vec2 aInstanceTexCoord1;\n attribute vec2 aInstanceTexCoord2;\n attribute vec2 aInstanceTexCoord3;\n\n attribute vec4 aInstanceColor;\n\n uniform mat4 uModelViewMatrix;\n uniform mat4 uInstancedModelViewMatrix;\n uniform mat4 uProjectionMatrix;\n uniform bool useInstances;\n\n varying highp vec2 vTexCoord;\n varying vec2 vFragPos;\n varying vec4 vInstanceColor;\n\n void main() {\n mat4 instanceMatrix = mat4(\n aInstanceMatrix0,\n aInstanceMatrix1,\n aInstanceMatrix2,\n aInstanceMatrix3\n );\n\n if(useInstances) {\n gl_Position = uProjectionMatrix * uInstancedModelViewMatrix * instanceMatrix * aVertexPosition;\n vFragPos = (uInstancedModelViewMatrix * instanceMatrix * aVertexPosition).xy;\n vInstanceColor = aInstanceColor;\n\n int vertexIndex = int(aVertexPosition.x > 0.0 ? (aVertexPosition.y > 0.0 ? 0 : 2) : (aVertexPosition.y > 0.0 ? 1 : 3));\n\n if(vertexIndex == 0) {\n vTexCoord = aInstanceTexCoord0;\n } else if(vertexIndex == 1) {\n vTexCoord = aInstanceTexCoord1;\n } else if(vertexIndex == 2) {\n vTexCoord = aInstanceTexCoord2;\n } else {\n vTexCoord = aInstanceTexCoord3;\n }\n } else {\n gl_Position = uProjectionMatrix * uModelViewMatrix * aVertexPosition;\n vFragPos = (uModelViewMatrix * aVertexPosition).xy;\n vTexCoord = aTextureCoord;\n vInstanceColor = vec4(1.0);\n }\n }\n";
|
|
2
|
+
export const STANDARD_FRAGMENT_SHADER: "\n #ifdef GL_ES\n precision highp float;\n #endif\n uniform bool useTexture;\n uniform vec4 uColor;\n uniform sampler2D uSampler;\n uniform float uOpacity;\n\n uniform vec2 uLightPosition[4];\n uniform vec3 uLightColor[4];\n uniform float uLightIntensity[4];\n uniform float uLightRadius[4];\n uniform int uActiveLights;\n\n uniform vec2 uDirLightPosition[4];\n uniform vec2 uDirLightDirection[4];\n uniform vec3 uDirLightColor[4];\n uniform float uDirLightIntensity[4];\n uniform float uDirLightWidth[4];\n uniform int uActiveDirLights;\n\n uniform vec3 uAmbientLightValues;\n uniform bool uUseLighting;\n\n varying vec2 vTexCoord;\n varying vec2 vFragPos;\n varying vec4 vInstanceColor;\n\n void main() {\n vec4 ambientLight = vec4(uAmbientLightValues.xyz, 1.0);\n\n vec4 texColor;\n if (useTexture) {\n texColor = texture2D(uSampler, vTexCoord);\n if (texColor.a < 0.01) discard;\n texColor *= uColor;\n } else {\n texColor = uColor;\n }\n\n texColor *= vInstanceColor;\n\n vec3 lighting = ambientLight.rgb;\n\n for(int i = 0; i < 4; i++) {\n if(i >= uActiveLights) break;\n\n float distance = length(uLightPosition[i] - vFragPos);\n\n if(distance < uLightRadius[i]) {\n float attenuation = 1.0 - distance / uLightRadius[i];\n\n lighting += uLightColor[i] * attenuation * uLightIntensity[i];\n }\n }\n\n for(int i = 0; i < 4; i++) {\n if(i >= uActiveDirLights) break;\n\n vec2 lightPos = uDirLightPosition[i];\n vec2 lightDir = normalize(uDirLightDirection[i]);\n vec2 toFrag = vFragPos - lightPos;\n\n float projection = dot(toFrag, lightDir);\n if(projection < 0.0) continue;\n\n float perpDistance = abs(dot(toFrag, vec2(-lightDir.y, lightDir.x)));\n\n if(perpDistance > uDirLightWidth[i] * 0.5) continue;\n\n float widthFactor = 1.0 - (perpDistance / (uDirLightWidth[i] * 0.5));\n\n float distance = length(toFrag);\n float maxDistance = 1000.0;\n float distanceFactor = max(0.0, 1.0 - (distance / maxDistance));\n\n lighting += uDirLightColor[i] * uDirLightIntensity[i] * widthFactor * distanceFactor;\n }\n\n vec4 outColor;\n if (uUseLighting) {\n outColor = vec4(texColor.rgb * lighting, texColor.a);\n } else {\n outColor = texColor;\n }\n outColor.a *= clamp(uOpacity, 0.0, 1.0);\n gl_FragColor = outColor;\n }\n";
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import Drawable from "./Drawable";
|
|
2
1
|
/**
|
|
3
2
|
* @class Square2D
|
|
4
3
|
* @description Represents a square 2D shape
|
|
5
4
|
*/
|
|
6
|
-
|
|
5
|
+
export class Square2D extends Drawable {
|
|
7
6
|
constructor();
|
|
8
7
|
}
|
|
9
8
|
/**
|
|
10
9
|
* @class Triangle2D
|
|
11
10
|
* @description Represents a triangle 2D shape
|
|
12
11
|
*/
|
|
13
|
-
|
|
12
|
+
export class Triangle2D extends Drawable {
|
|
14
13
|
constructor();
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
@@ -18,8 +17,7 @@ declare class Triangle2D extends Drawable {
|
|
|
18
17
|
* @description Represents a circle 2D shape
|
|
19
18
|
* @param {number} segments - The number of segments to use to draw the circle
|
|
20
19
|
*/
|
|
21
|
-
|
|
20
|
+
export class Circle2D extends Drawable {
|
|
22
21
|
constructor(segments?: number);
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=Shapes.d.ts.map
|
|
23
|
+
import Drawable from "./Drawable.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export default SpatialGrid;
|
|
2
|
+
/**
|
|
3
|
+
* @class SpatialGrid
|
|
4
|
+
* @description A uniform spatial hash grid for fast 2D neighbor queries (picking,
|
|
5
|
+
* proximity, broadphase). Rebuild it each frame (or as objects move) with
|
|
6
|
+
* clear()/insert(), then query by radius or rectangle.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const grid = new SpatialGrid(64);
|
|
10
|
+
* grid.clear();
|
|
11
|
+
* for (const e of enemies) grid.insert(e, e.transform.position.x, e.transform.position.y);
|
|
12
|
+
* const near = grid.queryRadius(player.x, player.y, 100);
|
|
13
|
+
*/
|
|
14
|
+
declare class SpatialGrid {
|
|
15
|
+
/**
|
|
16
|
+
* @param {number} cellSize - World units per cell
|
|
17
|
+
*/
|
|
18
|
+
constructor(cellSize?: number);
|
|
19
|
+
cellSize: number;
|
|
20
|
+
cells: Map<any, any>;
|
|
21
|
+
/** @private */
|
|
22
|
+
private _key;
|
|
23
|
+
/** @private */
|
|
24
|
+
private _cell;
|
|
25
|
+
/**
|
|
26
|
+
* @method clear
|
|
27
|
+
* @description Empties the grid.
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
/**
|
|
31
|
+
* @method insert
|
|
32
|
+
* @description Inserts an item at a world position.
|
|
33
|
+
* @param {*} item - The item to store
|
|
34
|
+
* @param {number} x - World x
|
|
35
|
+
* @param {number} y - World y
|
|
36
|
+
*/
|
|
37
|
+
insert(item: any, x: number, y: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* @method queryRect
|
|
40
|
+
* @description Returns items whose stored position lies within a rectangle.
|
|
41
|
+
* @returns {Array} - Matching items
|
|
42
|
+
*/
|
|
43
|
+
queryRect(minX: any, minY: any, maxX: any, maxY: any): any[];
|
|
44
|
+
/**
|
|
45
|
+
* @method queryRadius
|
|
46
|
+
* @description Returns items within a radius of a point.
|
|
47
|
+
* @returns {Array} - Matching items
|
|
48
|
+
*/
|
|
49
|
+
queryRadius(x: any, y: any, radius: any): any[];
|
|
50
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export default SpriteBatch;
|
|
2
|
+
/**
|
|
3
|
+
* @class SpriteBatch
|
|
4
|
+
* @description A dynamic batched sprite renderer. Instead of one draw call per
|
|
5
|
+
* sprite (as ordinary Drawables incur), it accumulates many sprites that share a
|
|
6
|
+
* texture into a single interleaved buffer and submits them in one
|
|
7
|
+
* `drawElements` call. Batches are flushed automatically when the texture
|
|
8
|
+
* changes or the buffer fills, so for content that shares a texture/atlas this
|
|
9
|
+
* collapses hundreds of draw calls into a handful.
|
|
10
|
+
*
|
|
11
|
+
* It uses its own minimal shader program (position + uv + per-vertex color), so
|
|
12
|
+
* it is independent of the main render pipeline.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const batch = new SpriteBatch();
|
|
16
|
+
* batch.begin(projectionMatrix, viewMatrix); // gl-matrix mat4s
|
|
17
|
+
* for (const e of entities) {
|
|
18
|
+
* batch.draw({ texture: atlasTex, x: e.x, y: e.y, w: 32, h: 32,
|
|
19
|
+
* u0: e.u0, v0: e.v0, u1: e.u1, v1: e.v1 });
|
|
20
|
+
* }
|
|
21
|
+
* batch.end();
|
|
22
|
+
*/
|
|
23
|
+
declare class SpriteBatch {
|
|
24
|
+
/**
|
|
25
|
+
* @method _writeQuad
|
|
26
|
+
* @description Pure helper that writes one quad's 4 interleaved vertices
|
|
27
|
+
* (position, uv, color) into `out` at `offset`. Positions are rotated around
|
|
28
|
+
* the quad center (cx, cy). Exposed (and side-effect free) for testing.
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private static _writeQuad;
|
|
32
|
+
/**
|
|
33
|
+
* @param {Object} [options] - { maxQuads = 2000 }
|
|
34
|
+
*/
|
|
35
|
+
constructor(options?: any);
|
|
36
|
+
gl: WebGLRenderingContext;
|
|
37
|
+
maxQuads: any;
|
|
38
|
+
program: any;
|
|
39
|
+
attribs: {
|
|
40
|
+
pos: number;
|
|
41
|
+
uv: number;
|
|
42
|
+
color: number;
|
|
43
|
+
};
|
|
44
|
+
uniforms: {
|
|
45
|
+
projection: WebGLUniformLocation;
|
|
46
|
+
view: WebGLUniformLocation;
|
|
47
|
+
sampler: WebGLUniformLocation;
|
|
48
|
+
};
|
|
49
|
+
vertexData: Float32Array<ArrayBuffer>;
|
|
50
|
+
vertexBuffer: WebGLBuffer;
|
|
51
|
+
indexBuffer: WebGLBuffer;
|
|
52
|
+
/** @private */
|
|
53
|
+
private _quadCount;
|
|
54
|
+
/** @private */
|
|
55
|
+
private _currentTexture;
|
|
56
|
+
/** @private */
|
|
57
|
+
private _projection;
|
|
58
|
+
/** @private */
|
|
59
|
+
private _view;
|
|
60
|
+
drawCalls: number;
|
|
61
|
+
/**
|
|
62
|
+
* @method begin
|
|
63
|
+
* @description Starts a batch with the given projection and view matrices
|
|
64
|
+
* (gl-matrix mat4 / Float32Array(16)).
|
|
65
|
+
*/
|
|
66
|
+
begin(projectionMatrix: any, viewMatrix: any): void;
|
|
67
|
+
/**
|
|
68
|
+
* @method draw
|
|
69
|
+
* @description Queues one sprite. Flushes first if the texture changed or the
|
|
70
|
+
* batch is full.
|
|
71
|
+
* @param {Object} sprite - {
|
|
72
|
+
* texture, x, y, w, h,
|
|
73
|
+
* rotation = 0, originX = 0.5, originY = 0.5,
|
|
74
|
+
* u0 = 0, v0 = 0, u1 = 1, v1 = 1,
|
|
75
|
+
* r = 1, g = 1, b = 1, a = 1
|
|
76
|
+
* }
|
|
77
|
+
*/
|
|
78
|
+
draw(sprite: any): void;
|
|
79
|
+
/**
|
|
80
|
+
* @method end
|
|
81
|
+
* @description Flushes any remaining sprites.
|
|
82
|
+
*/
|
|
83
|
+
end(): void;
|
|
84
|
+
/**
|
|
85
|
+
* @method flush
|
|
86
|
+
* @description Uploads and draws the currently staged quads.
|
|
87
|
+
*/
|
|
88
|
+
flush(): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export default StateMachine;
|
|
2
|
+
/**
|
|
3
|
+
* @class StateMachine
|
|
4
|
+
* @description A lightweight finite state machine for entity AI, animation
|
|
5
|
+
* states, game flow, etc. Each state can define `enter`, `update(dt)`, and
|
|
6
|
+
* `exit` handlers. Drive it from a Behaviour's update().
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const fsm = new StateMachine();
|
|
10
|
+
* fsm.add("idle", {
|
|
11
|
+
* update: (dt, sm) => { if (seesPlayer) sm.set("chase"); },
|
|
12
|
+
* });
|
|
13
|
+
* fsm.add("chase", {
|
|
14
|
+
* enter: () => playRoarSound(),
|
|
15
|
+
* update: (dt, sm) => moveTowardPlayer(dt),
|
|
16
|
+
* });
|
|
17
|
+
* fsm.set("idle");
|
|
18
|
+
* // in update(dt): fsm.update(dt);
|
|
19
|
+
*/
|
|
20
|
+
declare class StateMachine {
|
|
21
|
+
states: Map<any, any>;
|
|
22
|
+
current: any;
|
|
23
|
+
currentName: any;
|
|
24
|
+
previousName: any;
|
|
25
|
+
/**
|
|
26
|
+
* @method add
|
|
27
|
+
* @description Registers a state.
|
|
28
|
+
* @param {string} name - State name
|
|
29
|
+
* @param {{enter?:Function, update?:Function, exit?:Function}} handlers
|
|
30
|
+
* @returns {StateMachine} - this
|
|
31
|
+
*/
|
|
32
|
+
add(name: string, handlers: {
|
|
33
|
+
enter?: Function;
|
|
34
|
+
update?: Function;
|
|
35
|
+
exit?: Function;
|
|
36
|
+
}): StateMachine;
|
|
37
|
+
/**
|
|
38
|
+
* @method set
|
|
39
|
+
* @description Transitions to a state, running exit/enter handlers. Re-entering
|
|
40
|
+
* the same state is a no-op unless `force` is true.
|
|
41
|
+
* @param {string} name - Target state name
|
|
42
|
+
* @param {boolean} [force] - Allow re-entering the current state
|
|
43
|
+
* @returns {StateMachine} - this
|
|
44
|
+
*/
|
|
45
|
+
set(name: string, force?: boolean): StateMachine;
|
|
46
|
+
/**
|
|
47
|
+
* @method update
|
|
48
|
+
* @description Runs the current state's update handler.
|
|
49
|
+
* @param {number} dt - Seconds since the last frame
|
|
50
|
+
*/
|
|
51
|
+
update(dt: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* @method is
|
|
54
|
+
* @description Whether the given state is current.
|
|
55
|
+
* @param {string} name
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
is(name: string): boolean;
|
|
59
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export default Storage;
|
|
2
|
+
/**
|
|
3
|
+
* @class Storage
|
|
4
|
+
* @description Manages the storage of the game
|
|
5
|
+
*/
|
|
6
|
+
declare class Storage {
|
|
7
|
+
/**
|
|
8
|
+
* @method writeToLocalStorage
|
|
9
|
+
* @description Writes to local storage
|
|
10
|
+
* @param {string} key - The key to write to
|
|
11
|
+
* @param {any} value - The value to write to
|
|
12
|
+
*/
|
|
13
|
+
static writeToLocalStorage(key: string, value: any): void;
|
|
14
|
+
/**
|
|
15
|
+
* @method readFromLocalStorage
|
|
16
|
+
* @description Reads from local storage
|
|
17
|
+
* @param {string} key - The key to read from
|
|
18
|
+
* @returns {any} - The value read from local storage
|
|
19
|
+
*/
|
|
20
|
+
static readFromLocalStorage(key: string): any;
|
|
21
|
+
/**
|
|
22
|
+
* @method clearLocalStorage
|
|
23
|
+
* @description Clears local storage
|
|
24
|
+
*/
|
|
25
|
+
static clearLocalStorage(): void;
|
|
26
|
+
/**
|
|
27
|
+
* @method writeToSessionStorage
|
|
28
|
+
* @description Writes to session storage
|
|
29
|
+
* @param {string} key - The key to write to
|
|
30
|
+
* @param {any} value - The value to write to
|
|
31
|
+
*/
|
|
32
|
+
static writeToSessionStorage(key: string, value: any): void;
|
|
33
|
+
/**
|
|
34
|
+
* @method readFromSessionStorage
|
|
35
|
+
* @description Reads from session storage
|
|
36
|
+
* @param {string} key - The key to read from
|
|
37
|
+
* @returns {any} - The value read from session storage
|
|
38
|
+
*/
|
|
39
|
+
static readFromSessionStorage(key: string): any;
|
|
40
|
+
/**
|
|
41
|
+
* @method clearSessionStorage
|
|
42
|
+
* @description Clears session storage
|
|
43
|
+
*/
|
|
44
|
+
static clearSessionStorage(): void;
|
|
45
|
+
/**
|
|
46
|
+
* @method save
|
|
47
|
+
* @description Writes a versioned save under `key`. The payload is wrapped in
|
|
48
|
+
* an envelope `{ v, t, data }` so it can be migrated later, and the previous
|
|
49
|
+
* value is mirrored to `key + ".bak"` for corruption recovery. Quota and
|
|
50
|
+
* serialization errors are caught and reported rather than thrown.
|
|
51
|
+
* @param {string} key - The storage key
|
|
52
|
+
* @param {any} data - The data to persist (must be JSON-serializable)
|
|
53
|
+
* @param {Object} [options] - { version = 1, backup = true }
|
|
54
|
+
* @returns {boolean} - Whether the write succeeded
|
|
55
|
+
*/
|
|
56
|
+
static save(key: string, data: any, options?: any): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @method _unwrap
|
|
59
|
+
* @description Parses a stored string into a `{ v, data }` envelope, treating
|
|
60
|
+
* a plain (pre-versioning) value as version 0. Returns undefined for missing
|
|
61
|
+
* data and throws for malformed JSON.
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private static _unwrap;
|
|
65
|
+
/**
|
|
66
|
+
* @method load
|
|
67
|
+
* @description Reads a versioned save written by `save`. If the primary value
|
|
68
|
+
* is corrupt it falls back to the `.bak` copy; if that fails too it returns
|
|
69
|
+
* `fallback`. When the stored version differs from `version` and a `migrate`
|
|
70
|
+
* function is given, the data is upgraded (and rewritten unless disabled).
|
|
71
|
+
* @param {string} key - The storage key
|
|
72
|
+
* @param {Object} [options] - { version = 1, fallback = null, migrate, rewrite = true }
|
|
73
|
+
* @returns {any} - The (possibly migrated) saved data, or `fallback`
|
|
74
|
+
*/
|
|
75
|
+
static load(key: string, options?: any): any;
|
|
76
|
+
/**
|
|
77
|
+
* @method hasSave
|
|
78
|
+
* @description Returns whether a save (or its backup) exists for `key`.
|
|
79
|
+
* @param {string} key - The storage key
|
|
80
|
+
* @returns {boolean}
|
|
81
|
+
*/
|
|
82
|
+
static hasSave(key: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* @method removeSave
|
|
85
|
+
* @description Deletes a save and its backup.
|
|
86
|
+
* @param {string} key - The storage key
|
|
87
|
+
*/
|
|
88
|
+
static removeSave(key: string): void;
|
|
89
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
export default Texture;
|
|
2
2
|
/**
|
|
3
3
|
* @class Texture
|
|
4
4
|
* @description Represents a texture component
|
|
@@ -13,7 +13,6 @@ import Drawable from "./Drawable";
|
|
|
13
13
|
* @param {boolean} useLighting - Whether the texture should react to lighting
|
|
14
14
|
*/
|
|
15
15
|
declare class Texture extends Drawable {
|
|
16
|
-
constructor(texturePath?:
|
|
16
|
+
constructor(texturePath?: {}, frameWidth?: number, frameHeight?: number, framesPerRow?: number, totalFrames?: number, animationSpeed?: number, autoPlay?: boolean, pixelart?: boolean, useLighting?: boolean);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=Texture.d.ts.map
|
|
18
|
+
import Drawable from "./Drawable.js";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default TextureAtlas;
|
|
2
|
+
/**
|
|
3
|
+
* @class TextureAtlas
|
|
4
|
+
* @description Loads a packed sprite atlas (image + frame rectangles) and applies
|
|
5
|
+
* named frames to Drawables as normalized UV regions. Accepts TexturePacker
|
|
6
|
+
* JSON (hash or array `frames`) or a plain `{ name: {x,y,w,h} }` map.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const atlas = await TextureAtlas.load("sheet.png", sheetJson, true);
|
|
10
|
+
* const sprite = new Texture(atlas.texturePath, 0, 0, 1, 1, 0, false, true);
|
|
11
|
+
* obj.addComponent(sprite);
|
|
12
|
+
* atlas.applyTo(sprite, "player_idle_0");
|
|
13
|
+
*/
|
|
14
|
+
declare class TextureAtlas {
|
|
15
|
+
/**
|
|
16
|
+
* @method load
|
|
17
|
+
* @description Loads the atlas image (caching its GL texture) and parses frames.
|
|
18
|
+
* @param {string} texturePath
|
|
19
|
+
* @param {Object} atlasJson - Atlas description
|
|
20
|
+
* @param {boolean} [pixelart] - Filter mode for the cached texture
|
|
21
|
+
* @returns {Promise<TextureAtlas>}
|
|
22
|
+
*/
|
|
23
|
+
static load(texturePath: string, atlasJson: any, pixelart?: boolean): Promise<TextureAtlas>;
|
|
24
|
+
/** @private */
|
|
25
|
+
private static _parse;
|
|
26
|
+
constructor(texturePath: any, frames: any, width: any, height: any);
|
|
27
|
+
texturePath: any;
|
|
28
|
+
frames: any;
|
|
29
|
+
width: any;
|
|
30
|
+
height: any;
|
|
31
|
+
/**
|
|
32
|
+
* @method getFrame
|
|
33
|
+
* @description Returns the pixel rect { x, y, w, h } for a frame name.
|
|
34
|
+
*/
|
|
35
|
+
getFrame(name: any): any;
|
|
36
|
+
/**
|
|
37
|
+
* @method getRegion
|
|
38
|
+
* @description Returns the normalized UV region for a frame name.
|
|
39
|
+
* @returns {{left,top,right,bottom}|null}
|
|
40
|
+
*/
|
|
41
|
+
getRegion(name: any): {
|
|
42
|
+
left: any;
|
|
43
|
+
top: any;
|
|
44
|
+
right: any;
|
|
45
|
+
bottom: any;
|
|
46
|
+
} | null;
|
|
47
|
+
/**
|
|
48
|
+
* @method applyTo
|
|
49
|
+
* @description Applies a frame's UV region to a Drawable.
|
|
50
|
+
* @param {Drawable} drawable
|
|
51
|
+
* @param {string} name - Frame name
|
|
52
|
+
* @returns {TextureAtlas} - this
|
|
53
|
+
*/
|
|
54
|
+
applyTo(drawable: Drawable, name: string): TextureAtlas;
|
|
55
|
+
}
|