melonjs 19.7.1 → 19.9.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 +21 -6
- package/build/application/application.d.ts.map +1 -1
- package/build/application/defaultApplicationSettings.d.ts +1 -0
- package/build/application/defaultApplicationSettings.d.ts.map +1 -1
- package/build/application/settings.d.ts +34 -0
- package/build/application/settings.d.ts.map +1 -1
- package/build/audio/audio.d.ts +1 -1
- package/build/audio/audio.d.ts.map +1 -1
- package/build/audio/backend.d.ts +21 -2
- package/build/audio/backend.d.ts.map +1 -1
- package/build/audio/playback.d.ts +8 -28
- package/build/audio/playback.d.ts.map +1 -1
- package/build/camera/camera3d.d.ts +49 -0
- package/build/camera/camera3d.d.ts.map +1 -1
- package/build/geometries/path2d.d.ts +188 -75
- package/build/geometries/path2d.d.ts.map +1 -1
- package/build/geometries/rectangle.d.ts.map +1 -1
- package/build/index.d.ts +11 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +19170 -13625
- package/build/index.js.map +4 -4
- package/build/level/gltf/GLTFModel.d.ts +173 -0
- package/build/level/gltf/GLTFModel.d.ts.map +1 -0
- package/build/level/gltf/GLTFScene.d.ts +84 -0
- package/build/level/gltf/GLTFScene.d.ts.map +1 -0
- package/build/level/gltf/gltf_sampler.d.ts +49 -0
- package/build/level/gltf/gltf_sampler.d.ts.map +1 -0
- package/build/level/level.d.ts +7 -3
- package/build/level/level.d.ts.map +1 -1
- package/build/level/tiled/TMXTileMap.d.ts +5 -0
- package/build/level/tiled/TMXTileMap.d.ts.map +1 -1
- package/build/{renderable → lighting}/light2d.d.ts +79 -78
- package/build/lighting/light2d.d.ts.map +1 -0
- package/build/lighting/light3d.d.ts +86 -0
- package/build/lighting/light3d.d.ts.map +1 -0
- package/build/loader/cache.d.ts +2 -0
- package/build/loader/cache.d.ts.map +1 -1
- package/build/loader/loader.d.ts +156 -8
- package/build/loader/loader.d.ts.map +1 -1
- package/build/loader/parsers/fetchdata.d.ts +14 -0
- package/build/loader/parsers/fetchdata.d.ts.map +1 -1
- package/build/loader/parsers/gltf.d.ts +71 -0
- package/build/loader/parsers/gltf.d.ts.map +1 -0
- package/build/loader/parsers/mtl.d.ts.map +1 -1
- package/build/loader/parsers/shader.d.ts +47 -0
- package/build/loader/parsers/shader.d.ts.map +1 -0
- package/build/loader/parsers/video.d.ts.map +1 -1
- package/build/math/color.d.ts.map +1 -1
- package/build/math/math.d.ts +2 -2
- package/build/math/matrix2d.d.ts.map +1 -1
- package/build/math/noise.d.ts +141 -0
- package/build/math/noise.d.ts.map +1 -0
- package/build/math/observableVector2d.d.ts +1 -1
- package/build/math/observableVector2d.d.ts.map +1 -1
- package/build/math/observableVector3d.d.ts +1 -1
- package/build/math/observableVector3d.d.ts.map +1 -1
- package/build/math/vector2d.d.ts +1 -1
- package/build/math/vector2d.d.ts.map +1 -1
- package/build/math/vector3d.d.ts +1 -1
- package/build/math/vector3d.d.ts.map +1 -1
- package/build/math/vertex.d.ts +25 -0
- package/build/math/vertex.d.ts.map +1 -1
- package/build/physics/adapter.d.ts +4 -3
- package/build/physics/adapter.d.ts.map +1 -1
- package/build/physics/broadphase/aabb3d.d.ts +23 -2
- package/build/physics/broadphase/aabb3d.d.ts.map +1 -1
- package/build/renderable/anchorPoint.d.ts +80 -0
- package/build/renderable/anchorPoint.d.ts.map +1 -0
- package/build/renderable/animation.d.ts +41 -0
- package/build/renderable/animation.d.ts.map +1 -0
- package/build/renderable/collectable.d.ts +7 -1
- package/build/renderable/collectable.d.ts.map +1 -1
- package/build/renderable/container.d.ts +0 -1
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/entity/entity.d.ts +5 -2
- package/build/renderable/entity/entity.d.ts.map +1 -1
- package/build/renderable/frameAnimation.d.ts +154 -0
- package/build/renderable/frameAnimation.d.ts.map +1 -0
- package/build/renderable/imagelayer.d.ts +5 -2
- package/build/renderable/imagelayer.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +175 -6
- package/build/renderable/mesh.d.ts.map +1 -1
- package/build/renderable/nineslicesprite.d.ts +5 -7
- package/build/renderable/nineslicesprite.d.ts.map +1 -1
- package/build/renderable/renderable.d.ts +28 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +84 -34
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +350 -0
- package/build/renderable/sprite3d.d.ts.map +1 -0
- package/build/renderable/text/bitmaptext.d.ts +24 -12
- package/build/renderable/text/bitmaptext.d.ts.map +1 -1
- package/build/renderable/text/bitmaptextdata.d.ts +24 -1
- package/build/renderable/text/bitmaptextdata.d.ts.map +1 -1
- package/build/renderable/text/text.d.ts +50 -12
- package/build/renderable/text/text.d.ts.map +1 -1
- package/build/state/stage.d.ts +20 -1
- package/build/state/stage.d.ts.map +1 -1
- package/build/system/event.d.ts +18 -2
- package/build/system/event.d.ts.map +1 -1
- package/build/video/buffer/vertex.d.ts +7 -0
- package/build/video/buffer/vertex.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +4 -0
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +62 -1
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/rendertarget/render_target_pool.d.ts +17 -6
- package/build/video/rendertarget/render_target_pool.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +3 -2
- package/build/video/texture/atlas.d.ts.map +1 -1
- package/build/video/texture/cache.d.ts +55 -6
- package/build/video/texture/cache.d.ts.map +1 -1
- package/build/video/texture/frametexture.d.ts +73 -0
- package/build/video/texture/frametexture.d.ts.map +1 -0
- package/build/video/texture/noise_texture2d.d.ts +176 -0
- package/build/video/texture/noise_texture2d.d.ts.map +1 -0
- package/build/video/texture/parser/aseprite.d.ts.map +1 -1
- package/build/video/texture/texture2d.d.ts +83 -0
- package/build/video/texture/texture2d.d.ts.map +1 -0
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts +18 -0
- package/build/video/webgl/batchers/lit_mesh_batcher.d.ts.map +1 -0
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts +30 -4
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/material_batcher.d.ts +39 -3
- package/build/video/webgl/batchers/material_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/mesh_batcher.d.ts +52 -11
- package/build/video/webgl/batchers/mesh_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/primitive_batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/buffer/index.d.ts +13 -0
- package/build/video/webgl/buffer/index.d.ts.map +1 -1
- package/build/video/webgl/effects/hologram.d.ts +0 -5
- package/build/video/webgl/effects/hologram.d.ts.map +1 -1
- package/build/video/webgl/effects/shine.d.ts +1 -6
- package/build/video/webgl/effects/shine.d.ts.map +1 -1
- package/build/video/webgl/glshader.d.ts +29 -0
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/lighting/pack3d.d.ts +32 -0
- package/build/video/webgl/lighting/pack3d.d.ts.map +1 -0
- package/build/video/webgl/shadereffect.d.ts +183 -0
- package/build/video/webgl/shadereffect.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +59 -1
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +5 -5
- package/build/renderable/light2d.d.ts.map +0 -1
|
@@ -12,7 +12,7 @@ export default class Sprite extends Renderable {
|
|
|
12
12
|
* @param {number} x - the x coordinates of the sprite object
|
|
13
13
|
* @param {number} y - the y coordinates of the sprite object
|
|
14
14
|
* @param {object} settings - Configuration parameters for the Sprite object
|
|
15
|
-
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|TextureAtlas|CompressedImage|string} settings.image - reference to spritesheet image, a
|
|
15
|
+
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement|Texture2d|TextureAtlas|CompressedImage|string} settings.image - reference to a spritesheet image, a {@link Texture2d} asset (e.g. a {@link TextureAtlas}), a video element, a compressed texture, or a loader key
|
|
16
16
|
* @param {string} [settings.name=""] - name of this object
|
|
17
17
|
* @param {string} [settings.region] - region name of a specific region to use when using a texture atlas, see {@link TextureAtlas}
|
|
18
18
|
* @param {number} [settings.framewidth] - Width of a single frame within the spritesheet
|
|
@@ -20,8 +20,8 @@ export default class Sprite extends Renderable {
|
|
|
20
20
|
* @param {string|Color} [settings.tint] - a tint to be applied to this sprite
|
|
21
21
|
* @param {number} [settings.flipX] - flip the sprite on the horizontal axis
|
|
22
22
|
* @param {number} [settings.flipY] - flip the sprite on the vertical axis
|
|
23
|
-
* @param {Vector2d} [settings.anchorPoint={x:0.5, y:0.5}] - Anchor point to draw the frame at (defaults to the center of the frame).
|
|
24
|
-
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap|string} [settings.normalMap] - optional normal-map texture used for per-pixel lighting (SpriteIlluminator-style). Same layout/UVs as `settings.image`. When omitted (default), the sprite renders unlit and pays no extra cost. Ignored by the Canvas renderer. Note: `HTMLVideoElement` is intentionally not supported — normal maps encode static surface directions in RGB, and the engine caches the GL texture per image reference (a video would freeze on frame 0).
|
|
23
|
+
* @param {string|Vector2d|{x:number,y:number}} [settings.anchorPoint={x:0.5, y:0.5}] - Anchor point to draw the frame at (defaults to the center of the frame). Also accepts the named presets `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`. For spritesheet atlases the anchor also becomes the cached atlas's per-frame pivot (see {@link TextureAtlas}).
|
|
24
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap|Texture2d|string} [settings.normalMap] - optional normal-map texture used for per-pixel lighting (SpriteIlluminator-style). Same layout/UVs as `settings.image`. When omitted (default), the sprite renders unlit and pays no extra cost. Ignored by the Canvas renderer. Note: `HTMLVideoElement` is intentionally not supported — normal maps encode static surface directions in RGB, and the engine caches the GL texture per image reference (a video would freeze on frame 0).
|
|
25
25
|
* @example
|
|
26
26
|
* // create a single sprite from a standalone image, with anchor in the center
|
|
27
27
|
* let sprite = new me.Sprite(0, 0, {
|
|
@@ -52,7 +52,7 @@ export default class Sprite extends Renderable {
|
|
|
52
52
|
* videoSprite.play();
|
|
53
53
|
*/
|
|
54
54
|
constructor(x: number, y: number, settings: {
|
|
55
|
-
image: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | TextureAtlas | CompressedImage | string;
|
|
55
|
+
image: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | Texture2d | TextureAtlas | CompressedImage | string;
|
|
56
56
|
name?: string | undefined;
|
|
57
57
|
region?: string | undefined;
|
|
58
58
|
framewidth?: number | undefined;
|
|
@@ -60,20 +60,13 @@ export default class Sprite extends Renderable {
|
|
|
60
60
|
tint?: string | Color | undefined;
|
|
61
61
|
flipX?: number | undefined;
|
|
62
62
|
flipY?: number | undefined;
|
|
63
|
-
anchorPoint?: Vector2d |
|
|
64
|
-
|
|
63
|
+
anchorPoint?: string | Vector2d | {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
} | undefined;
|
|
67
|
+
normalMap?: string | ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | Texture2d | undefined;
|
|
65
68
|
});
|
|
66
|
-
|
|
67
|
-
* @type {boolean}
|
|
68
|
-
* @default false
|
|
69
|
-
*/
|
|
70
|
-
animationpause: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* animation cycling speed (delay between frame in ms)
|
|
73
|
-
* @type {number}
|
|
74
|
-
* @default 100
|
|
75
|
-
*/
|
|
76
|
-
animationspeed: number;
|
|
69
|
+
_frameAnim: FrameAnimation;
|
|
77
70
|
/**
|
|
78
71
|
* global offset for the position to draw from on the source image.
|
|
79
72
|
* @type {Vector2d}
|
|
@@ -102,19 +95,6 @@ export default class Sprite extends Renderable {
|
|
|
102
95
|
* @ignore
|
|
103
96
|
*/
|
|
104
97
|
_normalMap: ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | null;
|
|
105
|
-
anim: {};
|
|
106
|
-
resetAnim: Function | (() => Sprite) | undefined;
|
|
107
|
-
current: {
|
|
108
|
-
name: undefined;
|
|
109
|
-
length: number;
|
|
110
|
-
offset: Vector2d;
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
angle: number;
|
|
114
|
-
idx: number;
|
|
115
|
-
trim: null;
|
|
116
|
-
};
|
|
117
|
-
dt: number;
|
|
118
98
|
/**
|
|
119
99
|
* flicker settings
|
|
120
100
|
* @ignore
|
|
@@ -129,6 +109,13 @@ export default class Sprite extends Renderable {
|
|
|
129
109
|
textureAtlas: any;
|
|
130
110
|
width: any;
|
|
131
111
|
height: any;
|
|
112
|
+
set animationpause(value: boolean);
|
|
113
|
+
/**
|
|
114
|
+
* pause the frame animation, freezing the current frame.
|
|
115
|
+
* @type {boolean}
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
get animationpause(): boolean;
|
|
132
119
|
/**
|
|
133
120
|
* pause the video when losing focus
|
|
134
121
|
* @ignore
|
|
@@ -148,19 +135,62 @@ export default class Sprite extends Renderable {
|
|
|
148
135
|
*/
|
|
149
136
|
get normalMap(): HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap | null;
|
|
150
137
|
atlasIndices: any;
|
|
138
|
+
/**
|
|
139
|
+
* defined animations, keyed by id (see {@link Sprite#addAnimation}).
|
|
140
|
+
* @type {object}
|
|
141
|
+
*/
|
|
142
|
+
get anim(): object;
|
|
143
|
+
/**
|
|
144
|
+
* current frame information (name / index / texture offset & size / trim).
|
|
145
|
+
* @type {object}
|
|
146
|
+
*/
|
|
147
|
+
get current(): object;
|
|
148
|
+
set dt(value: number);
|
|
149
|
+
/**
|
|
150
|
+
* elapsed time within the current animation frame, in milliseconds.
|
|
151
|
+
* @type {number}
|
|
152
|
+
*/
|
|
153
|
+
get dt(): number;
|
|
154
|
+
set animationspeed(value: number);
|
|
155
|
+
/**
|
|
156
|
+
* animation cycling speed (delay between frames in ms).
|
|
157
|
+
* @type {number}
|
|
158
|
+
* @default 100
|
|
159
|
+
*/
|
|
160
|
+
get animationspeed(): number;
|
|
151
161
|
/**
|
|
152
162
|
* return the flickering state of the object
|
|
153
163
|
* @returns {boolean}
|
|
154
164
|
*/
|
|
155
165
|
isFlickering(): boolean;
|
|
156
166
|
/**
|
|
157
|
-
*
|
|
167
|
+
* Play an animation, or resume the current animation / video. A shorthand:
|
|
168
|
+
* call with an animation id to switch to (and start) it, or with no argument
|
|
169
|
+
* to resume after {@link Sprite#pause}. Always clears the paused state. The
|
|
170
|
+
* options mirror {@link Sprite#setCurrentAnimation} and the 3D
|
|
171
|
+
* {@link GLTFModel#play}, so 2D and 3D animation share one API.
|
|
172
|
+
* @param {string} [name] - animation id to play; omit to just resume
|
|
173
|
+
* @param {string|Function|object} [options] - loop / chain / completion behavior (see {@link Sprite#setCurrentAnimation})
|
|
174
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
175
|
+
* @example
|
|
176
|
+
* sprite.play("walk"); // switch to + play "walk"
|
|
177
|
+
* sprite.play("die", { loop: false }); // play once, hold the last frame
|
|
178
|
+
* sprite.pause();
|
|
179
|
+
* sprite.play(); // resume
|
|
180
|
+
*/
|
|
181
|
+
play(name?: string, options?: string | Function | object): Sprite;
|
|
182
|
+
/**
|
|
183
|
+
* Pause the current animation or video, freezing the current frame. Resume
|
|
184
|
+
* with {@link Sprite#play}.
|
|
185
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
158
186
|
*/
|
|
159
|
-
|
|
187
|
+
pause(): Sprite;
|
|
160
188
|
/**
|
|
161
|
-
*
|
|
189
|
+
* Stop the current animation or video and reset it to the first frame
|
|
190
|
+
* (paused). (Use {@link Sprite#pause} instead to freeze in place.)
|
|
191
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
162
192
|
*/
|
|
163
|
-
|
|
193
|
+
stop(): Sprite;
|
|
164
194
|
/**
|
|
165
195
|
* make the object flicker
|
|
166
196
|
* @param {number} duration - expressed in milliseconds
|
|
@@ -260,6 +290,16 @@ export default class Sprite extends Renderable {
|
|
|
260
290
|
* }
|
|
261
291
|
*/
|
|
262
292
|
isCurrentAnimation(name: string): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* the names of every animation defined on this sprite (via
|
|
295
|
+
* {@link Sprite#addAnimation}).
|
|
296
|
+
* @returns {string[]} the defined animation names
|
|
297
|
+
* @example
|
|
298
|
+
* sprite.addAnimation("walk", [0, 1, 2, 3]);
|
|
299
|
+
* sprite.addAnimation("idle", [4, 5]);
|
|
300
|
+
* sprite.getAnimationNames(); // ["walk", "idle"]
|
|
301
|
+
*/
|
|
302
|
+
getAnimationNames(): string[];
|
|
263
303
|
/**
|
|
264
304
|
* change the current texture atlas region for this sprite
|
|
265
305
|
* @see Texture.getRegion
|
|
@@ -270,6 +310,14 @@ export default class Sprite extends Renderable {
|
|
|
270
310
|
* mySprite.setRegion(mytexture.getRegion("shadedDark13.png"));
|
|
271
311
|
*/
|
|
272
312
|
setRegion(region: object): Sprite;
|
|
313
|
+
/**
|
|
314
|
+
* Apply the current frame's texture region to this sprite's geometry: swap
|
|
315
|
+
* the source sub-texture, then resolve size / anchor (honoring trimming).
|
|
316
|
+
* Invoked by the shared {@link FrameAnimation} engine via `setRegion`.
|
|
317
|
+
* @param {object} region - the texture region object
|
|
318
|
+
* @ignore
|
|
319
|
+
*/
|
|
320
|
+
_applyFrame(region: object): void;
|
|
273
321
|
/**
|
|
274
322
|
* force the current animation frame index.
|
|
275
323
|
* @param {number} [index=0] - animation frame index
|
|
@@ -317,8 +365,10 @@ export default class Sprite extends Renderable {
|
|
|
317
365
|
destroy(): void;
|
|
318
366
|
}
|
|
319
367
|
import Renderable from "./renderable.js";
|
|
368
|
+
import FrameAnimation from "./frameAnimation.js";
|
|
320
369
|
import type { Vector2d } from "../math/vector2d.js";
|
|
321
370
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
322
371
|
import type Renderer from "./../video/renderer.js";
|
|
372
|
+
import Texture2d from "./../video/texture/texture2d.ts";
|
|
323
373
|
import { Color } from "../math/color.ts";
|
|
324
374
|
//# sourceMappingURL=sprite.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sprite.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite.js"],"names":[],"mappings":"AAcA;;;;GAIG;AAEH;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0CG;IACH,eA1CW,MAAM,KACN,MAAM,YAEd;QAAoH,KAAK,EAAjH,gBAAgB,GAAC,iBAAiB,GAAC,gBAAgB,GAAC,SAAS,GAAC,YAAY,GAAC,eAAe,GAAC,MAAM;QAC/E,IAAI;QACJ,MAAM;QACN,UAAU;QACV,WAAW;QACL,IAAI;QACV,KAAK;QACL,KAAK;QACwB,WAAW;eAAvC,MAAM;eAAG,MAAM;;QACyD,SAAS;KAC5G,EAmSF;IAnPA,2BAEE;IAEF;;;;OAIG;IACH,QAHU,QAAQ,CAGkB;IAEpC;;;;OAIG;IACH,SAHU,OAAO,CAGG;IAEpB;;;;OAIG;IAGH;;;OAGG;IACH,QAFU,YAAY,CAEJ;IAElB;;;;OAIG;IACH,wFAAsB;IAEtB;;;OAGG;IACH;;;;;MAKC;IAKA,WAAqC;IACrC,kBAAkC;IAsCjC,WAG8C;IAC9C,YAGgD;IAkMnD,0BANU,OAAO,EAQhB;IAVD;;;;OAIG;IACH,sBAHU,OAAO,CAKhB;IA1LE;;;OAGG;IACH,mDAEE;IAuML,qBALU,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,GAAC,IAAI,EAoC5E;I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ACJ,MAAM,CAIlB;IAyCD;;;;;;OAMG;IACH,kBAFW,QAAQ,QAWlB;IAED;;;OAGG;IACH,mBAFW,QAAQ,QAQlB;IAED;;;;OAIG;IACH,eAHW,QAAQ,QAuDlB;IAED;;;OAGG;IACH,gBAiBC;CACD;uBAp2BsB,iBAAiB;2BADb,qBAAqB;8BAQrB,qBAAqB;6BAXnB,6BAA6B;0BAYjC,wBAAwB;sBAX3B,iCAAiC;sBAJjC,kBAAkB"}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A textured **quad in 3D space** — the 3D counterpart of {@link Sprite},
|
|
3
|
+
* for rendering sprites under a {@link Camera3d} (the 2.5D workflow: characters,
|
|
4
|
+
* pickups, foliage, signs, particles in a 3D scene). It's a thin {@link Mesh}
|
|
5
|
+
* subclass, so it rides the same world-space mesh pipeline (depth testing,
|
|
6
|
+
* frustum culling) and supports the same material features (`lit`, `emissive`,
|
|
7
|
+
* `alphaCutoff`).
|
|
8
|
+
*
|
|
9
|
+
* Its headline feature is **billboarding** — keeping the quad facing the camera
|
|
10
|
+
* regardless of camera orientation (see {@link Sprite3d#billboard}). With
|
|
11
|
+
* billboarding off it's a fixed-orientation quad (decals, posters, ground
|
|
12
|
+
* markers).
|
|
13
|
+
*
|
|
14
|
+
* **Frame animation** is supported through the same API as {@link Sprite}
|
|
15
|
+
* ({@link Sprite3d#addAnimation}, {@link Sprite3d#setCurrentAnimation},
|
|
16
|
+
* {@link Sprite3d#play}/`pause`/`stop`) — pass `framewidth`/`frameheight` for a
|
|
17
|
+
* spritesheet, or a packed {@link TextureAtlas}, exactly as you would for a 2D
|
|
18
|
+
* `Sprite`. Both share the {@link FrameAnimation} engine, so the timing, looping
|
|
19
|
+
* and chaining behavior is identical; `Sprite3d` maps the current frame onto the
|
|
20
|
+
* quad each step — including packer **rotated** and **trimmed** regions, mapped
|
|
21
|
+
* to full parity with the 2D `Sprite`.
|
|
22
|
+
*
|
|
23
|
+
* **Camera3d only.** Like {@link Mesh}, `Sprite3d` renders through the 3D
|
|
24
|
+
* world-space path; under a 2D `Camera2d` it falls back to the mesh's
|
|
25
|
+
* self-projection and **billboarding has no effect** (a 2D scene has no camera
|
|
26
|
+
* orientation to face). Use a regular {@link Sprite} for 2D.
|
|
27
|
+
*
|
|
28
|
+
* **Anchoring.** Unlike its {@link Mesh} parent — where `anchorPoint` is inert
|
|
29
|
+
* on the 3D path and transforms pivot at the model origin — Sprite3d's
|
|
30
|
+
* `anchorPoint` is live: the anchor is baked into the quad's local vertices
|
|
31
|
+
* (never applied as a renderer transform on either camera path) and can be
|
|
32
|
+
* changed at runtime via `anchorPoint.set(...)`, which re-bakes the quad and
|
|
33
|
+
* re-derives the cull bounds. Same key, convention and centered default as
|
|
34
|
+
* the 2D {@link Sprite}, including the named presets (`"bottom"`, …).
|
|
35
|
+
* @augments Mesh
|
|
36
|
+
* @category Game Objects
|
|
37
|
+
* @example
|
|
38
|
+
* import { Application, Camera3d, Sprite3d } from "melonjs";
|
|
39
|
+
*
|
|
40
|
+
* // a 3D app (Camera3d is required for billboarding)
|
|
41
|
+
* const app = new Application(1024, 768, { cameraClass: Camera3d });
|
|
42
|
+
*
|
|
43
|
+
* // a tree that always faces the camera but stays upright (2.5D).
|
|
44
|
+
* // its texture has a transparent background — the mesh pass is opaque, so
|
|
45
|
+
* // `alphaCutoff` (default 0.5) discards those texels for a clean silhouette.
|
|
46
|
+
* const tree = new Sprite3d(0, 0, {
|
|
47
|
+
* image: "tree", // a preloaded image with transparency
|
|
48
|
+
* width: 64, height: 96,
|
|
49
|
+
* z: -200, // 3D depth (world z)
|
|
50
|
+
* billboard: true, // = "cylindrical"
|
|
51
|
+
* // alphaCutoff: 0.5, // the default — lower it to keep softer edges,
|
|
52
|
+
* // or set 0 for a fully-opaque quad
|
|
53
|
+
* });
|
|
54
|
+
* app.world.addChild(tree); // add it to the game world, like any Renderable
|
|
55
|
+
*
|
|
56
|
+
* // an animated, fully camera-facing pickup from a spritesheet, mirrored
|
|
57
|
+
* const coin = new Sprite3d(0, 0, {
|
|
58
|
+
* image: "coins",
|
|
59
|
+
* framewidth: 32, frameheight: 32,
|
|
60
|
+
* width: 48, height: 48,
|
|
61
|
+
* billboard: "spherical",
|
|
62
|
+
* alphaCutoff: 0.5, // cut out the transparent frame background
|
|
63
|
+
* });
|
|
64
|
+
* coin.addAnimation("spin", [0, 1, 2, 3, 4, 5]);
|
|
65
|
+
* coin.setCurrentAnimation("spin");
|
|
66
|
+
* coin.flipX(); // face the other way (mirrors the sprite)
|
|
67
|
+
* app.world.addChild(coin);
|
|
68
|
+
*
|
|
69
|
+
* // a character anchored at the feet, so `pos` sits on the ground plane
|
|
70
|
+
* // instead of at the sprite's geometric center
|
|
71
|
+
* const hero = new Sprite3d(0, 0, {
|
|
72
|
+
* image: "hero",
|
|
73
|
+
* width: 48, height: 64,
|
|
74
|
+
* billboard: "cylindrical",
|
|
75
|
+
* anchorPoint: "bottom", // == { x: 0.5, y: 1 }
|
|
76
|
+
* });
|
|
77
|
+
*/
|
|
78
|
+
export default class Sprite3d extends Mesh {
|
|
79
|
+
/**
|
|
80
|
+
* @param {number} x - world x position
|
|
81
|
+
* @param {number} y - world y position
|
|
82
|
+
* @param {object} settings - configuration
|
|
83
|
+
* @param {HTMLImageElement|Texture2d|string} [settings.image] - the sprite texture (image name, image, or a {@link Texture2d} asset such as a {@link TextureAtlas}). Alias: `settings.texture`.
|
|
84
|
+
* @param {number} [settings.width=settings.framewidth] - quad width in world units (pixels)
|
|
85
|
+
* @param {number} [settings.height=settings.width] - quad height in world units
|
|
86
|
+
* @param {number} [settings.framewidth] - width of a single frame within a spritesheet (enables frame animation)
|
|
87
|
+
* @param {number} [settings.frameheight] - height of a single frame within a spritesheet
|
|
88
|
+
* @param {string} [settings.region] - region name when using a texture atlas (see {@link TextureAtlas})
|
|
89
|
+
* @param {object[]} [settings.anims] - predefined animations (same shape as {@link Sprite})
|
|
90
|
+
* @param {number} [settings.z=0] - 3D depth (world z); also settable later via `.depth`
|
|
91
|
+
* @param {boolean|string} [settings.billboard=false] - billboard mode: `false` (fixed orientation), `true` / `"cylindrical"` (faces the camera but stays upright — the 2.5D default), or `"spherical"` (faces the camera on all axes). Only applies under a `Camera3d`.
|
|
92
|
+
* @param {string|Vector2d|{x:number,y:number}} [settings.anchorPoint={x:0.5,y:0.5}] - anchor of the quad relative to `pos` — same key, normalized 0..1 convention (`x`: 0 left→1 right, `y`: 0 top→1 bottom) and centered default as the 2D {@link Sprite}. Also accepts the named presets `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`. Baked into the quad's local vertices (composes with billboarding, flips, and trimmed/rotated atlas frames) — never applied as a renderer transform on either camera path. Mutable at runtime via `this.anchorPoint.set(...)` (re-bakes the quad and re-derives the cull bounds). Invalid values throw.
|
|
93
|
+
* @param {boolean} [settings.flipX=false] - mirror the sprite horizontally (see {@link Sprite3d#flipX})
|
|
94
|
+
* @param {boolean} [settings.flipY=false] - mirror the sprite vertically (see {@link Sprite3d#flipY})
|
|
95
|
+
* @param {boolean} [settings.lit=false] - shade through the lit mesh batcher (see {@link Mesh})
|
|
96
|
+
* @param {number[]|Float32Array} [settings.emissive] - emissive color (see {@link Mesh})
|
|
97
|
+
* @param {number} [settings.alphaCutoff=0.5] - alpha cutout threshold (see {@link Mesh}). The mesh pass is opaque (no alpha blending), so this defaults to `0.5` to discard a sprite's transparent background (clean cutout silhouette, correct depth, no sorting). Set `0` for a fully-opaque quad, or tune the threshold.
|
|
98
|
+
*/
|
|
99
|
+
constructor(x: number, y: number, settings: {
|
|
100
|
+
image?: string | HTMLImageElement | Texture2d | undefined;
|
|
101
|
+
width?: number | undefined;
|
|
102
|
+
height?: number | undefined;
|
|
103
|
+
framewidth?: number | undefined;
|
|
104
|
+
frameheight?: number | undefined;
|
|
105
|
+
region?: string | undefined;
|
|
106
|
+
anims?: object[] | undefined;
|
|
107
|
+
z?: number | undefined;
|
|
108
|
+
billboard?: string | boolean | undefined;
|
|
109
|
+
anchorPoint?: string | Vector2d | {
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
};
|
|
113
|
+
flipX?: boolean | undefined;
|
|
114
|
+
flipY?: boolean | undefined;
|
|
115
|
+
lit?: boolean | undefined;
|
|
116
|
+
emissive?: number[] | Float32Array<ArrayBufferLike> | undefined;
|
|
117
|
+
alphaCutoff?: number | undefined;
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* the quad's half-width in world units (see {@link Sprite3d#billboard}).
|
|
121
|
+
* @type {number}
|
|
122
|
+
* @ignore
|
|
123
|
+
*/
|
|
124
|
+
_halfW: number;
|
|
125
|
+
/** @ignore */
|
|
126
|
+
_halfH: number;
|
|
127
|
+
/** @ignore */
|
|
128
|
+
_anchorOffsetX: number;
|
|
129
|
+
/** @ignore */
|
|
130
|
+
_anchorOffsetY: number;
|
|
131
|
+
/** @ignore */
|
|
132
|
+
_refLw: number;
|
|
133
|
+
/** @ignore */
|
|
134
|
+
_refLh: number;
|
|
135
|
+
/** @ignore */
|
|
136
|
+
_flipX: boolean;
|
|
137
|
+
/** @ignore */
|
|
138
|
+
_flipY: boolean;
|
|
139
|
+
/** @ignore */
|
|
140
|
+
_region: object | null;
|
|
141
|
+
/**
|
|
142
|
+
* a callback fired when the current animation completes a cycle.
|
|
143
|
+
* @type {Function}
|
|
144
|
+
*/
|
|
145
|
+
onended: Function;
|
|
146
|
+
/** the frame-aware atlas (== this.texture) @ignore */
|
|
147
|
+
source: any;
|
|
148
|
+
/** the atlas region dictionary @ignore */
|
|
149
|
+
textureAtlas: any;
|
|
150
|
+
/** name→index map for named-region atlases @ignore */
|
|
151
|
+
atlasIndices: any;
|
|
152
|
+
/** the shared frame-animation engine @ignore */
|
|
153
|
+
_frameAnim: FrameAnimation;
|
|
154
|
+
/**
|
|
155
|
+
* Billboard mode — keeps the quad facing the active {@link Camera3d}:
|
|
156
|
+
* - `false` (default) — fixed orientation (a flat quad in the XY plane;
|
|
157
|
+
* decals, posters, ground markers).
|
|
158
|
+
* - `true` / `"cylindrical"` — faces the camera but stays upright
|
|
159
|
+
* (rotates only around the world up axis). The 2.5D default — trees,
|
|
160
|
+
* characters, items.
|
|
161
|
+
* - `"spherical"` — faces the camera on all axes (particles, glints).
|
|
162
|
+
*
|
|
163
|
+
* **Only applies under a `Camera3d`**; ignored on the 2D path.
|
|
164
|
+
*
|
|
165
|
+
* Note: while billboarding, orientation comes from the camera, so the
|
|
166
|
+
* renderable's `currentTransform` (`rotate()` / `scale()` / parent-container
|
|
167
|
+
* transforms) and `meshScale` are **not** applied — only `pos` / `depth`,
|
|
168
|
+
* `flipX` / `flipY`, and the quad's authored size. With billboarding `false`
|
|
169
|
+
* the standard {@link Mesh} world transform applies as usual.
|
|
170
|
+
* @type {boolean|string}
|
|
171
|
+
* @default false
|
|
172
|
+
*/
|
|
173
|
+
billboard: boolean | string;
|
|
174
|
+
/** the camera captured at draw time for the billboard projection @ignore */
|
|
175
|
+
_billboardCam: Camera3d | null;
|
|
176
|
+
/**
|
|
177
|
+
* anchorPoint changed at runtime (the ObservablePoint callback wired in
|
|
178
|
+
* the constructor): recompute the baked local offset from the live anchor
|
|
179
|
+
* and the art size, re-bake the quad, and re-derive the frustum-cull
|
|
180
|
+
* bounds. Preserves the base ObservablePoint contract (updateBounds +
|
|
181
|
+
* isDirty, see Renderable's anchorPoint callback).
|
|
182
|
+
* @ignore
|
|
183
|
+
*/
|
|
184
|
+
_onAnchorChanged(): void;
|
|
185
|
+
/**
|
|
186
|
+
* defined animations, keyed by id (see {@link Sprite3d#addAnimation}).
|
|
187
|
+
* @type {object}
|
|
188
|
+
*/
|
|
189
|
+
get anim(): object;
|
|
190
|
+
/**
|
|
191
|
+
* current frame information (name / index / texture offset & size / trim).
|
|
192
|
+
* @type {object}
|
|
193
|
+
*/
|
|
194
|
+
get current(): object;
|
|
195
|
+
set dt(value: number);
|
|
196
|
+
/**
|
|
197
|
+
* elapsed time within the current animation frame, in milliseconds.
|
|
198
|
+
* @type {number}
|
|
199
|
+
*/
|
|
200
|
+
get dt(): number;
|
|
201
|
+
set animationspeed(value: number);
|
|
202
|
+
/**
|
|
203
|
+
* animation cycling speed (delay between frames in ms).
|
|
204
|
+
* @type {number}
|
|
205
|
+
* @default 100
|
|
206
|
+
*/
|
|
207
|
+
get animationspeed(): number;
|
|
208
|
+
set animationpause(value: boolean);
|
|
209
|
+
/**
|
|
210
|
+
* pause the frame animation, freezing the current frame.
|
|
211
|
+
* @type {boolean}
|
|
212
|
+
* @default false
|
|
213
|
+
*/
|
|
214
|
+
get animationpause(): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Add an animation, identical to {@link Sprite#addAnimation}.
|
|
217
|
+
* @param {string} name - animation id
|
|
218
|
+
* @param {number[]|string[]|object[]} index - frame indices / names (see {@link Sprite#addAnimation})
|
|
219
|
+
* @param {number} [animationspeed] - cycling speed in ms
|
|
220
|
+
* @returns {number} number of frames added
|
|
221
|
+
*/
|
|
222
|
+
addAnimation(name: string, index: number[] | string[] | object[], animationspeed?: number): number;
|
|
223
|
+
/**
|
|
224
|
+
* Select the active animation, identical to {@link Sprite#setCurrentAnimation}.
|
|
225
|
+
* @param {string} name - animation id
|
|
226
|
+
* @param {string|Function|object} [resetAnim] - loop / chain / completion behavior
|
|
227
|
+
* @param {boolean} [preserve_dt=false]
|
|
228
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
229
|
+
*/
|
|
230
|
+
setCurrentAnimation(name: string, resetAnim?: string | Function | object, preserve_dt?: boolean): Sprite3d;
|
|
231
|
+
/**
|
|
232
|
+
* Reverse the given (or current) animation in place (see {@link Sprite#reverseAnimation}).
|
|
233
|
+
* @param {string} [name] - animation id
|
|
234
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
235
|
+
*/
|
|
236
|
+
reverseAnimation(name?: string): Sprite3d;
|
|
237
|
+
/**
|
|
238
|
+
* Mirror the sprite horizontally (e.g. flip a character to face the other
|
|
239
|
+
* way). Unlike the 2D {@link Sprite}, the flip mirrors the quad's local
|
|
240
|
+
* geometry so it works for every billboard mode and for rotated/trimmed atlas
|
|
241
|
+
* regions alike. Takes effect immediately on the current frame.
|
|
242
|
+
* @param {boolean} [flip=true]
|
|
243
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
244
|
+
*/
|
|
245
|
+
flipX(flip?: boolean): Sprite3d;
|
|
246
|
+
/**
|
|
247
|
+
* Mirror the sprite vertically. See {@link Sprite3d#flipX}.
|
|
248
|
+
* @param {boolean} [flip=true]
|
|
249
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
250
|
+
*/
|
|
251
|
+
flipY(flip?: boolean): Sprite3d;
|
|
252
|
+
/**
|
|
253
|
+
* @returns {boolean} true if the sprite is mirrored horizontally.
|
|
254
|
+
*/
|
|
255
|
+
isFlippedX(): boolean;
|
|
256
|
+
/**
|
|
257
|
+
* @returns {boolean} true if the sprite is mirrored vertically.
|
|
258
|
+
*/
|
|
259
|
+
isFlippedY(): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Play (and optionally switch to) an animation, identical to {@link Sprite#play}.
|
|
262
|
+
* @param {string} [name] - animation id to play; omit to resume
|
|
263
|
+
* @param {string|Function|object} [options] - loop / chain / completion behavior
|
|
264
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
265
|
+
*/
|
|
266
|
+
play(name?: string, options?: string | Function | object): Sprite3d;
|
|
267
|
+
/**
|
|
268
|
+
* Pause the current animation, freezing the current frame (see {@link Sprite#pause}).
|
|
269
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
270
|
+
*/
|
|
271
|
+
pause(): Sprite3d;
|
|
272
|
+
/**
|
|
273
|
+
* Stop and reset the current animation to its first frame (see {@link Sprite#stop}).
|
|
274
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
275
|
+
*/
|
|
276
|
+
stop(): Sprite3d;
|
|
277
|
+
/**
|
|
278
|
+
* Force the current animation frame index (see {@link Sprite#setAnimationFrame}).
|
|
279
|
+
* @param {number} [index=0] - animation frame index
|
|
280
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
281
|
+
*/
|
|
282
|
+
setAnimationFrame(index?: number): Sprite3d;
|
|
283
|
+
/**
|
|
284
|
+
* Apply a texture region directly (see {@link Sprite#setRegion}).
|
|
285
|
+
* @param {object} region - typically from `texture.getRegion(name)`
|
|
286
|
+
* @returns {Sprite3d} Reference to this object for method chaining
|
|
287
|
+
*/
|
|
288
|
+
setRegion(region: object): Sprite3d;
|
|
289
|
+
/**
|
|
290
|
+
* @param {string} name - animation id
|
|
291
|
+
* @returns {boolean} true if `name` is the current animation (see {@link Sprite#isCurrentAnimation}).
|
|
292
|
+
*/
|
|
293
|
+
isCurrentAnimation(name: string): boolean;
|
|
294
|
+
/**
|
|
295
|
+
* @returns {string[]} the names of every defined animation (see {@link Sprite#getAnimationNames}).
|
|
296
|
+
*/
|
|
297
|
+
getAnimationNames(): string[];
|
|
298
|
+
/**
|
|
299
|
+
* @returns {number} the current animation frame index (see {@link Sprite#getCurrentAnimationFrame}).
|
|
300
|
+
*/
|
|
301
|
+
getCurrentAnimationFrame(): number;
|
|
302
|
+
/**
|
|
303
|
+
* The frame object for the given index within the current animation.
|
|
304
|
+
* @param {number} id - the frame id
|
|
305
|
+
* @returns {object} the frame data
|
|
306
|
+
* @ignore
|
|
307
|
+
*/
|
|
308
|
+
getAnimationFrameObjectByIndex(id: number): object;
|
|
309
|
+
/**
|
|
310
|
+
* Apply the current frame's texture region to the quad — the geometry hook
|
|
311
|
+
* called by the shared {@link FrameAnimation} engine (the 3D counterpart of
|
|
312
|
+
* {@link Sprite}'s sub-texture / size / anchor swap). Rewrites both the quad's
|
|
313
|
+
* UVs (the atlas sub-rect, with a 90° corner permutation for packer-rotated
|
|
314
|
+
* regions) and its local vertices (the trimmed art's sub-rectangle within the
|
|
315
|
+
* logical frame, scaled into the quad's world footprint, then shifted by the
|
|
316
|
+
* anchor offset), so trimmed and rotated `TextureAtlas` regions render at
|
|
317
|
+
* full parity with the 2D `Sprite`.
|
|
318
|
+
* @param {object} region - the texture region object
|
|
319
|
+
* @ignore
|
|
320
|
+
*/
|
|
321
|
+
_applyFrame(region: object): void;
|
|
322
|
+
/**
|
|
323
|
+
* Release resources (returns the engine's pooled `current.offset` to the
|
|
324
|
+
* pool), then defer to the standard mesh/renderable teardown.
|
|
325
|
+
* @ignore
|
|
326
|
+
*/
|
|
327
|
+
destroy(): void;
|
|
328
|
+
/**
|
|
329
|
+
* Capture the rendering camera so {@link Sprite3d#_projectVerticesWorld} can
|
|
330
|
+
* orient the billboard toward it. Read from the per-draw `viewport` (passed
|
|
331
|
+
* by `Container.draw`), so a multi-camera stage billboards correctly against
|
|
332
|
+
* whichever camera is drawing. When no `Camera3d` viewport is supplied the
|
|
333
|
+
* billboard is inactive and the quad renders fixed-orientation.
|
|
334
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer
|
|
335
|
+
* @param {Camera2d} [viewport]
|
|
336
|
+
* @ignore
|
|
337
|
+
*/
|
|
338
|
+
draw(renderer: CanvasRenderer | WebGLRenderer, viewport?: Camera2d): void;
|
|
339
|
+
/**
|
|
340
|
+
* Orient the quad toward the camera when billboarding; otherwise defer to the
|
|
341
|
+
* standard {@link Mesh} world projection (a fixed-orientation quad).
|
|
342
|
+
* @ignore
|
|
343
|
+
*/
|
|
344
|
+
_projectVerticesWorld(offsetX: any, offsetY: any, offsetZ: any): void;
|
|
345
|
+
}
|
|
346
|
+
import Mesh from "./mesh.js";
|
|
347
|
+
import FrameAnimation from "./frameAnimation.js";
|
|
348
|
+
import Camera3d from "../camera/camera3d.ts";
|
|
349
|
+
import Texture2d from "../video/texture/texture2d.ts";
|
|
350
|
+
//# sourceMappingURL=sprite3d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sprite3d.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite3d.js"],"names":[],"mapp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
3
|
+
*
|
|
4
|
+
* The font descriptor uses the AngelCode BMFont format and may be supplied in
|
|
5
|
+
* either flavour — the **text** (`.fnt`) or the **XML** form — the
|
|
6
|
+
* serialisation is auto-detected, so packs that ship an `.xml` descriptor load
|
|
7
|
+
* as-is, with no conversion step. Load the descriptor as a `binary` asset and
|
|
8
|
+
* its page image as an `image` asset, then reference both by the same name.
|
|
3
9
|
* @category Text
|
|
4
10
|
*/
|
|
5
11
|
export default class BitmapText extends Renderable {
|
|
@@ -7,29 +13,32 @@ export default class BitmapText extends Renderable {
|
|
|
7
13
|
* @param {number} x - position of the text object
|
|
8
14
|
* @param {number} y - position of the text object
|
|
9
15
|
* @param {object} settings - the text configuration
|
|
10
|
-
* @param {string|Image} settings.font - a font name to identify the
|
|
11
|
-
* @param {string} [settings.fontData=settings.font] - the bitmap font data corresponding name, or the bitmap font data itself
|
|
16
|
+
* @param {string|Image} settings.font - a font name to identify the corresponding source image
|
|
17
|
+
* @param {string} [settings.fontData=settings.font] - the bitmap font data corresponding name, or the bitmap font data itself (AngelCode BMFont, `.fnt` text or `.xml`)
|
|
12
18
|
* @param {number} [settings.size] - size a scaling ratio
|
|
13
19
|
* @param {Color|string} [settings.fillStyle] - a CSS color value used to tint the bitmapText (@see BitmapText.tint)
|
|
14
20
|
* @param {number} [settings.lineWidth=1] - line width, in pixels, when drawing stroke
|
|
15
21
|
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
16
22
|
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
17
23
|
* @param {number} [settings.lineHeight=1.0] - line spacing height
|
|
18
|
-
* @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
|
|
24
|
+
* @param {string|Vector2d|{x:number,y:number}} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at. Also accepts the named presets `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`.
|
|
19
25
|
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
20
26
|
* @param {(string|string[])} [settings.text] - a string, or an array of strings
|
|
21
27
|
* @example
|
|
22
|
-
* //
|
|
28
|
+
* // Load the BMFont descriptor as a "binary" asset and its page as an "image".
|
|
29
|
+
* // Both the text (.fnt) and XML (.xml) BMFont flavours are accepted and
|
|
30
|
+
* // auto-detected, so an .xml descriptor can be used directly:
|
|
23
31
|
* loader.preload([
|
|
32
|
+
* // text (.fnt) BMFont
|
|
24
33
|
* { name: "arial", type: "binary", src: "data/font/arial.fnt" },
|
|
25
|
-
* { name: "arial", type: "image",
|
|
34
|
+
* { name: "arial", type: "image", src: "data/font/arial.png" },
|
|
35
|
+
* // XML BMFont (exported by many bitmap-font tools) — loaded as-is
|
|
36
|
+
* { name: "pixel", type: "binary", src: "data/font/pixel.xml" },
|
|
37
|
+
* { name: "pixel", type: "image", src: "data/font/pixel.png" },
|
|
26
38
|
* ])
|
|
27
39
|
* // Then create an instance of your bitmap font:
|
|
28
|
-
* let myFont = new BitmapText(x, y, {font:"arial", text:"Hello"});
|
|
29
|
-
* //
|
|
30
|
-
* // either call the draw function from your Renderable draw function
|
|
31
|
-
* myFont.draw(renderer, "Hello!", 0, 0);
|
|
32
|
-
* // or just add it to the world container
|
|
40
|
+
* let myFont = new BitmapText(x, y, { font: "arial", text: "Hello" });
|
|
41
|
+
* // add it to the world container
|
|
33
42
|
* app.world.addChild(myFont);
|
|
34
43
|
*/
|
|
35
44
|
constructor(x: number, y: number, settings: {
|
|
@@ -41,7 +50,10 @@ export default class BitmapText extends Renderable {
|
|
|
41
50
|
textAlign?: string | undefined;
|
|
42
51
|
textBaseline?: string | undefined;
|
|
43
52
|
lineHeight?: number | undefined;
|
|
44
|
-
anchorPoint?:
|
|
53
|
+
anchorPoint?: string | Vector2d | {
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
};
|
|
45
57
|
wordWrapWidth?: number | undefined;
|
|
46
58
|
text?: string | string[] | undefined;
|
|
47
59
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmaptext.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/bitmaptext.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bitmaptext.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/bitmaptext.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,eA/BW,MAAM,KACN,MAAM,YAEd;QAA+B,IAAI,EAA3B,MAAM,8DAAM;QACM,QAAQ;QACR,IAAI;QACE,SAAS;QACf,SAAS;QACT,SAAS;QACT,YAAY;QACZ,UAAU;QACmB,WAAW,GAA1D,MAAM,GAAC,QAAQ,GAAC;YAAC,CAAC,EAAC,MAAM,CAAC;YAAA,CAAC,EAAC,MAAM,CAAA;SAAC;QACjB,aAAa;QACF,IAAI;KACzC,EAkIF;IA7GA;;;;;;OAMG;IACH,kBAHU,MAAM,CAG6B;IAE7C;;;;;;OAMG;IACH,qBAHU,MAAM,CAGkC;IAElD;;;;;;OAMG;IACH,mBAHU,MAAM,CAG4B;IAE5C;;;;;;OAMG;IACH,sBAHU,MAAM,CAGiC;IAEjD;;;OAGG;IACH,cAAe;IAEf;;;OAGG;IACH,kBAA2C;IAE3C;;;OAGG;IACH,kBAG2B;IAG1B;;;OAGG;IAEH,iBAAgE;IA8MlE,4BANU,KAAK,EAad;IAhBD;;;;;OAKG;IACH,wBAHU,KAAK,CAKd;IA9KA;;OAEG;IACH,2BAA4B;IAG5B,qBAAoC;IAWrC;;;;;OAKG;IACH,eAJW,MAAM,UACN,MAAM,GACJ,UAAU,CAWtB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GAAC,MAAM,GAAC,MAAM,EAAE,GACpB,UAAU,CAqBtB;IAoBD,oCAdU,MAAM,EAmBf;IAvBD;;;;;;;;;;;;;OAaG;IACH,gCAVU,MAAM,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