melonjs 19.8.0 → 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 +3 -0
- package/build/application/application.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/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 +5 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3276 -594
- package/build/index.js.map +4 -4
- package/build/loader/cache.d.ts +1 -0
- package/build/loader/cache.d.ts.map +1 -1
- package/build/loader/loader.d.ts +61 -3
- 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/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/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/physics/adapter.d.ts +4 -3
- package/build/physics/adapter.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/collectable.d.ts +7 -1
- package/build/renderable/collectable.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/imagelayer.d.ts +5 -2
- package/build/renderable/imagelayer.d.ts.map +1 -1
- package/build/renderable/mesh.d.ts +26 -2
- 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 +6 -1
- package/build/renderable/renderable.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +10 -6
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/renderable/sprite3d.d.ts +41 -5
- package/build/renderable/sprite3d.d.ts.map +1 -1
- 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/system/event.d.ts +18 -2
- package/build/system/event.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 +41 -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 +2 -1
- 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_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 +1 -1
- 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 +0 -5
- 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/shadereffect.d.ts +183 -0
- package/build/video/webgl/shadereffect.d.ts.map +1 -1
- package/build/video/webgl/webgl_renderer.d.ts +41 -1
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -161,7 +161,7 @@ export default class Entity extends Renderable {
|
|
|
161
161
|
* @param {string} [settings.name] - object entity name
|
|
162
162
|
* @param {string} [settings.id] - object unique IDs
|
|
163
163
|
* @param {Image|string} [settings.image] - resource name of a spritesheet to use for the entity renderable component
|
|
164
|
-
* @param {Vector2d} [settings.anchorPoint=0.0] - Entity anchor point
|
|
164
|
+
* @param {string|Vector2d|{x:number,y:number}} [settings.anchorPoint=0.0] - Entity anchor point. Also accepts the named presets `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"`.
|
|
165
165
|
* @param {number} [settings.framewidth=settings.width] - width of a single frame in the given spritesheet
|
|
166
166
|
* @param {number} [settings.frameheight=settings.width] - height of a single frame in the given spritesheet
|
|
167
167
|
* @param {string} [settings.type] - object type
|
|
@@ -175,7 +175,10 @@ export default class Entity extends Renderable {
|
|
|
175
175
|
name?: string | undefined;
|
|
176
176
|
id?: string | undefined;
|
|
177
177
|
image?: string | (new (width?: number, height?: number) => HTMLImageElement) | undefined;
|
|
178
|
-
anchorPoint?:
|
|
178
|
+
anchorPoint?: string | Vector2d | {
|
|
179
|
+
x: number;
|
|
180
|
+
y: number;
|
|
181
|
+
};
|
|
179
182
|
framewidth?: number | undefined;
|
|
180
183
|
frameheight?: number | undefined;
|
|
181
184
|
type?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/renderable/entity/entity.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/renderable/entity/entity.js"],"names":[],"mappings":"AAQA;;;;;;;;IAQI;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6IG;AACH;IACC,mCAAkC;IAElC;;;;;;;;;;;;;;;;;OAiBG;IACH,eAjBW,MAAM,KACN,MAAM,YAGd;QAAyB,KAAK,EAAtB,MAAM;QACW,MAAM,EAAvB,MAAM;QACY,IAAI;QACJ,EAAE;QACI,KAAK;QACkB,WAAW,GAA1D,MAAM,GAAC,QAAQ,GAAC;YAAC,CAAC,EAAC,MAAM,CAAC;YAAA,CAAC,EAAC,MAAM,CAAA;SAAC;QACjB,UAAU;QACV,WAAW;QACX,IAAI;QACJ,aAAa;QACc,MAAM;KAC3D,EA0FF;IA9EA;;;OAGG;IACH,gBAAkB;IAqFnB,sBAPU,UAAU,EAmBnB;IArBD;;;OAGG;IAEH,kBAHU,UAAU,CAKnB;IAnDA;;;OAGG;IACH,IAFU,MAAM,CAEW;IAE3B;;;;OAIG;IACH,OAFU,OAAO,CAEA;IAwDlB,cAAc;IACd,yBAKC;IAED;;;;OAIG;IACH,wBAHW,OAAO,GACL,MAAM,CA0BlB;IAED;;OAEG;IACH,qBAEC;IAED,6BAkBC;IAoCD;;OAEG;IACH,0BAIC;CACD;uBA7YsB,kBAAkB;4BAQhB,2BAA2B;0BAH7B,iCAAiC;6BAE9B,6BAA6B;0BAHhC,4BAA4B;6BAEzB,+BAA+B"}
|
|
@@ -16,7 +16,7 @@ export default class ImageLayer extends Sprite {
|
|
|
16
16
|
* @param {number} [settings.z=0] - z-index position
|
|
17
17
|
* @param {number|Vector2d} [settings.ratio=1.0] - Scrolling ratio to be applied. See {@link ImageLayer#ratio}
|
|
18
18
|
* @param {"repeat"|"repeat-x"|"repeat-y"|"no-repeat"} [settings.repeat="repeat"] - define if and how an Image Layer should be repeated. See {@link ImageLayer#repeat}
|
|
19
|
-
* @param {number|Vector2d} [settings.anchorPoint=<0.0,0.0>] - Define how the image is anchored to the viewport bound. By default, its upper-left corner is anchored to the viewport bounds upper left corner.
|
|
19
|
+
* @param {number|string|Vector2d|{x:number,y:number}} [settings.anchorPoint=<0.0,0.0>] - Define how the image is anchored to the viewport bound. By default, its upper-left corner is anchored to the viewport bounds upper left corner. Also accepts the named presets `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`, `"bottom-left"`, `"bottom-right"` (anchored relative to the viewport, e.g. `"bottom"` = bottom-center of the viewport); a bare number anchors both axes.
|
|
20
20
|
* @example
|
|
21
21
|
* // create a repetitive background pattern on the X axis using the citycloud image asset
|
|
22
22
|
* app.world.addChild(new me.ImageLayer(0, 0, {
|
|
@@ -30,7 +30,10 @@ export default class ImageLayer extends Sprite {
|
|
|
30
30
|
z?: number | undefined;
|
|
31
31
|
ratio?: number | Vector2d | undefined;
|
|
32
32
|
repeat?: "repeat" | "no-repeat" | "repeat-x" | "repeat-y" | undefined;
|
|
33
|
-
anchorPoint?: number | Vector2d |
|
|
33
|
+
anchorPoint?: string | number | Vector2d | {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
} | undefined;
|
|
34
37
|
});
|
|
35
38
|
/**
|
|
36
39
|
* Define the image scrolling ratio<br>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"imagelayer.d.ts","sourceRoot":"","sources":["../../src/renderable/imagelayer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"imagelayer.d.ts","sourceRoot":"","sources":["../../src/renderable/imagelayer.js"],"names":[],"mappings":"AAaA;;;GAGG;AAEH;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;OAgBG;IACH,eAhBW,MAAM,KACN,MAAM,YAEd;QAA4E,KAAK,EAAzE,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,MAAM;QACvC,IAAI;QACJ,CAAC;QACQ,KAAK;QACsB,MAAM;QACN,WAAW;eAAvC,MAAM;eAAG,MAAM;;KACjD,EAgEF;IAlCA;;;;;;;;;OASG;IACH,OAHU,QAAQ,CAGqB;IAyCxC,kBAPU,MAAM,EA2Bf;IAnCD;;;;;;;;;;OAUG;IACH,cAHU,MAAM,CAKf;IAGA,4BAAoB;IAGlB,6BAAoB;IACpB,6BAAoB;IAkBvB,wBAsBC;IAED;;;;OAIG;IACH,UAHW,MAAM,KACN,MAAM,QAOhB;IAED;;;OAGG;IACH,sBAKC;IAJA,cAGC;IAGF;;;OAGG;IACH,oBA+CC;IAED;;;;;;;;;;;;;;;OAeG;IACH,6BAmBC;IAED;;;;;OAKG;IACH,yBAHW,cAAc,GAAC,aAAa,aAC5B,QAAQ,QAyElB;IAGD,0BAMC;CAWD;mBAxWkB,aAAa;8BAIL,qBAAqB"}
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
* mesh under a transformed parent to pivot elsewhere). Consequently, on the
|
|
16
16
|
* `Camera3d` world-space path the mesh opts out of the anchor offset entirely
|
|
17
17
|
* (see {@link Renderable#applyAnchorTransform}); the legacy 2D path still
|
|
18
|
-
* honors `anchorPoint` for backward compatibility.
|
|
18
|
+
* honors `anchorPoint` for backward compatibility. Subclasses that bake the
|
|
19
|
+
* anchor into their vertex data instead (e.g. {@link Sprite3d}, via the
|
|
20
|
+
* internal `_anchorBaked` flag) opt out on **both** paths — for those, the
|
|
21
|
+
* vertex bake is the single anchoring mechanism.
|
|
19
22
|
* @category Game Objects
|
|
20
23
|
*/
|
|
21
24
|
export default class Mesh extends Renderable {
|
|
@@ -35,7 +38,7 @@ export default class Mesh extends Renderable {
|
|
|
35
38
|
* @param {boolean} [settings.normalize=true] - fit the source geometry into a `[-0.5, 0.5]` unit cube before scaling, so `width`/`height` behave like a Sprite. Set `false` to keep the geometry's real-world coordinates — required when several meshes share one coordinate space (e.g. nodes of an imported glTF scene) so their relative scale and layout are preserved.
|
|
36
39
|
* @param {number} [settings.scale] - world-space scale (pixels per source unit) for the Camera3d path; defaults to `width`. Set this when `width`/`height` describe the renderable's world bounds (frustum culling) rather than the geometry scale — see {@link Mesh#meshScale}.
|
|
37
40
|
* @param {boolean} [settings.rightHanded=false] - treat the source as right-handed (Y-up, e.g. glTF) under the `Camera3d` world path. The default Y-up→Y-down bridge negates Y only (a reflection, which mirrors the scene left/right); `true` negates Y **and** Z (a rotation) so chirality is preserved and the result matches the authoring tool. See {@link Mesh#rightHanded}.
|
|
38
|
-
* @param {string} [settings.textureRepeat] - texture wrap mode (`"repeat"` / `"repeat-x"` / `"repeat-y"` / `"no-repeat"`)
|
|
41
|
+
* @param {string} [settings.textureRepeat] - texture wrap mode (`"repeat"` / `"repeat-x"` / `"repeat-y"` / `"no-repeat"`) this mesh samples its texture with (per-mesh — it does not modify the shared texture, so other meshes/sprites using the same image are unaffected). Use `"repeat"` when the geometry's UVs fall outside the `[0, 1]` range and rely on the texture tiling (e.g. glTF assets, whose default sampler wrap is REPEAT) — otherwise the texture clamps to its edge texels and looks flat. Ignored for the white-pixel fallback. Note: REPEAT on a non-power-of-two texture requires WebGL 2.
|
|
39
42
|
* @param {string} [settings.textureFilter] - texture magnification filter (`"nearest"` for crisp pixel-art upscaling, `"linear"` for smooth) applied to the resolved texture. Omit to keep the renderer's global `antiAlias` default. WebGL only (ignored by the Canvas renderer).
|
|
40
43
|
* @param {number} [settings.alphaCutoff=0] - alpha cutout threshold. Fragments whose final alpha is below this value are discarded (hard-edged cutout — foliage, fences, decals — with no blending or sorting). `0` disables the cutout. Set automatically by the glTF loader from a material's `alphaMode: "MASK"`. WebGL mesh path only.
|
|
41
44
|
* @param {number[]|Float32Array} [settings.emissive] - emissive (self-illumination) color `[r, g, b]` (0..1, may exceed 1 for HDR glow) added on top of the lit/unlit color so the surface glows regardless of scene lights (neon, lava, screens). Omit / all-zero for no emission. Set automatically by the glTF loader (`emissiveFactor`) and OBJ loader (MTL `Ke`). WebGL mesh path only.
|
|
@@ -238,6 +241,25 @@ export default class Mesh extends Renderable {
|
|
|
238
241
|
*/
|
|
239
242
|
vertexColors: Uint32Array;
|
|
240
243
|
texture: any;
|
|
244
|
+
/**
|
|
245
|
+
* Per-mesh texture wrap mode (`"repeat"` / `"repeat-x"` / `"repeat-y"`
|
|
246
|
+
* / `"no-repeat"`), or `undefined` to sample with the texture's own
|
|
247
|
+
* wrap. Some assets author UVs outside the `[0, 1]` range and rely on
|
|
248
|
+
* the sampler repeating the texture (this is the glTF default sampler
|
|
249
|
+
* behavior); the mesh would otherwise clamp to the edge texels and
|
|
250
|
+
* look flat / untextured.
|
|
251
|
+
*
|
|
252
|
+
* Kept on the mesh and threaded to the batcher at draw time — sampler
|
|
253
|
+
* state per use, like a GL sampler object — so it never mutates the
|
|
254
|
+
* per-image `TextureAtlas` shared with every other consumer of the
|
|
255
|
+
* same image (#1503). Two meshes (or a mesh and a sprite) can point
|
|
256
|
+
* at one image with different wrap modes; the texture cache keys GL
|
|
257
|
+
* units by `(source, repeat)` so each wrap gets its own GL texture.
|
|
258
|
+
* Applied only to a real texture — never the shared white-pixel
|
|
259
|
+
* fallback, which is global and must stay `"no-repeat"`.
|
|
260
|
+
* @type {string|undefined}
|
|
261
|
+
*/
|
|
262
|
+
textureRepeat: string | undefined;
|
|
241
263
|
/**
|
|
242
264
|
* Projection matrix applied automatically before the model transform in draw().
|
|
243
265
|
* Defaults to a perspective projection (45° FOV, camera at z=-2.5) suitable for
|
|
@@ -247,6 +269,8 @@ export default class Mesh extends Renderable {
|
|
|
247
269
|
*/
|
|
248
270
|
projectionMatrix: Matrix3d;
|
|
249
271
|
/** @ignore */
|
|
272
|
+
_anchorBaked: boolean;
|
|
273
|
+
/** @ignore */
|
|
250
274
|
_hullPoints: Vector2d[];
|
|
251
275
|
/** @ignore */
|
|
252
276
|
_hullPolygon: Polygon | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/renderable/mesh.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mesh.d.ts","sourceRoot":"","sources":["../../src/renderable/mesh.js"],"names":[],"mappings":"AAmHA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;IACH,eAhEW,MAAM,KACN,MAAM,YAEd;QAA0B,KAAK;QACU,QAAQ;QACR,GAAG;QACJ,OAAO;QACS,OAAO;QACrC,QAAQ;QACT,KAAK,EAAtB,MAAM;QACY,MAAM;QACL,aAAa;QACb,SAAS;QACV,KAAK;QACJ,WAAW;QACZ,aAAa;QACb,aAAa;QACb,WAAW;QACI,QAAQ;KACjD,EAwbF;IAjYC;;;OAGG;IACH,kBAFU,YAAY,CAEkB;IAExC;;;OAGG;IACH,KAFU,YAAY,CAEA;IAQtB;;;OAGG;IACH,aAFU,MAAM,CAEsB;IAmCvC,2BAAo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AkI/B;;;;;;;;;;;;OAYG;IACH,YATa,iBAAiB,CAoH7B;IAED;;;;;;;OAOG;IACH,iBALa,OAAO,CAAC,WAAW,CAAC,CAOhC;CACD;uBA3hCsB,iBAAiB;sBAZlB,kBAAkB;yBACf,qBAAqB;yBACrB,qBAAqB;wBAJtB,0BAA0B;uBAU3B,iCAAiC;6BAE3B,6BAA6B"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* additional import for TypeScript
|
|
3
|
-
* @import {Color} from "./../math/color.ts";
|
|
4
|
-
* @import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
5
|
-
*/
|
|
6
1
|
/**
|
|
7
2
|
* A NineSliceSprite is similar to a Sprite, but it uses 9-slice scaling to stretch its inner area to fit the size of the Renderable,
|
|
8
3
|
* by proportionally scaling a sprite by splitting it in a grid of nine parts (with only parts 1, 3, 7, 9 not being scaled). <br>
|
|
@@ -27,7 +22,7 @@ export default class NineSliceSprite extends Sprite {
|
|
|
27
22
|
* @param {string|Color} [settings.tint] - a tint to be applied to this sprite
|
|
28
23
|
* @param {number} [settings.flipX] - flip the sprite on the horizontal axis
|
|
29
24
|
* @param {number} [settings.flipY] - flip the sprite on the vertical axis
|
|
30
|
-
* @param {Vector2d} [settings.anchorPoint={x:0.5, y:0.5}] - Anchor point to draw the frame at (defaults to the center of the frame).
|
|
25
|
+
* @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"`.
|
|
31
26
|
* @example
|
|
32
27
|
* this.panelSprite = new me.NineSliceSprite(0, 0, {
|
|
33
28
|
* image : game.texture,
|
|
@@ -49,7 +44,10 @@ export default class NineSliceSprite extends Sprite {
|
|
|
49
44
|
tint?: string | Color | undefined;
|
|
50
45
|
flipX?: number | undefined;
|
|
51
46
|
flipY?: number | undefined;
|
|
52
|
-
anchorPoint?:
|
|
47
|
+
anchorPoint?: string | Vector2d | {
|
|
48
|
+
x: number;
|
|
49
|
+
y: number;
|
|
50
|
+
};
|
|
53
51
|
});
|
|
54
52
|
set width(value: number);
|
|
55
53
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nineslicesprite.d.ts","sourceRoot":"","sources":["../../src/renderable/nineslicesprite.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"nineslicesprite.d.ts","sourceRoot":"","sources":["../../src/renderable/nineslicesprite.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,eAxBW,MAAM,KACN,MAAM,YAEd;QAAyB,KAAK,EAAtB,MAAM;QACW,MAAM,EAAvB,MAAM;QACY,MAAM;QACN,MAAM;QACyD,KAAK,EAAtF,gBAAgB,GAAC,iBAAiB,GAAC,YAAY,GAAC,eAAe,GAAC,MAAM;QACpD,IAAI;QACJ,MAAM;QACN,UAAU;QACV,WAAW;QACL,IAAI;QACV,KAAK;QACL,KAAK;QACwB,WAAW,GAA1D,MAAM,GAAC,QAAQ,GAAC;YAAC,CAAC,EAAC,MAAM,CAAC;YAAA,CAAC,EAAC,MAAM,CAAA;SAAC;KAC3C,EA8BF;IASD,iBALU,MAAM,EAOf;IATD;;;OAGG;IACH,aAFU,MAAM,CAIf;IAYD,kBALU,MAAM,EAOf;IATD;;;OAGG;IACH,cAFU,MAAM,CAIf;IAxBA,kBAA2B;IAC3B,mBAA6B;IAE7B,2BAA6B;IAC7B,2BAA6B;IAkD9B;;OAEG;IACH,0BAyEC;CACD;mBAvMkB,aAAa;kCAKC,6BAA6B;2BADtC,oBAAoB"}
|
|
@@ -25,7 +25,12 @@ export default class Renderable extends Rect {
|
|
|
25
25
|
* a Renderable's anchor point defaults to (0.5,0.5), which corresponds to the center position.<br>
|
|
26
26
|
* <br>
|
|
27
27
|
* <i><b>Note:</b> Object created through Tiled will have their anchorPoint set to (0, 0) to match Tiled Level editor implementation.
|
|
28
|
-
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`. </i>
|
|
28
|
+
* To specify a value through Tiled, use a json expression like `json:{"x":0.5,"y":0.5}`, or (since 19.9) a plain string preset such as `bottom`. </i>
|
|
29
|
+
* <br>
|
|
30
|
+
* At construction time, `settings.anchorPoint` also accepts the named presets
|
|
31
|
+
* `"center"`, `"top"`, `"bottom"`, `"left"`, `"right"`, `"top-left"`, `"top-right"`,
|
|
32
|
+
* `"bottom-left"`, `"bottom-right"` on every renderable that consumes it
|
|
33
|
+
* (Sprite, Entity, Collectable, ImageLayer, Text, BitmapText, Sprite3d and subclasses).
|
|
29
34
|
* @type {ObservablePoint}
|
|
30
35
|
* @default <0.5,0.5>
|
|
31
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderable.d.ts","sourceRoot":"","sources":["../../src/renderable/renderable.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;IAaI;AAEJ;;;GAGG;AACH;IAkBG,iBAAmB;IAGpB
|
|
1
|
+
{"version":3,"file":"renderable.d.ts","sourceRoot":"","sources":["../../src/renderable/renderable.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;IAaI;AAEJ;;;GAGG;AACH;IAkBG,iBAAmB;IAGpB;;;;;;;;;;;;;;;OAeG;IACH,aAHU,eAAe,CAMvB;IAGD;;;;;;;OAOG;IACH,kBAFU,QAAQ,CAEoB;IAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;IACH,MAlCU,WAAW,CAkCA;IAErB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAHU,MAAM,GAAC,SAAS,CAGF;IAExB;;;;;OAKG;IACH,MAFU,MAAM,CAEK;IAErB;;;;;;;;;;OAUG;IACH,6BAAmC;IAEnC;;;;OAIG;IACH,cAHU,OAAO,CAGQ;IAEz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M,CAwClB;IAED;;;;;;;;OAQG;IACH,uBAFa,QAAQ,CAYpB;IAED;;;;;;OAMG;IACH,kBAFW,cAAc,GAAC,aAAa,QA+DtC;IAED;;;;;;;;;;;;OAYG;IAEH,eAJW,cAAc,GAAC,aAAa,aAC5B,QAAQ,QAKlB;IAED;;;;;OAKG;IACH,mBAFW,cAAc,GAAC,aAAa,QAqBtC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,0CAZa,OAAO,CAoBnB;IAkCD;;;OAGG;IACH,8BA6DC;IAED;;;;;;OAMG;IACH,yBAFc,GAAC,EAAA,QAId;IAED;;;;;;;OAOG;IACH,0BAFc,GAAC,EAAA,QAId;IAED;;;;;;OAMG;IACH,4BAFc,GAAC,EAAA,QAId;CACD;qBApnCoB,8BAA8B;gCADnB,kCAAkC;yBAKzC,qBAAqB;2BAWpB,gBAAgB;wBADnB,oBAAoB;+BAKf,8BAA8B;6BADhC,0BAA0B;0BAF7B,yBAAyB;6BACtB,4BAA4B;6BAG1B,iCAAiC;gCAC9B,sCAAsC;+BACvC,oCAAoC"}
|
|
@@ -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,8 +60,11 @@ 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
69
|
_frameAnim: FrameAnimation;
|
|
67
70
|
/**
|
|
@@ -366,5 +369,6 @@ import FrameAnimation from "./frameAnimation.js";
|
|
|
366
369
|
import type { Vector2d } from "../math/vector2d.js";
|
|
367
370
|
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
368
371
|
import type Renderer from "./../video/renderer.js";
|
|
372
|
+
import Texture2d from "./../video/texture/texture2d.ts";
|
|
369
373
|
import { Color } from "../math/color.ts";
|
|
370
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA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a,MAAM,CAelB;IAED;;;;;;;;;;;OAWG;IACH,kBAVW,MAAM,wBAEJ,MAAM,CAoBlB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,mBAzBW,MAAM,SACN,MAAM,EAAE,GAAC,MAAM,EAAE,GAAC,MAAM,EAAE,mBAC1B,MAAM,GACJ,MAAM,CAwBlB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,0BAlCW,MAAM,cACN,MAAM,WAAS,gBACf,OAAO,GACL,MAAM,CAkClB;IAED;;;;;OAKG;IACH,wBAJW,MAAM,GACJ,MAAM,CASlB;IAED;;;;;;;;OAQG;IACH,yBAPW,MAAM,GACJ,OAAO,CAQnB;IAED;;;;;;;;OAQG;IACH,qBANa,MAAM,EAAE,CAQpB;IAED;;;;;;;;OAQG;IACH,kBANW,MAAM,GACJ,MAAM,CAQlB;IAED;;;;;;OAMG;IACH,oBAHW,MAAM,QA0ChB;IAED;;;;;;;OAOG;IACH,0BANW,MAAM,GACJ,MAAM,CAQlB;IAED;;;OAGG;IACH,4BAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,mCAHW,MAAM,GACJ,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"}
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
* world-space path; under a 2D `Camera2d` it falls back to the mesh's
|
|
25
25
|
* self-projection and **billboarding has no effect** (a 2D scene has no camera
|
|
26
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"`, …).
|
|
27
35
|
* @augments Mesh
|
|
28
36
|
* @category Game Objects
|
|
29
37
|
* @example
|
|
@@ -57,13 +65,22 @@
|
|
|
57
65
|
* coin.setCurrentAnimation("spin");
|
|
58
66
|
* coin.flipX(); // face the other way (mirrors the sprite)
|
|
59
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
|
+
* });
|
|
60
77
|
*/
|
|
61
78
|
export default class Sprite3d extends Mesh {
|
|
62
79
|
/**
|
|
63
80
|
* @param {number} x - world x position
|
|
64
81
|
* @param {number} y - world y position
|
|
65
82
|
* @param {object} settings - configuration
|
|
66
|
-
* @param {HTMLImageElement|
|
|
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`.
|
|
67
84
|
* @param {number} [settings.width=settings.framewidth] - quad width in world units (pixels)
|
|
68
85
|
* @param {number} [settings.height=settings.width] - quad height in world units
|
|
69
86
|
* @param {number} [settings.framewidth] - width of a single frame within a spritesheet (enables frame animation)
|
|
@@ -72,6 +89,7 @@ export default class Sprite3d extends Mesh {
|
|
|
72
89
|
* @param {object[]} [settings.anims] - predefined animations (same shape as {@link Sprite})
|
|
73
90
|
* @param {number} [settings.z=0] - 3D depth (world z); also settable later via `.depth`
|
|
74
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.
|
|
75
93
|
* @param {boolean} [settings.flipX=false] - mirror the sprite horizontally (see {@link Sprite3d#flipX})
|
|
76
94
|
* @param {boolean} [settings.flipY=false] - mirror the sprite vertically (see {@link Sprite3d#flipY})
|
|
77
95
|
* @param {boolean} [settings.lit=false] - shade through the lit mesh batcher (see {@link Mesh})
|
|
@@ -79,7 +97,7 @@ export default class Sprite3d extends Mesh {
|
|
|
79
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.
|
|
80
98
|
*/
|
|
81
99
|
constructor(x: number, y: number, settings: {
|
|
82
|
-
image?: string | HTMLImageElement |
|
|
100
|
+
image?: string | HTMLImageElement | Texture2d | undefined;
|
|
83
101
|
width?: number | undefined;
|
|
84
102
|
height?: number | undefined;
|
|
85
103
|
framewidth?: number | undefined;
|
|
@@ -88,6 +106,10 @@ export default class Sprite3d extends Mesh {
|
|
|
88
106
|
anims?: object[] | undefined;
|
|
89
107
|
z?: number | undefined;
|
|
90
108
|
billboard?: string | boolean | undefined;
|
|
109
|
+
anchorPoint?: string | Vector2d | {
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
};
|
|
91
113
|
flipX?: boolean | undefined;
|
|
92
114
|
flipY?: boolean | undefined;
|
|
93
115
|
lit?: boolean | undefined;
|
|
@@ -103,6 +125,10 @@ export default class Sprite3d extends Mesh {
|
|
|
103
125
|
/** @ignore */
|
|
104
126
|
_halfH: number;
|
|
105
127
|
/** @ignore */
|
|
128
|
+
_anchorOffsetX: number;
|
|
129
|
+
/** @ignore */
|
|
130
|
+
_anchorOffsetY: number;
|
|
131
|
+
/** @ignore */
|
|
106
132
|
_refLw: number;
|
|
107
133
|
/** @ignore */
|
|
108
134
|
_refLh: number;
|
|
@@ -147,6 +173,15 @@ export default class Sprite3d extends Mesh {
|
|
|
147
173
|
billboard: boolean | string;
|
|
148
174
|
/** the camera captured at draw time for the billboard projection @ignore */
|
|
149
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;
|
|
150
185
|
/**
|
|
151
186
|
* defined animations, keyed by id (see {@link Sprite3d#addAnimation}).
|
|
152
187
|
* @type {object}
|
|
@@ -277,8 +312,9 @@ export default class Sprite3d extends Mesh {
|
|
|
277
312
|
* {@link Sprite}'s sub-texture / size / anchor swap). Rewrites both the quad's
|
|
278
313
|
* UVs (the atlas sub-rect, with a 90° corner permutation for packer-rotated
|
|
279
314
|
* regions) and its local vertices (the trimmed art's sub-rectangle within the
|
|
280
|
-
* logical frame, scaled into the quad's world footprint
|
|
281
|
-
* rotated `TextureAtlas` regions render at
|
|
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`.
|
|
282
318
|
* @param {object} region - the texture region object
|
|
283
319
|
* @ignore
|
|
284
320
|
*/
|
|
@@ -310,5 +346,5 @@ export default class Sprite3d extends Mesh {
|
|
|
310
346
|
import Mesh from "./mesh.js";
|
|
311
347
|
import FrameAnimation from "./frameAnimation.js";
|
|
312
348
|
import Camera3d from "../camera/camera3d.ts";
|
|
313
|
-
import
|
|
349
|
+
import Texture2d from "../video/texture/texture2d.ts";
|
|
314
350
|
//# sourceMappingURL=sprite3d.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprite3d.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite3d.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sprite3d.d.ts","sourceRoot":"","sources":["../../src/renderable/sprite3d.js"],"names":[],"mappings":"AAmEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH;IACC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAnBW,MAAM,KACN,MAAM,YAEd;QAAqD,KAAK;QAChC,KAAK;QACL,MAAM;QACN,UAAU;QACV,WAAW;QACX,MAAM;QACJ,KAAK;QACP,CAAC;QACO,SAAS;QACY,WAAW,GAA1D,MAAM,GAAC,QAAQ,GAAC;YAAC,CAAC,EAAC,MAAM,CAAC;YAAA,CAAC,EAAC,MAAM,CAAA;SAAC;QAChB,KAAK;QACL,KAAK;QACL,GAAG;QACW,QAAQ;QACvB,WAAW;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AED;;;;;OAKG;IACH,YAJW,MAAM,YACN,MAAM,cAAU,MAAM,GACpB,QAAQ,CAQpB;IAED;;;OAGG;IACH,SAFa,QAAQ,CAKpB;IAED;;;OAGG;IACH,QAFa,QAAQ,CAMpB;IAED;;;;OAIG;IACH,0BAHW,MAAM,GACJ,QAAQ,CAKpB;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACJ,QAAQ,CAKpB;IAED;;;OAGG;IACH,yBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;OAEG;IACH,qBAFa,MAAM,EAAE,CAIpB;IAED;;OAEG;IACH,4BAFa,MAAM,CAIlB;IAED;;;;;OAKG;IACH,mCAJW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;;;;;;;;OAWG;IACH,oBAHW,MAAM,QA2GhB;IAgBD;;;;OAIG;IACH,gBAIC;IAED;;;;;;;;;OASG;IACH,eAJW,cAAc,GAAC,aAAa,aAC5B,QAAQ,QAMlB;IAED;;;;OAIG;IACH,sEA4DC;CACD;iBAx2BgB,WAAW;2BADD,qBAAqB;qBAL3B,uBAAuB;sBAGtB,+BAA+B"}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* a bitmap font object
|
|
2
|
+
* a bitmap font object.
|
|
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;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format in both its
|
|
4
|
+
* text (`.fnt`) and XML serialisations (the flavour is auto-detected).
|
|
4
5
|
* @category Text
|
|
5
6
|
*/
|
|
6
7
|
export default class BitmapTextData {
|
|
@@ -18,6 +19,28 @@ export default class BitmapTextData {
|
|
|
18
19
|
};
|
|
19
20
|
constructor(data: string);
|
|
20
21
|
parse(fontData: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Record a parsed glyph and fold it into the font's vertical metrics.
|
|
24
|
+
* @ignore
|
|
25
|
+
*/
|
|
26
|
+
recordGlyph(glyph: Glyph, baseLine: number): void;
|
|
27
|
+
/**
|
|
28
|
+
* Look up a glyph by char code, honestly typed as possibly missing (the
|
|
29
|
+
* glyph map's index signature otherwise hides that a lookup can be absent).
|
|
30
|
+
* @ignore
|
|
31
|
+
*/
|
|
32
|
+
glyphFor(id: number): Glyph | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Parse the AngelCode BMFont text (.fnt) format.
|
|
35
|
+
* @ignore
|
|
36
|
+
*/
|
|
37
|
+
parseText(fontData: string): void;
|
|
38
|
+
/**
|
|
39
|
+
* Parse the AngelCode BMFont XML format (same data as the .fnt text form).
|
|
40
|
+
* Padding is optional in XML exports (e.g. frostyfreeze) and defaults to 0.
|
|
41
|
+
* @ignore
|
|
42
|
+
*/
|
|
43
|
+
parseXML(fontData: string): void;
|
|
21
44
|
}
|
|
22
45
|
export declare const bitmapTextDataPool: import("../../system/pool.ts").Pool<BitmapTextData, [fontData: string]>;
|
|
23
46
|
//# sourceMappingURL=bitmaptextdata.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitmaptextdata.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/bitmaptextdata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AA8E/B
|
|
1
|
+
{"version":3,"file":"bitmaptextdata.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/bitmaptextdata.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AA8E/B;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IAClC,MAAM,EAAE,MAAM,CAAK;IACnB,QAAQ,EAAE,MAAM,CAAK;IACrB,SAAS,EAAE,MAAM,CAAK;IACtB,OAAO,EAAE,MAAM,CAAK;IACpB,UAAU,EAAE,MAAM,CAAK;IACvB,SAAS,EAAE,MAAM,CAAK;IACtB,OAAO,EAAE,MAAM,CAAK;IACpB,WAAW,EAAE,MAAM,CAAK;IACxB,cAAc,EAAE,MAAM,CAAK;IAC3B,MAAM,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAA;KAAE,CAAM;gBAE1B,IAAI,EAAE,MAAM;IAIxB,KAAK,CAAC,QAAQ,EAAE,MAAM;IAqDtB;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM;IAY1C;;;;OAIG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAIvC;;;OAGG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM;IA6C1B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM;CAwDzB;AAED,eAAO,MAAM,kBAAkB,yEAY7B,CAAC"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* a
|
|
2
|
+
* a Text object: draws a string using a system or web font.
|
|
3
|
+
*
|
|
4
|
+
* The text is rasterised to a cached texture, so it draws as fast as a sprite
|
|
5
|
+
* while staying fully styleable — `fillStyle`, `strokeStyle` + `lineWidth`, and
|
|
6
|
+
* per-object opacity — with multi-line text (embedded `\n`), optional
|
|
7
|
+
* `wordWrapWidth` word-wrapping, and chainable {@link Text#bold} /
|
|
8
|
+
* {@link Text#italic}. `font` accepts any CSS family, including the generic
|
|
9
|
+
* keywords (`sans-serif`, `monospace`, …); a web font loaded through the
|
|
10
|
+
* `fontface` loader is referenced by its family name.
|
|
11
|
+
*
|
|
12
|
+
* For a crisp, tintable, retro look — or large amounts of mostly-static text —
|
|
13
|
+
* consider {@link BitmapText} instead.
|
|
3
14
|
* @category Text
|
|
4
15
|
*/
|
|
5
16
|
export default class Text extends Renderable {
|
|
@@ -7,19 +18,43 @@ export default class Text extends Renderable {
|
|
|
7
18
|
* @param {number} x - position of the text object
|
|
8
19
|
* @param {number} y - position of the text object
|
|
9
20
|
* @param {object} settings - the text configuration
|
|
10
|
-
* @param {string} settings.font - a CSS family font name
|
|
11
|
-
* @param {number|string} settings.size - size, or size
|
|
12
|
-
* @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
|
|
13
|
-
* @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
|
|
14
|
-
* @param {number} [settings.lineWidth=0] -
|
|
15
|
-
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
16
|
-
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
21
|
+
* @param {string} settings.font - a CSS font family: a specific name (`"Arial"`), a generic keyword (`"sans-serif"`, `"monospace"`, …), or a web font loaded via the `fontface` loader (referenced by its family name)
|
|
22
|
+
* @param {number|string} settings.size - the font size: a number in pixels, or a CSS size string with a unit (`"24px"` / `"1.5em"` / `"18pt"`)
|
|
23
|
+
* @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value used to fill the glyphs
|
|
24
|
+
* @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value used for the glyph outline (drawn when `lineWidth` > 0)
|
|
25
|
+
* @param {number} [settings.lineWidth=0] - outline width in pixels (0 = no stroke)
|
|
26
|
+
* @param {string} [settings.textAlign="left"] - horizontal text alignment ("left", "center", "right")
|
|
27
|
+
* @param {string} [settings.textBaseline="top"] - the text baseline ("top", "hanging", "middle", "alphabetic", "ideographic", "bottom")
|
|
17
28
|
* @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
|
|
19
|
-
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS
|
|
29
|
+
* @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"`.
|
|
30
|
+
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixels of a line before it wraps
|
|
20
31
|
* @param {(string|string[])} [settings.text=""] - a string, or an array of strings
|
|
21
32
|
* @example
|
|
22
|
-
*
|
|
33
|
+
* // a styled, word-wrapped, multi-line label using a generic system font
|
|
34
|
+
* const label = new Text(8, 8, {
|
|
35
|
+
* font: "sans-serif", // any CSS family (generic keywords work too)
|
|
36
|
+
* size: 24, // number (px) or a "1.5em" / "18pt" string
|
|
37
|
+
* fillStyle: "#ffffff",
|
|
38
|
+
* strokeStyle: "#202020",
|
|
39
|
+
* lineWidth: 2, // outline the glyphs
|
|
40
|
+
* textAlign: "left",
|
|
41
|
+
* textBaseline: "top",
|
|
42
|
+
* wordWrapWidth: 200, // wrap lines longer than 200px
|
|
43
|
+
* text: "Hello melonJS!\nStyled, wrapped, multi-line text.",
|
|
44
|
+
* });
|
|
45
|
+
* label.bold(); // bold() / italic() are chainable
|
|
46
|
+
* label.setOpacity(0.8); // per-object transparency
|
|
47
|
+
* app.world.addChild(label);
|
|
48
|
+
* @example
|
|
49
|
+
* // a web font (loaded via the fontface loader) is used by its family name
|
|
50
|
+
* loader.preload(
|
|
51
|
+
* [{ name: "kenpixel", type: "fontface", src: "data/font/kenvector.woff2" }],
|
|
52
|
+
* () => {
|
|
53
|
+
* app.world.addChild(
|
|
54
|
+
* new Text(0, 0, { font: "kenpixel", size: 32, text: "Web font" }),
|
|
55
|
+
* );
|
|
56
|
+
* },
|
|
57
|
+
* );
|
|
23
58
|
*/
|
|
24
59
|
constructor(x: number, y: number, settings: {
|
|
25
60
|
font: string;
|
|
@@ -30,7 +65,10 @@ export default class Text extends Renderable {
|
|
|
30
65
|
textAlign?: string | undefined;
|
|
31
66
|
textBaseline?: string | undefined;
|
|
32
67
|
lineHeight?: number | undefined;
|
|
33
|
-
anchorPoint?:
|
|
68
|
+
anchorPoint?: string | Vector2d | {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
};
|
|
34
72
|
wordWrapWidth?: number | undefined;
|
|
35
73
|
text?: string | string[] | undefined;
|
|
36
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/text.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/renderable/text/text.js"],"names":[],"mappings":"AAuCA;;;;;;;;;;;;;;GAcG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACH,eAzCW,MAAM,KACN,MAAM,YAEd;QAAyB,IAAI,EAArB,MAAM;QACkB,IAAI,EAA5B,MAAM,GAAC,MAAM;QACW,SAAS;QACT,WAAW;QACjB,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,EAmGF;IApEA;;;;OAIG;IACH,WAHU,KAAK,CAGwB;IAEvC;;;;OAIG;IACH,aAHU,KAAK,CAG0B;IAEzC;;;;OAIG;IACH,WAHU,MAAM,CAGE;IAElB;;;;;OAKG;IACH,WAHU,MAAM,CAGO;IAEvB;;;;;OAKG;IACH,cAHU,MAAM,CAGS;IAEzB;;;;;OAKG;IACH,YAHU,MAAM,CAGK;IAErB;;;;;OAKG;IACH,eAHU,MAAM,CAGO;IAEvB;;;;OAIG;IACH,UAHU,MAAM,CAGE;IAElB;;;OAGG;IACH,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