littlejsengine 1.18.19 → 1.18.22
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 +15 -1
- package/dist/littlejs.d.ts +215 -20
- package/dist/littlejs.esm.js +709 -58
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +690 -57
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +687 -57
- package/package.json +1 -1
- package/plugins/box2d.js +12 -11
- package/plugins/newgrounds.js +2 -1
- package/plugins/pluginExport.js +18 -1
- package/plugins/postProcess.js +5 -4
- package/plugins/textureSheet.js +439 -0
- package/plugins/threejs.js +155 -0
- package/plugins/tweenSystem.js +5 -1
- package/plugins/uiSystem.js +4 -3
- package/src/engine.js +6 -2
- package/src/engineAudio.js +2 -2
- package/src/engineBuild.mjs +4 -2
- package/src/engineDebug.js +3 -0
- package/src/engineDraw.js +32 -14
- package/src/engineInput.js +8 -4
- package/src/engineMath.js +2 -2
- package/src/engineParticles.js +5 -6
- package/src/engineSettings.js +1 -0
- package/src/engineTileLayer.js +10 -6
- package/src/engineUtilities.js +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ The code is very clean and well documented with many examples to get you started
|
|
|
38
38
|
- Blazing fast WebGL2 + Canvas2D hybrid rendering system
|
|
39
39
|
- Apply [Shadertoy](https://www.shadertoy.com) style shaders for post-processing effects
|
|
40
40
|
- Robust particle effect system and [effect design tool](https://killedbyapixel.github.io/LittleJS/examples/particles/)
|
|
41
|
+
- Optional 3D rendering with the [Three.js](https://threejs.org) plugin
|
|
41
42
|
|
|
42
43
|
### 🔊 Audio
|
|
43
44
|
|
|
@@ -73,6 +74,18 @@ The code is very clean and well documented with many examples to get you started
|
|
|
73
74
|
- Medal tracking system with [Newgrounds](https://www.newgrounds.com/) support
|
|
74
75
|
- Node.js build system
|
|
75
76
|
|
|
77
|
+
### 🤖 AI Friendly
|
|
78
|
+
|
|
79
|
+
- The entire API is small and well documented so LLMs can produce high quality results
|
|
80
|
+
- [LittleJS AI Tools](https://github.com/KilledByAPixel/LittleJS-AI) - Templates, examples, and prompts tuned for AI + LittleJS workflows
|
|
81
|
+
- [LittleJS GPT](https://chatgpt.com/g/g-67c7c080b5bc81919736bc8815836be6-littlejs-game-maker) - Build LittleJS games right inside ChatGPT
|
|
82
|
+
|
|
83
|
+
### 🧊 3D with Three.js
|
|
84
|
+
|
|
85
|
+
- Optional [Three.js](https://threejs.org) plugin renders a 3D scene behind the LittleJS canvas
|
|
86
|
+
- 2D camera and 3D camera stay aligned so sprites and meshes share the same world space
|
|
87
|
+
- LittleJS physics drive Three.js meshes with `ThreeJSObject`
|
|
88
|
+
|
|
76
89
|
## How To Use LittleJS
|
|
77
90
|
|
|
78
91
|
To get started download the latest LittleJS package from GitHub or install via npm:
|
|
@@ -113,7 +126,6 @@ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
|
|
|
113
126
|
- [LittleJS Quick Reference Sheet](https://github.com/KilledByAPixel/LittleJS/blob/main/REFERENCE.md) - A reference sheet to help you get started.
|
|
114
127
|
- [Little JS FAQ](https://github.com/KilledByAPixel/LittleJS/blob/main/FAQ.md) - Answers to common questions about LittleJS.
|
|
115
128
|
- [JS13k Branch](https://github.com/KilledByAPixel/LittleJS/tree/js13k) - For size coding events like JS13k there is a special branch that builds to a 7KB zip.
|
|
116
|
-
- [LittleJS AI Tools](https://github.com/KilledByAPixel/LittleJS-AI) - Experiments, games, and templates to improve LittleJS + AI workflows.
|
|
117
129
|
|
|
118
130
|
## Examples
|
|
119
131
|
|
|
@@ -126,6 +138,8 @@ LittleJS comes with several demos both for learning and using as starter project
|
|
|
126
138
|
- [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
|
|
127
139
|
- [Platformer](https://killedbyapixel.github.io/LittleJS/examples/platformer/) - Platformer/shooter demo that loads level data
|
|
128
140
|
- [Box2D Demo](https://killedbyapixel.github.io/LittleJS/examples/box2d/) - Box2D plugin demonstration and testbed
|
|
141
|
+
- [Three.js Side Scroller](https://killedbyapixel.github.io/LittleJS/examples/threejs/sideScroller/) - 3D rendering with Three.js behind the 2D canvas
|
|
142
|
+
- [Three.js Platformer](https://killedbyapixel.github.io/LittleJS/examples/threejs/platformer/) - 3D platformer with LittleJS gameplay and Three.js rendering
|
|
129
143
|
- [Stress Test](https://killedbyapixel.github.io/LittleJS/examples/stress/) - Sprite rendering benchmark and music system demo
|
|
130
144
|
- [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
|
|
131
145
|
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -606,6 +606,7 @@ declare module "littlejsengine" {
|
|
|
606
606
|
* @memberof Settings */
|
|
607
607
|
export let soundEnable: boolean;
|
|
608
608
|
/** Volume scale to apply to all sound, music and speech
|
|
609
|
+
* Use setSoundVolume to also update the audio master gain immediately
|
|
609
610
|
* @type {number}
|
|
610
611
|
* @default
|
|
611
612
|
* @memberof Settings */
|
|
@@ -1481,7 +1482,7 @@ declare module "littlejsengine" {
|
|
|
1481
1482
|
*/
|
|
1482
1483
|
export class Timer {
|
|
1483
1484
|
/** Create a timer object set time passed in
|
|
1484
|
-
* @param {number} [timeLeft] - How much time left before the timer
|
|
1485
|
+
* @param {number} [timeLeft] - How much time left before the timer is elapsed in seconds (undefined = unset)
|
|
1485
1486
|
* @param {boolean} [useRealTime] - Should the timer keep running even when the game is paused? (useful for UI) */
|
|
1486
1487
|
constructor(timeLeft?: number, useRealTime?: boolean);
|
|
1487
1488
|
useRealTime: boolean;
|
|
@@ -1668,8 +1669,9 @@ declare module "littlejsengine" {
|
|
|
1668
1669
|
* @param {TextureInfo} [textureInfo] - Texture info to use
|
|
1669
1670
|
* @param {number} [padding] - How many pixels padding around all sides of each tile (increases grid size, does not affect tile size)
|
|
1670
1671
|
* @param {number} [bleed] - How many pixels smaller to shrink UVS of tiles (does not affect grid size, only UVs)
|
|
1672
|
+
* @param {number} [columns] - How many frames per row for frame(), 0 to keep frames on a single row
|
|
1671
1673
|
*/
|
|
1672
|
-
constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number);
|
|
1674
|
+
constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number, columns?: number);
|
|
1673
1675
|
/** @property {Vector2} - Top left corner of tile in pixels */
|
|
1674
1676
|
pos: Vector2;
|
|
1675
1677
|
/** @property {Vector2} - Size of tile in pixels */
|
|
@@ -1680,28 +1682,36 @@ declare module "littlejsengine" {
|
|
|
1680
1682
|
textureInfo: TextureInfo;
|
|
1681
1683
|
/** @property {number} - Shrinks tile by this many pixels to prevent neighbors bleeding */
|
|
1682
1684
|
bleed: number;
|
|
1685
|
+
/** @property {number} - How many frames per row for frame(), 0 to keep frames on a single row */
|
|
1686
|
+
columns: number;
|
|
1683
1687
|
/** Returns a copy of this tile offset by a vector
|
|
1684
1688
|
* @param {Vector2} offset - Offset to apply in pixels
|
|
1685
1689
|
* @return {TileInfo}
|
|
1686
1690
|
*/
|
|
1687
1691
|
offset(offset: Vector2): TileInfo;
|
|
1688
1692
|
/** Returns a copy of this tile offset by a number of animation frames
|
|
1693
|
+
* Frames wrap down to the next row if columns is set
|
|
1689
1694
|
* @param {number} frame - Offset to apply in animation frames
|
|
1690
1695
|
* @return {TileInfo}
|
|
1691
1696
|
*/
|
|
1692
1697
|
frame(frame: number): TileInfo;
|
|
1698
|
+
/** Set how many frames per row this tile uses, so frame() can wrap
|
|
1699
|
+
* @param {number} [columns] - Frames per row, 0 to keep frames on a single row
|
|
1700
|
+
* @return {TileInfo}
|
|
1701
|
+
*/
|
|
1702
|
+
setColumns(columns?: number): TileInfo;
|
|
1693
1703
|
/**
|
|
1694
|
-
*
|
|
1695
|
-
* @param {
|
|
1704
|
+
* Returns a tile info for an index using this tile as reference
|
|
1705
|
+
* @param {Vector2|number} [index=0]
|
|
1696
1706
|
* @return {TileInfo}
|
|
1697
1707
|
*/
|
|
1698
|
-
|
|
1708
|
+
index(index?: Vector2 | number): TileInfo;
|
|
1699
1709
|
/**
|
|
1700
|
-
*
|
|
1701
|
-
* @param {
|
|
1710
|
+
* Set this tile to use a full image in a texture info
|
|
1711
|
+
* @param {TextureInfo} [textureInfo]
|
|
1702
1712
|
* @return {TileInfo}
|
|
1703
1713
|
*/
|
|
1704
|
-
|
|
1714
|
+
setFullImage(textureInfo?: TextureInfo): TileInfo;
|
|
1705
1715
|
}
|
|
1706
1716
|
/**
|
|
1707
1717
|
* Tile Info - Stores info about each texture
|
|
@@ -2660,9 +2670,9 @@ declare module "littlejsengine" {
|
|
|
2660
2670
|
* @param {number} [rate] - How quickly to speak
|
|
2661
2671
|
* @param {number} [pitch] - How much to change the pitch by
|
|
2662
2672
|
* @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
|
|
2663
|
-
* @return {SpeechSynthesisUtterance} - The utterance that was spoken
|
|
2673
|
+
* @return {SpeechSynthesisUtterance|undefined} - The utterance that was spoken, or undefined if speech is unavailable
|
|
2664
2674
|
* @memberof Audio */
|
|
2665
|
-
export function speak(text: string, volume?: number, rate?: number, pitch?: number, language?: string): SpeechSynthesisUtterance;
|
|
2675
|
+
export function speak(text: string, volume?: number, rate?: number, pitch?: number, language?: string): SpeechSynthesisUtterance | undefined;
|
|
2666
2676
|
/** Stop all queued speech
|
|
2667
2677
|
* @memberof Audio */
|
|
2668
2678
|
export function speakStop(): void;
|
|
@@ -2684,7 +2694,7 @@ declare module "littlejsengine" {
|
|
|
2684
2694
|
* @param {number} [pan] - How much to apply stereo panning
|
|
2685
2695
|
* @param {boolean} [loop] - True if the sound should loop when it reaches the end
|
|
2686
2696
|
* @param {number} [sampleRate=44100] - Sample rate for the sound
|
|
2687
|
-
* @param {GainNode} [gainNode] - Optional gain node for volume control while playing
|
|
2697
|
+
* @param {GainNode} [gainNode] - Optional gain node for volume control while playing (disconnected when the sound ends)
|
|
2688
2698
|
* @param {number} [offset] - Offset in seconds to start playback from
|
|
2689
2699
|
* @param {AudioEndedCallback} [onended] - Callback for when the sound ends
|
|
2690
2700
|
* @return {AudioBufferSourceNode} - The source node of the sound played, may be undefined if play fails
|
|
@@ -3068,7 +3078,7 @@ declare module "littlejsengine" {
|
|
|
3068
3078
|
* @param {boolean} [useWebGL] - Should this layer use WebGL for rendering
|
|
3069
3079
|
*/
|
|
3070
3080
|
constructor(pos: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number, useWebGL?: boolean);
|
|
3071
|
-
/** @property {Array<TileLayerData>} -
|
|
3081
|
+
/** @property {Array<TileLayerData>} - Array of tile data for the layer */
|
|
3072
3082
|
data: TileLayerData[];
|
|
3073
3083
|
/** @property {boolean} - Is this layer using a webgl texture? */
|
|
3074
3084
|
isUsingWebGL: boolean;
|
|
@@ -3225,8 +3235,8 @@ declare module "littlejsengine" {
|
|
|
3225
3235
|
* rgb(1,1,1,1), rgb(0,0,0,1), // colorStartA, colorStartB
|
|
3226
3236
|
* rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
|
|
3227
3237
|
* 1, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
|
|
3228
|
-
* .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate
|
|
3229
|
-
* .5, 1 // randomness, collide
|
|
3238
|
+
* .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate
|
|
3239
|
+
* .5, 1 // randomness, collide
|
|
3230
3240
|
* );
|
|
3231
3241
|
*/
|
|
3232
3242
|
export class ParticleEmitter extends EngineObject {
|
|
@@ -3572,7 +3582,7 @@ declare module "littlejsengine" {
|
|
|
3572
3582
|
* @memberof PostProcess */
|
|
3573
3583
|
export let postProcess: PostProcessPlugin;
|
|
3574
3584
|
/**
|
|
3575
|
-
*
|
|
3585
|
+
* Post Process Plugin - Applies a full screen shader to the rendered output
|
|
3576
3586
|
* @memberof PostProcess
|
|
3577
3587
|
*/
|
|
3578
3588
|
export class PostProcessPlugin {
|
|
@@ -3910,8 +3920,8 @@ declare module "littlejsengine" {
|
|
|
3910
3920
|
* @return {number} */
|
|
3911
3921
|
getNavigationDirection(): number;
|
|
3912
3922
|
/** Get other axis navigation direction from gamepad or keyboard
|
|
3913
|
-
* @return {
|
|
3914
|
-
getNavigationOtherDirection():
|
|
3923
|
+
* @return {number} */
|
|
3924
|
+
getNavigationOtherDirection(): number;
|
|
3915
3925
|
/** Get if navigation button was pressed from gamepad or keyboard
|
|
3916
3926
|
* @return {boolean} */
|
|
3917
3927
|
getNavigationWasPressed(): boolean;
|
|
@@ -4111,7 +4121,7 @@ declare module "littlejsengine" {
|
|
|
4111
4121
|
maxLength: number;
|
|
4112
4122
|
text: string;
|
|
4113
4123
|
click(): void;
|
|
4114
|
-
/** Stop editing the text
|
|
4124
|
+
/** Stop editing the text */
|
|
4115
4125
|
stopEditing(): void;
|
|
4116
4126
|
/** Key down event handler if this object is being edited
|
|
4117
4127
|
* @param {KeyboardEvent} [e] */
|
|
@@ -4170,7 +4180,7 @@ declare module "littlejsengine" {
|
|
|
4170
4180
|
* @param {Color} [color=uiSystem.defaultButtonColor]
|
|
4171
4181
|
*/
|
|
4172
4182
|
constructor(pos?: Vector2, size?: Vector2, checked?: boolean, text?: string, color?: Color);
|
|
4173
|
-
/** @property {boolean} -
|
|
4183
|
+
/** @property {boolean} - Is the checkbox currently checked? */
|
|
4174
4184
|
checked: boolean;
|
|
4175
4185
|
text: string;
|
|
4176
4186
|
click(): void;
|
|
@@ -4390,7 +4400,7 @@ declare module "littlejsengine" {
|
|
|
4390
4400
|
* @param {number} [lineWidth]
|
|
4391
4401
|
* @param {boolean} [useWebGL=glEnable]
|
|
4392
4402
|
* @param {CanvasRenderingContext2D} [context] */
|
|
4393
|
-
drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number,
|
|
4403
|
+
drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, useWebGL?: boolean, context?: CanvasRenderingContext2D): void;
|
|
4394
4404
|
/** converts a box2d vec2 to a Vector2
|
|
4395
4405
|
* @param {Object} v */
|
|
4396
4406
|
vec2From(v: any): Vector2;
|
|
@@ -5707,4 +5717,189 @@ declare module "littlejsengine" {
|
|
|
5707
5717
|
/** True if walkable and not blocked by cost. */
|
|
5708
5718
|
isClear(): boolean;
|
|
5709
5719
|
}
|
|
5720
|
+
/**
|
|
5721
|
+
* LittleJS Three.js Plugin
|
|
5722
|
+
* - Renders a three.js scene on a canvas behind the LittleJS canvases
|
|
5723
|
+
* - The three.js module is passed in by the user, nothing is bundled
|
|
5724
|
+
* - Keep canvasClearColor transparent so the 3D scene shows through
|
|
5725
|
+
* - Aligned camera mode locks the 3D camera to the LittleJS 2D camera
|
|
5726
|
+
* - ThreeJSObject lets LittleJS physics drive a three.js mesh
|
|
5727
|
+
* - Call new ThreeJSPlugin(THREE) in gameInit to set up
|
|
5728
|
+
* @namespace ThreeJS
|
|
5729
|
+
*/
|
|
5730
|
+
/** Global ThreeJS plugin object
|
|
5731
|
+
* @type {ThreeJSPlugin}
|
|
5732
|
+
* @memberof ThreeJS */
|
|
5733
|
+
export let threeJS: ThreeJSPlugin;
|
|
5734
|
+
/**
|
|
5735
|
+
* ThreeJS Plugin - Renders a three.js scene behind the LittleJS canvas
|
|
5736
|
+
* @example
|
|
5737
|
+
* // in gameInit, with three.js loaded by the user
|
|
5738
|
+
* new ThreeJSPlugin(THREE);
|
|
5739
|
+
* threeJS.scene.add(new THREE.AmbientLight);
|
|
5740
|
+
* @memberof ThreeJS
|
|
5741
|
+
*/
|
|
5742
|
+
export class ThreeJSPlugin {
|
|
5743
|
+
/** Set up the three.js rendering layer, call in gameInit
|
|
5744
|
+
* @param {Object} THREE - The three.js module, supplied by the user
|
|
5745
|
+
* @param {number} [cameraFOV] - Vertical field of view in degrees */
|
|
5746
|
+
constructor(THREE: any, cameraFOV?: number);
|
|
5747
|
+
/** @property {Object} - The three.js module passed into the constructor */
|
|
5748
|
+
THREE: any;
|
|
5749
|
+
/** @property {Object} - The three.js renderer */
|
|
5750
|
+
renderer: any;
|
|
5751
|
+
/** @property {Object} - The three.js scene, add lights and meshes here */
|
|
5752
|
+
scene: any;
|
|
5753
|
+
/** @property {Object} - The three.js perspective camera */
|
|
5754
|
+
camera: any;
|
|
5755
|
+
/** @property {boolean} - Lock the camera to the LittleJS 2D camera so the z=0 plane matches world space */
|
|
5756
|
+
cameraAlign2D: boolean;
|
|
5757
|
+
/** Position the camera so the z=0 plane exactly matches LittleJS world space,
|
|
5758
|
+
* called automatically when cameraAlign2D is set */
|
|
5759
|
+
alignCamera2D(): void;
|
|
5760
|
+
/** Sync the canvas layout and render the scene, called automatically each frame */
|
|
5761
|
+
render(): void;
|
|
5762
|
+
}
|
|
5763
|
+
/**
|
|
5764
|
+
* ThreeJS Object - EngineObject that drives a three.js mesh
|
|
5765
|
+
* - LittleJS physics moves the object and the mesh follows automatically
|
|
5766
|
+
* - Destroying the object removes the mesh from the scene
|
|
5767
|
+
* @extends EngineObject
|
|
5768
|
+
* @memberof ThreeJS
|
|
5769
|
+
*/
|
|
5770
|
+
export class ThreeJSObject extends EngineObject {
|
|
5771
|
+
/** Create an engine object that drives a three.js mesh
|
|
5772
|
+
* @param {Vector2} [pos] - World space position
|
|
5773
|
+
* @param {Vector2} [size] - World space size
|
|
5774
|
+
* @param {Object} [mesh] - The three.js object3d to drive
|
|
5775
|
+
* @param {number} [z] - Mesh height above the 2D plane */
|
|
5776
|
+
constructor(pos?: Vector2, size?: Vector2, mesh?: any, z?: number);
|
|
5777
|
+
/** @property {Object} - The three.js object3d this object drives */
|
|
5778
|
+
mesh: any;
|
|
5779
|
+
/** @property {number} - Mesh height above the 2D plane */
|
|
5780
|
+
z: number;
|
|
5781
|
+
/** Copy this object's transform to the mesh */
|
|
5782
|
+
syncMesh(): void;
|
|
5783
|
+
}
|
|
5784
|
+
/**
|
|
5785
|
+
* LittleJS Texture Sheet Plugin
|
|
5786
|
+
* - Packs images into texture sheets as they are loaded
|
|
5787
|
+
* - Sprites are placed automatically, callers get a TileInfo
|
|
5788
|
+
* - Sheets are created and filled as needed
|
|
5789
|
+
* - Sheets fill in call order, images decode in parallel
|
|
5790
|
+
* - Animation frames keep layout and wrap across rows as needed
|
|
5791
|
+
* - WebGL textures upload once per batch of loads
|
|
5792
|
+
* - loadAtlas imports pre-packed atlases (TexturePacker and Aseprite json)
|
|
5793
|
+
* @namespace TextureSheets
|
|
5794
|
+
*/
|
|
5795
|
+
/** Width and height in pixels of texture sheets created by loadSprite
|
|
5796
|
+
* @type {number}
|
|
5797
|
+
* @default
|
|
5798
|
+
* @memberof Settings */
|
|
5799
|
+
export let textureSheetSize: number;
|
|
5800
|
+
/** Default padding pixels around each frame packed by loadSprite
|
|
5801
|
+
* @type {number}
|
|
5802
|
+
* @default
|
|
5803
|
+
* @memberof Settings */
|
|
5804
|
+
export let textureSheetPadding: number;
|
|
5805
|
+
/** Set width and height in pixels of texture sheets created by loadSprite
|
|
5806
|
+
* @param {number} size
|
|
5807
|
+
* @memberof Settings */
|
|
5808
|
+
export function setTextureSheetSize(size: number): void;
|
|
5809
|
+
/** Set default padding pixels around each frame packed by loadSprite
|
|
5810
|
+
* @param {number} padding
|
|
5811
|
+
* @memberof Settings */
|
|
5812
|
+
export function setTextureSheetPadding(padding: number): void;
|
|
5813
|
+
/** Array of texture sheets created by loadSprite
|
|
5814
|
+
* @type {Array<TextureSheet>}
|
|
5815
|
+
* @memberof TextureSheets */
|
|
5816
|
+
export let textureSheets: Array<TextureSheet>;
|
|
5817
|
+
/**
|
|
5818
|
+
* Texture Sheet - A texture that images are packed into as they load
|
|
5819
|
+
* Uses shelf packing, images are placed left to right then wrap to a new row
|
|
5820
|
+
* @memberof TextureSheets
|
|
5821
|
+
*/
|
|
5822
|
+
export class TextureSheet {
|
|
5823
|
+
/** Create a texture sheet, called automatically by loadSprite
|
|
5824
|
+
* @param {number} [size] - Width and height of the sheet in pixels */
|
|
5825
|
+
constructor(size?: number);
|
|
5826
|
+
/** @property {number} - Width and height of the sheet in pixels */
|
|
5827
|
+
size: number;
|
|
5828
|
+
/** @property {OffscreenCanvas} - Canvas holding the packed images */
|
|
5829
|
+
canvas: OffscreenCanvas;
|
|
5830
|
+
/** @property {OffscreenCanvasRenderingContext2D} - 2d context for the canvas */
|
|
5831
|
+
context: OffscreenCanvasRenderingContext2D;
|
|
5832
|
+
/** @property {TextureInfo} - The texture info for this sheet */
|
|
5833
|
+
textureInfo: TextureInfo;
|
|
5834
|
+
/** @property {Vector2} - Where the next image will be packed */
|
|
5835
|
+
cursor: Vector2;
|
|
5836
|
+
/** @property {number} - Height of the row being packed */
|
|
5837
|
+
rowHeight: number;
|
|
5838
|
+
/** @property {boolean} - Has the canvas changed since the last webgl upload? */
|
|
5839
|
+
glDirty: boolean;
|
|
5840
|
+
/** Find a spot for an image on this sheet without drawing it
|
|
5841
|
+
* @param {Vector2} imageSize - Size of the source image in pixels
|
|
5842
|
+
* @param {Vector2} [frameSize] - Size of each frame, or the whole image if not passed
|
|
5843
|
+
* @param {number} [padding] - How many pixels padding around each frame
|
|
5844
|
+
* @return {TileInfo} Tile for the packed image, or undefined if the sheet is full */
|
|
5845
|
+
tryAdd(imageSize: Vector2, frameSize?: Vector2, padding?: number): TileInfo;
|
|
5846
|
+
/** Draw an image into this sheet at a tile returned by tryAdd
|
|
5847
|
+
* @param {HTMLImageElement} image - Source image to copy from
|
|
5848
|
+
* @param {TileInfo} tileInfo - Where to put it, from tryAdd
|
|
5849
|
+
* @param {boolean} [update] - Upload to webgl now, pass false when batching */
|
|
5850
|
+
drawImage(image: HTMLImageElement, tileInfo: TileInfo, update?: boolean): void;
|
|
5851
|
+
/** Upload the canvas to webgl if it has changed since the last upload
|
|
5852
|
+
* Only needed after batching, drawImage uploads automatically by default */
|
|
5853
|
+
updateTexture(): void;
|
|
5854
|
+
}
|
|
5855
|
+
/** Load an image and pack it into a texture sheet
|
|
5856
|
+
* - Returns a TileInfo immediately which is filled in when the image loads
|
|
5857
|
+
* - Nothing is visible until it loads, use spritesReady to wait for it
|
|
5858
|
+
* - Pass frameSize for animations, then step through them with TileInfo.frame
|
|
5859
|
+
* - Grid images keep their layout and frames wrap down to the next row
|
|
5860
|
+
* @param {string} src - Image source path
|
|
5861
|
+
* @param {Vector2|number} [frameSize] - Size of each animation frame in pixels
|
|
5862
|
+
* @param {number} [padding] - How many pixels padding around each frame
|
|
5863
|
+
* @return {TileInfo}
|
|
5864
|
+
* @example
|
|
5865
|
+
* const playerTile = loadSprite('player.png'); // a single sprite
|
|
5866
|
+
* const runTile = loadSprite('run.png', vec2(16)); // a 16x16 frame animation
|
|
5867
|
+
* @memberof TextureSheets */
|
|
5868
|
+
export function loadSprite(src: string, frameSize?: Vector2 | number, padding?: number): TileInfo;
|
|
5869
|
+
/** Load a pre-packed texture atlas and repack it onto texture sheets
|
|
5870
|
+
* - Supports TexturePacker json (hash and array) and Aseprite json
|
|
5871
|
+
* - Returns an empty object which is filled with TileInfos when loaded
|
|
5872
|
+
* - Frames are named by the json, animations are grouped automatically
|
|
5873
|
+
* - Aseprite frame tags become animations, so do names like run_0, run_1
|
|
5874
|
+
* - Trimmed frames are restored to their full source size when packed
|
|
5875
|
+
* - Rotated frames are rotated back upright when packed
|
|
5876
|
+
* @param {string} imageSrc - Atlas image path
|
|
5877
|
+
* @param {string|Object} jsonSrc - Atlas json path, or already parsed json data
|
|
5878
|
+
* @param {number} [padding] - How many pixels padding around each frame
|
|
5879
|
+
* @return {Object} Object mapping frame and animation names to TileInfos
|
|
5880
|
+
* @example
|
|
5881
|
+
* const atlas = loadAtlas('sprites.png', 'sprites.json');
|
|
5882
|
+
* await spritesReady();
|
|
5883
|
+
* drawTile(pos, size, atlas.player); // a single frame
|
|
5884
|
+
* drawTile(pos, size, atlas.run.frame(2)); // frame 2 of the run animation
|
|
5885
|
+
* @memberof TextureSheets */
|
|
5886
|
+
export function loadAtlas(imageSrc: string, jsonSrc: string | any, padding?: number): any;
|
|
5887
|
+
/** Parse atlas json into a list of named frame groups, used by loadAtlas
|
|
5888
|
+
* - Accepts TexturePacker json (hash and array) and Aseprite json
|
|
5889
|
+
* - Frames tagged in Aseprite or named like run_0, run_1 group into animations
|
|
5890
|
+
* @param {Object} data - Parsed atlas json data
|
|
5891
|
+
* @return {Array<Object>} List of {name, frames} groups in atlas order
|
|
5892
|
+
* @memberof TextureSheets */
|
|
5893
|
+
export function parseAtlas(data: any): Array<any>;
|
|
5894
|
+
/** Wait for everything started by loadSprite and loadAtlas to finish packing
|
|
5895
|
+
* @return {Promise}
|
|
5896
|
+
* @example
|
|
5897
|
+
* async function gameInit()
|
|
5898
|
+
* {
|
|
5899
|
+
* playerTile = loadSprite('player.png');
|
|
5900
|
+
* runTile = loadSprite('run.png', vec2(16));
|
|
5901
|
+
* await spritesReady();
|
|
5902
|
+
* }
|
|
5903
|
+
* @memberof TextureSheets */
|
|
5904
|
+
export function spritesReady(): Promise<any>;
|
|
5710
5905
|
}
|