littlejsengine 1.14.16 → 1.14.19
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/dist/littlejs.d.ts +55 -32
- package/dist/littlejs.esm.js +393 -227
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +393 -227
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +393 -227
- package/examples/box2d/game.js +3 -2
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +5 -5
- package/examples/electron/game.js +2 -2
- package/examples/electron/index.html +2 -2
- package/examples/index.html +57 -49
- package/examples/module/game.js +2 -2
- package/examples/platformer/gameEffects.js +1 -1
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/musicPlayer.js +1 -0
- package/examples/shorts/parallax.js +1 -1
- package/examples/shorts/sequencer.js +2 -2
- package/examples/shorts/shader.js +29 -0
- package/examples/shorts/tileLayer.js +1 -1
- package/examples/shorts/tiltedView.js +14 -6
- package/examples/shorts/topDown.js +1 -1
- package/examples/starter/game.js +2 -2
- package/examples/starter/index.html +2 -2
- package/examples/style.css +1 -0
- package/examples/typescript/game.js +2 -2
- package/examples/typescript/game.ts +1 -1
- package/examples/uiSystem/game.js +1 -0
- package/package.json +1 -1
- package/plugins/postProcess.js +71 -51
- package/plugins/uiSystem.js +76 -23
- package/src/engine.js +28 -14
- package/src/engineAudio.js +20 -10
- package/src/engineDraw.js +35 -29
- package/src/engineParticles.js +1 -1
- package/src/engineTileLayer.js +31 -39
- package/src/engineWebGL.js +134 -63
package/dist/littlejs.d.ts
CHANGED
|
@@ -165,10 +165,12 @@ declare module "littlejsengine" {
|
|
|
165
165
|
* @memberof Engine
|
|
166
166
|
*/
|
|
167
167
|
/** Add a new update function for a plugin
|
|
168
|
-
* @param {PluginCallback} [
|
|
169
|
-
* @param {PluginCallback} [
|
|
168
|
+
* @param {PluginCallback} [update]
|
|
169
|
+
* @param {PluginCallback} [render]
|
|
170
|
+
* @param {PluginCallback} [glContextLost]
|
|
171
|
+
* @param {PluginCallback} [glContextRestored]
|
|
170
172
|
* @memberof Engine */
|
|
171
|
-
export function engineAddPlugin(
|
|
173
|
+
export function engineAddPlugin(update?: PluginCallback, render?: PluginCallback, glContextLost?: PluginCallback, glContextRestored?: PluginCallback): void;
|
|
172
174
|
/**
|
|
173
175
|
* LittleJS Debug System
|
|
174
176
|
* - Press Esc to show debug overlay with mouse pick
|
|
@@ -1340,12 +1342,11 @@ declare module "littlejsengine" {
|
|
|
1340
1342
|
*/
|
|
1341
1343
|
frame(frame: number): TileInfo;
|
|
1342
1344
|
/**
|
|
1343
|
-
* Set this tile to use a full image
|
|
1344
|
-
* @param {
|
|
1345
|
-
* @param {WebGLTexture} [glTexture] - WebGL texture
|
|
1345
|
+
* Set this tile to use a full image in a texture info
|
|
1346
|
+
* @param {TextureInfo} textureInfo
|
|
1346
1347
|
* @return {TileInfo}
|
|
1347
1348
|
*/
|
|
1348
|
-
setFullImage(
|
|
1349
|
+
setFullImage(textureInfo: TextureInfo): TileInfo;
|
|
1349
1350
|
}
|
|
1350
1351
|
/**
|
|
1351
1352
|
* Tile Info - Stores info about each texture
|
|
@@ -1355,18 +1356,24 @@ declare module "littlejsengine" {
|
|
|
1355
1356
|
/**
|
|
1356
1357
|
* Create a TextureInfo, called automatically by the engine
|
|
1357
1358
|
* @param {HTMLImageElement|OffscreenCanvas} image
|
|
1358
|
-
* @param {
|
|
1359
|
+
* @param {boolean} [useWebGL] - Should use WebGL if available?
|
|
1359
1360
|
*/
|
|
1360
|
-
constructor(image: HTMLImageElement | OffscreenCanvas,
|
|
1361
|
-
/** @property {HTMLImageElement} - image source */
|
|
1361
|
+
constructor(image: HTMLImageElement | OffscreenCanvas, useWebGL?: boolean);
|
|
1362
|
+
/** @property {HTMLImageElement|OffscreenCanvas} - image source */
|
|
1362
1363
|
image: OffscreenCanvas | HTMLImageElement;
|
|
1363
1364
|
/** @property {Vector2} - size of the image */
|
|
1364
1365
|
size: Vector2;
|
|
1365
1366
|
/** @property {Vector2} - inverse of the size, cached for rendering */
|
|
1366
1367
|
sizeInverse: Vector2;
|
|
1367
1368
|
/** @property {WebGLTexture} - WebGL texture */
|
|
1368
|
-
glTexture:
|
|
1369
|
+
glTexture: any;
|
|
1370
|
+
/** Creates the WebGL texture, updates if already created */
|
|
1369
1371
|
createWebGLTexture(): void;
|
|
1372
|
+
/** Destroys the WebGL texture */
|
|
1373
|
+
destroyWebGLTexture(): void;
|
|
1374
|
+
/** Check if the texture is webgl enabled
|
|
1375
|
+
* @return {boolean} */
|
|
1376
|
+
hasWebGL(): boolean;
|
|
1370
1377
|
}
|
|
1371
1378
|
/**
|
|
1372
1379
|
* LittleJS Drawing System
|
|
@@ -1553,10 +1560,11 @@ declare module "littlejsengine" {
|
|
|
1553
1560
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
1554
1561
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
1555
1562
|
* @param {string} [font=fontDefault]
|
|
1563
|
+
* @param {string} [fontStyle]
|
|
1556
1564
|
* @param {number} [maxWidth]
|
|
1557
1565
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
|
|
1558
1566
|
* @memberof Draw */
|
|
1559
|
-
export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, maxWidth?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1567
|
+
export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1560
1568
|
/** Draw text on overlay canvas in world space
|
|
1561
1569
|
* Automatically splits new lines into rows
|
|
1562
1570
|
* @param {string} text
|
|
@@ -1567,9 +1575,10 @@ declare module "littlejsengine" {
|
|
|
1567
1575
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
1568
1576
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
1569
1577
|
* @param {string} [font=fontDefault]
|
|
1578
|
+
* @param {string} [fontStyle]
|
|
1570
1579
|
* @param {number} [maxWidth]
|
|
1571
1580
|
* @memberof Draw */
|
|
1572
|
-
export function drawTextOverlay(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, maxWidth?: number): void;
|
|
1581
|
+
export function drawTextOverlay(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number): void;
|
|
1573
1582
|
/** Draw text on overlay canvas in screen space
|
|
1574
1583
|
* Automatically splits new lines into rows
|
|
1575
1584
|
* @param {string} text
|
|
@@ -1580,10 +1589,11 @@ declare module "littlejsengine" {
|
|
|
1580
1589
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
1581
1590
|
* @param {CanvasTextAlign} [textAlign]
|
|
1582
1591
|
* @param {string} [font=fontDefault]
|
|
1592
|
+
* @param {string} [fontStyle]
|
|
1583
1593
|
* @param {number} [maxWidth]
|
|
1584
1594
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
1585
1595
|
* @memberof Draw */
|
|
1586
|
-
export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, maxWidth?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1596
|
+
export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1587
1597
|
/** Enable normal or additive blend mode
|
|
1588
1598
|
* @param {boolean} [additive]
|
|
1589
1599
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
@@ -1609,11 +1619,11 @@ declare module "littlejsengine" {
|
|
|
1609
1619
|
*/
|
|
1610
1620
|
export class FontImage {
|
|
1611
1621
|
/** Create an image font
|
|
1612
|
-
* @param {HTMLImageElement} [image]
|
|
1613
|
-
* @param {Vector2} [tileSize=(8,8)]
|
|
1614
|
-
* @param {Vector2} [paddingSize=(0,1)] - How much
|
|
1622
|
+
* @param {HTMLImageElement} [image] - Image for the font, default if undefined
|
|
1623
|
+
* @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
|
|
1624
|
+
* @param {Vector2} [paddingSize=(0,1)] - How much space between characters
|
|
1615
1625
|
*/
|
|
1616
|
-
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2
|
|
1626
|
+
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2);
|
|
1617
1627
|
image: any;
|
|
1618
1628
|
tileSize: Vector2;
|
|
1619
1629
|
paddingSize: Vector2;
|
|
@@ -2154,7 +2164,7 @@ declare module "littlejsengine" {
|
|
|
2154
2164
|
* @param {GainNode} [gainNode] - Optional gain node for volume control while playing
|
|
2155
2165
|
* @param {number} [offset] - Offset in seconds to start playback from
|
|
2156
2166
|
* @param {AudioEndedCallback} [onended] - Callback for when the sound ends
|
|
2157
|
-
* @return {AudioBufferSourceNode} - The
|
|
2167
|
+
* @return {AudioBufferSourceNode} - The source node of the sound played, may be undefined if play fails
|
|
2158
2168
|
* @memberof Audio */
|
|
2159
2169
|
export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number, gainNode?: GainNode, offset?: number, onended?: AudioEndedCallback): AudioBufferSourceNode;
|
|
2160
2170
|
/** Generate and play a ZzFX sound
|
|
@@ -2445,8 +2455,7 @@ declare module "littlejsengine" {
|
|
|
2445
2455
|
canvas: OffscreenCanvas;
|
|
2446
2456
|
/** @property {OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this layer */
|
|
2447
2457
|
context: OffscreenCanvasRenderingContext2D;
|
|
2448
|
-
|
|
2449
|
-
glTexture: WebGLTexture;
|
|
2458
|
+
textureInfo: TextureInfo;
|
|
2450
2459
|
/** Draw this canvas layer centered in world space, with color applied if using WebGL
|
|
2451
2460
|
* @param {Vector2} pos - Center in world space
|
|
2452
2461
|
* @param {Vector2} [size] - Size in world space
|
|
@@ -2506,9 +2515,8 @@ declare module "littlejsengine" {
|
|
|
2506
2515
|
* @param {Vector2} size - World space size
|
|
2507
2516
|
* @param {TileInfo} [tileInfo] - Default tile info for layer (used for size and texture)
|
|
2508
2517
|
* @param {number} [renderOrder] - Objects are sorted by renderOrder
|
|
2509
|
-
* @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
2510
2518
|
*/
|
|
2511
|
-
constructor(position: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number
|
|
2519
|
+
constructor(position: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number);
|
|
2512
2520
|
data: TileLayerData[];
|
|
2513
2521
|
/** Draw all the tile data to an offscreen canvas
|
|
2514
2522
|
* - This may be slow in some browsers but only needs to be done once */
|
|
@@ -2595,7 +2603,7 @@ declare module "littlejsengine" {
|
|
|
2595
2603
|
* tile(0, 16), // tileInfo
|
|
2596
2604
|
* rgb(1,1,1,1), rgb(0,0,0,1), // colorStartA, colorStartB
|
|
2597
2605
|
* rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
|
|
2598
|
-
*
|
|
2606
|
+
* 1, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
|
|
2599
2607
|
* .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
|
|
2600
2608
|
* .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
|
|
2601
2609
|
* );
|
|
@@ -2881,17 +2889,16 @@ declare module "littlejsengine" {
|
|
|
2881
2889
|
/** Create global post processing shader
|
|
2882
2890
|
* @param {string} shaderCode
|
|
2883
2891
|
* @param {boolean} [includeOverlay]
|
|
2892
|
+
* @param {boolean} [includeMainCanvas]
|
|
2884
2893
|
* @example
|
|
2885
2894
|
* // create the post process plugin object
|
|
2886
2895
|
* new PostProcessPlugin(shaderCode);
|
|
2887
2896
|
*/
|
|
2888
|
-
constructor(shaderCode: string, includeOverlay?: boolean);
|
|
2897
|
+
constructor(shaderCode: string, includeOverlay?: boolean, includeMainCanvas?: boolean);
|
|
2889
2898
|
/** @property {WebGLProgram} - Shader for post processing */
|
|
2890
|
-
shader:
|
|
2899
|
+
shader: any;
|
|
2891
2900
|
/** @property {WebGLTexture} - Texture for post processing */
|
|
2892
|
-
texture:
|
|
2893
|
-
/** @property {boolean} - Should overlay canvas be included in post processing */
|
|
2894
|
-
includeOverlay: boolean;
|
|
2901
|
+
texture: any;
|
|
2895
2902
|
}
|
|
2896
2903
|
/**
|
|
2897
2904
|
* LittleJS ZzFXM Plugin
|
|
@@ -2980,6 +2987,8 @@ declare module "littlejsengine" {
|
|
|
2980
2987
|
defaultHoverColor: Color;
|
|
2981
2988
|
/** @property {Color} - Default color for disabled UI elements */
|
|
2982
2989
|
defaultDisabledColor: Color;
|
|
2990
|
+
/** @property {Color} - Uses a gradient fill combined with color */
|
|
2991
|
+
defaultGradientColor: any;
|
|
2983
2992
|
/** @property {number} - Default line width for UI elements */
|
|
2984
2993
|
defaultLineWidth: number;
|
|
2985
2994
|
/** @property {number} - Default rounded rect corner radius for UI elements */
|
|
@@ -3004,14 +3013,17 @@ declare module "littlejsengine" {
|
|
|
3004
3013
|
hoverObject: any;
|
|
3005
3014
|
/** @property {UIObject} - Hover object at start of update */
|
|
3006
3015
|
lastHoverObject: any;
|
|
3016
|
+
/** @property {number} - If set ui coords will be renormalized to this canvas height */
|
|
3017
|
+
nativeHeight: number;
|
|
3007
3018
|
/** Draw a rectangle to the UI context
|
|
3008
3019
|
* @param {Vector2} pos
|
|
3009
3020
|
* @param {Vector2} size
|
|
3010
3021
|
* @param {Color} [color=uiSystem.defaultColor]
|
|
3011
3022
|
* @param {number} [lineWidth=uiSystem.defaultLineWidth]
|
|
3012
3023
|
* @param {Color} [lineColor=uiSystem.defaultLineColor]
|
|
3013
|
-
* @param {number} [cornerRadius=uiSystem.defaultCornerRadius]
|
|
3014
|
-
|
|
3024
|
+
* @param {number} [cornerRadius=uiSystem.defaultCornerRadius]
|
|
3025
|
+
* @param {Color} [gradientColor=uiSystem.defaultGradientColor] */
|
|
3026
|
+
drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, cornerRadius?: number, gradientColor?: Color): void;
|
|
3015
3027
|
/** Draw a line to the UI context
|
|
3016
3028
|
* @param {Vector2} posA
|
|
3017
3029
|
* @param {Vector2} posB
|
|
@@ -3035,8 +3047,9 @@ declare module "littlejsengine" {
|
|
|
3035
3047
|
* @param {Color} [lineColor=uiSystem.defaultLineColor]
|
|
3036
3048
|
* @param {string} [align]
|
|
3037
3049
|
* @param {string} [font=uiSystem.defaultFont]
|
|
3050
|
+
* @param {string} [fontStyle]
|
|
3038
3051
|
* @param {boolean} [applyMaxWidth=true] */
|
|
3039
|
-
drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string, applyMaxWidth?: boolean): void;
|
|
3052
|
+
drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string, fontStyle?: string, applyMaxWidth?: boolean): void;
|
|
3040
3053
|
/**
|
|
3041
3054
|
* @callback DragAndDropCallback - Callback for drag and drop events
|
|
3042
3055
|
* @param {DragEvent} event - The drag event
|
|
@@ -3081,12 +3094,16 @@ declare module "littlejsengine" {
|
|
|
3081
3094
|
hoverColor: Color;
|
|
3082
3095
|
/** @property {Color} - Color for line drawing */
|
|
3083
3096
|
lineColor: Color;
|
|
3097
|
+
/** @property {Color} - Uses a gradient fill combined with color */
|
|
3098
|
+
gradientColor: any;
|
|
3084
3099
|
/** @property {number} - Width for line drawing */
|
|
3085
3100
|
lineWidth: number;
|
|
3086
3101
|
/** @property {number} - Corner radius for rounded rects */
|
|
3087
3102
|
cornerRadius: number;
|
|
3088
3103
|
/** @property {string} - Font for this objecct */
|
|
3089
3104
|
font: string;
|
|
3105
|
+
/** @property {string} - Font style for this object or undefined */
|
|
3106
|
+
fontStyle: any;
|
|
3090
3107
|
/** @property {number} - Override for text width */
|
|
3091
3108
|
textWidth: any;
|
|
3092
3109
|
/** @property {number} - Override for text height */
|
|
@@ -3111,6 +3128,8 @@ declare module "littlejsengine" {
|
|
|
3111
3128
|
interactive: boolean;
|
|
3112
3129
|
/** @property {boolean} - Activate when dragged over with mouse held down */
|
|
3113
3130
|
dragActivate: boolean;
|
|
3131
|
+
/** @property {boolean} - True if this can be a hover object */
|
|
3132
|
+
canBeHover: boolean;
|
|
3114
3133
|
/** Add a child UIObject to this object
|
|
3115
3134
|
* @param {UIObject} child
|
|
3116
3135
|
*/
|
|
@@ -3119,6 +3138,10 @@ declare module "littlejsengine" {
|
|
|
3119
3138
|
* @param {UIObject} child
|
|
3120
3139
|
*/
|
|
3121
3140
|
removeChild(child: UIObject): void;
|
|
3141
|
+
/** Check if the mouse is overlapping a box in screen space
|
|
3142
|
+
* @return {boolean} - True if overlapping
|
|
3143
|
+
*/
|
|
3144
|
+
isMouseOverlapping(): boolean;
|
|
3122
3145
|
/** Update the object, called automatically by plugin once each frame */
|
|
3123
3146
|
update(): void;
|
|
3124
3147
|
/** Render the object, called automatically by plugin once each frame */
|