littlejsengine 1.14.28 → 1.15.3
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 +117 -19
- package/dist/littlejs.esm.js +339 -79
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +338 -79
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +302 -57
- package/examples/electron/index.html +2 -2
- package/examples/index.html +1 -0
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/box2dCar.js +1 -1
- package/examples/shorts/music.js +1 -0
- package/examples/shorts/musicPlayer.js +1 -0
- package/examples/shorts/sequencer.js +2 -0
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/sound.js +1 -0
- package/examples/shorts/timers.js +1 -0
- package/examples/shorts/uiSystem.js +1 -0
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +34 -0
- package/examples/starter/index.html +3 -3
- package/examples/uiSystem/game.js +1 -0
- package/package.json +1 -1
- package/plugins/pluginExport.js +1 -0
- package/plugins/uiSystem.js +204 -3
- package/src/engine.js +5 -5
- package/src/engineAudio.js +0 -1
- package/src/engineDebug.js +36 -22
- package/src/engineDraw.js +57 -33
- package/src/engineInput.js +1 -1
- package/src/engineObject.js +3 -1
- package/src/engineParticles.js +3 -0
- package/src/engineTileLayer.js +1 -1
- package/src/engineUtilities.js +28 -12
package/dist/littlejs.d.ts
CHANGED
|
@@ -105,7 +105,7 @@ declare module "littlejsengine" {
|
|
|
105
105
|
export function setPaused(isPaused?: boolean): void;
|
|
106
106
|
/**
|
|
107
107
|
* @callback GameInitCallback - Called after the engine starts, can be async
|
|
108
|
-
* @
|
|
108
|
+
* @return {void|Promise<void>}
|
|
109
109
|
* @memberof Engine
|
|
110
110
|
*/
|
|
111
111
|
/**
|
|
@@ -139,10 +139,10 @@ declare module "littlejsengine" {
|
|
|
139
139
|
* @memberof Engine */
|
|
140
140
|
export function engineObjectsDestroy(): void;
|
|
141
141
|
/** Collects all object within a given area
|
|
142
|
-
* @param {Vector2} [pos]
|
|
143
|
-
* @param {Vector2|number} [size]
|
|
142
|
+
* @param {Vector2} [pos] - Center of test area, or undefined for all objects
|
|
143
|
+
* @param {Vector2|number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
144
144
|
* @param {Array<EngineObject>} [objects=engineObjects] - List of objects to check
|
|
145
|
-
* @return {Array<EngineObject>}
|
|
145
|
+
* @return {Array<EngineObject>} - List of collected objects
|
|
146
146
|
* @memberof Engine */
|
|
147
147
|
export function engineObjectsCollect(pos?: Vector2, size?: Vector2 | number, objects?: Array<EngineObject>): Array<EngineObject>;
|
|
148
148
|
/**
|
|
@@ -216,8 +216,9 @@ declare module "littlejsengine" {
|
|
|
216
216
|
* @param {number} [time]
|
|
217
217
|
* @param {number} [angle]
|
|
218
218
|
* @param {boolean} [fill]
|
|
219
|
+
* @param {boolean} [screenSpace]
|
|
219
220
|
* @memberof Debug */
|
|
220
|
-
export function debugRect(pos: Vector2, size?: Vector2, color?: Color | string, time?: number, angle?: number, fill?: boolean): void;
|
|
221
|
+
export function debugRect(pos: Vector2, size?: Vector2, color?: Color | string, time?: number, angle?: number, fill?: boolean, screenSpace?: boolean): void;
|
|
221
222
|
/** Draw a debug poly in world space
|
|
222
223
|
* @param {Vector2} pos
|
|
223
224
|
* @param {Array<Vector2>} points
|
|
@@ -225,39 +226,45 @@ declare module "littlejsengine" {
|
|
|
225
226
|
* @param {number} [time]
|
|
226
227
|
* @param {number} [angle]
|
|
227
228
|
* @param {boolean} [fill]
|
|
229
|
+
* @param {boolean} [screenSpace]
|
|
228
230
|
* @memberof Debug */
|
|
229
|
-
export function debugPoly(pos: Vector2, points: Array<Vector2>, color?: Color | string, time?: number, angle?: number, fill?: boolean): void;
|
|
231
|
+
export function debugPoly(pos: Vector2, points: Array<Vector2>, color?: Color | string, time?: number, angle?: number, fill?: boolean, screenSpace?: boolean): void;
|
|
230
232
|
/** Draw a debug circle in world space
|
|
231
233
|
* @param {Vector2} pos
|
|
232
234
|
* @param {number} [size] - diameter
|
|
233
235
|
* @param {Color|string} [color]
|
|
234
236
|
* @param {number} [time]
|
|
235
237
|
* @param {boolean} [fill]
|
|
238
|
+
* @param {boolean} [screenSpace]
|
|
236
239
|
* @memberof Debug */
|
|
237
|
-
export function debugCircle(pos: Vector2, size?: number, color?: Color | string, time?: number, fill?: boolean): void;
|
|
240
|
+
export function debugCircle(pos: Vector2, size?: number, color?: Color | string, time?: number, fill?: boolean, screenSpace?: boolean): void;
|
|
238
241
|
/** Draw a debug point in world space
|
|
239
242
|
* @param {Vector2} pos
|
|
240
243
|
* @param {Color|string} [color]
|
|
241
244
|
* @param {number} [time]
|
|
242
245
|
* @param {number} [angle]
|
|
246
|
+
* @param {boolean} [screenSpace]
|
|
243
247
|
* @memberof Debug */
|
|
244
|
-
export function debugPoint(pos: Vector2, color?: Color | string, time?: number, angle?: number): void;
|
|
248
|
+
export function debugPoint(pos: Vector2, color?: Color | string, time?: number, angle?: number, screenSpace?: boolean): void;
|
|
245
249
|
/** Draw a debug line in world space
|
|
246
250
|
* @param {Vector2} posA
|
|
247
251
|
* @param {Vector2} posB
|
|
248
252
|
* @param {Color|string} [color]
|
|
249
253
|
* @param {number} [width]
|
|
250
254
|
* @param {number} [time]
|
|
255
|
+
* @param {boolean} [screenSpace]
|
|
251
256
|
* @memberof Debug */
|
|
252
|
-
export function debugLine(posA: Vector2, posB: Vector2, color?: Color | string, width?: number, time?: number): void;
|
|
257
|
+
export function debugLine(posA: Vector2, posB: Vector2, color?: Color | string, width?: number, time?: number, screenSpace?: boolean): void;
|
|
253
258
|
/** Draw a debug combined axis aligned bounding box in world space
|
|
254
259
|
* @param {Vector2} posA
|
|
255
260
|
* @param {Vector2} sizeA
|
|
256
261
|
* @param {Vector2} posB
|
|
257
262
|
* @param {Vector2} sizeB
|
|
258
263
|
* @param {Color|string} [color]
|
|
264
|
+
* @param {number} [time]
|
|
265
|
+
* @param {boolean} [screenSpace]
|
|
259
266
|
* @memberof Debug */
|
|
260
|
-
export function debugOverlap(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB: Vector2, color?: Color | string): void;
|
|
267
|
+
export function debugOverlap(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB: Vector2, color?: Color | string, time?: number, screenSpace?: boolean): void;
|
|
261
268
|
/** Draw a debug axis aligned bounding box in world space
|
|
262
269
|
* @param {string} text
|
|
263
270
|
* @param {Vector2} pos
|
|
@@ -266,8 +273,9 @@ declare module "littlejsengine" {
|
|
|
266
273
|
* @param {number} [time]
|
|
267
274
|
* @param {number} [angle]
|
|
268
275
|
* @param {string} [font]
|
|
276
|
+
* @param {boolean} [screenSpace]
|
|
269
277
|
* @memberof Debug */
|
|
270
|
-
export function debugText(text: string, pos: Vector2, size?: number, color?: Color | string, time?: number, angle?: number, font?: string): void;
|
|
278
|
+
export function debugText(text: string, pos: Vector2, size?: number, color?: Color | string, time?: number, angle?: number, font?: string, screenSpace?: boolean): void;
|
|
271
279
|
/** Clear all debug primitives in the list
|
|
272
280
|
* @memberof Debug */
|
|
273
281
|
export function debugClear(): void;
|
|
@@ -813,7 +821,7 @@ declare module "littlejsengine" {
|
|
|
813
821
|
* @param {number} valueA
|
|
814
822
|
* @param {number} valueB
|
|
815
823
|
* @param {number} [wrapSize]
|
|
816
|
-
* @
|
|
824
|
+
* @return {number}
|
|
817
825
|
* @memberof Utilities */
|
|
818
826
|
export function distanceWrap(valueA: number, valueB: number, wrapSize?: number): number;
|
|
819
827
|
/** Linearly interpolates between values passed in with wrapping
|
|
@@ -821,20 +829,20 @@ declare module "littlejsengine" {
|
|
|
821
829
|
* @param {number} valueB
|
|
822
830
|
* @param {number} percent
|
|
823
831
|
* @param {number} [wrapSize]
|
|
824
|
-
* @
|
|
832
|
+
* @return {number}
|
|
825
833
|
* @memberof Utilities */
|
|
826
834
|
export function lerpWrap(valueA: number, valueB: number, percent: number, wrapSize?: number): number;
|
|
827
835
|
/** Returns signed wrapped distance between the two angles passed in
|
|
828
836
|
* @param {number} angleA
|
|
829
837
|
* @param {number} angleB
|
|
830
|
-
* @
|
|
838
|
+
* @return {number}
|
|
831
839
|
* @memberof Utilities */
|
|
832
840
|
export function distanceAngle(angleA: number, angleB: number): number;
|
|
833
841
|
/** Linearly interpolates between the angles passed in with wrapping
|
|
834
842
|
* @param {number} angleA
|
|
835
843
|
* @param {number} angleB
|
|
836
844
|
* @param {number} percent
|
|
837
|
-
* @
|
|
845
|
+
* @return {number}
|
|
838
846
|
* @memberof Utilities */
|
|
839
847
|
export function lerpAngle(angleA: number, angleB: number, percent: number): number;
|
|
840
848
|
/** Linearly interpolates between values passed in using percent
|
|
@@ -1229,13 +1237,18 @@ declare module "littlejsengine" {
|
|
|
1229
1237
|
*/
|
|
1230
1238
|
export class Timer {
|
|
1231
1239
|
/** Create a timer object set time passed in
|
|
1232
|
-
* @param {number} [timeLeft] - How much time left before the timer
|
|
1233
|
-
|
|
1240
|
+
* @param {number} [timeLeft] - How much time left before the timer
|
|
1241
|
+
* @param {boolean} [useRealTime] - Should the timer keep running even when the game is paused? (useful for UI) */
|
|
1242
|
+
constructor(timeLeft?: number, useRealTime?: boolean);
|
|
1243
|
+
useRealTime: boolean;
|
|
1234
1244
|
time: number;
|
|
1235
1245
|
setTime: number;
|
|
1236
1246
|
/** Set the timer with seconds passed in
|
|
1237
1247
|
* @param {number} [timeLeft] - How much time left before the timer is elapsed in seconds */
|
|
1238
1248
|
set(timeLeft?: number): void;
|
|
1249
|
+
/** Set if the timer should keep running even when the game is paused
|
|
1250
|
+
* @param {boolean} [useRealTime] */
|
|
1251
|
+
setUseRealTime(useRealTime?: boolean): void;
|
|
1239
1252
|
/** Unset the timer */
|
|
1240
1253
|
unset(): void;
|
|
1241
1254
|
/** Returns true if set
|
|
@@ -1256,6 +1269,9 @@ declare module "littlejsengine" {
|
|
|
1256
1269
|
/** Get the time this timer was set to, returns 0 if not set
|
|
1257
1270
|
* @return {number} */
|
|
1258
1271
|
getSetTime(): number;
|
|
1272
|
+
/** Get the current global time this timer is based on
|
|
1273
|
+
* @return {number} */
|
|
1274
|
+
getGlobalTime(): number;
|
|
1259
1275
|
/** Returns this timer expressed as a string
|
|
1260
1276
|
* @return {string} */
|
|
1261
1277
|
toString(): string;
|
|
@@ -3138,6 +3154,12 @@ declare module "littlejsengine" {
|
|
|
3138
3154
|
defaultSoundRelease: any;
|
|
3139
3155
|
/** @property {Sound} - Default sound when interactive UI element is clicked */
|
|
3140
3156
|
defaultSoundClick: any;
|
|
3157
|
+
/** @property {Color} - Color for shadow */
|
|
3158
|
+
defaultShadowColor: Color;
|
|
3159
|
+
/** @property {number} - Size of shadow blur */
|
|
3160
|
+
defaultShadowBlur: number;
|
|
3161
|
+
/** @property {Vector2} - Offset of shadow blur */
|
|
3162
|
+
defaultShadowOffset: Vector2;
|
|
3141
3163
|
/** @property {Array<UIObject>} - List of all UI elements */
|
|
3142
3164
|
uiObjects: any[];
|
|
3143
3165
|
/** @property {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} - Context to render UI elements to */
|
|
@@ -3157,8 +3179,11 @@ declare module "littlejsengine" {
|
|
|
3157
3179
|
* @param {number} [lineWidth]
|
|
3158
3180
|
* @param {Color} [lineColor]
|
|
3159
3181
|
* @param {number} [cornerRadius]
|
|
3160
|
-
* @param {Color} [gradientColor]
|
|
3161
|
-
|
|
3182
|
+
* @param {Color} [gradientColor]
|
|
3183
|
+
* @param {Color} [shadowColor]
|
|
3184
|
+
* @param {number} [shadowBlur]
|
|
3185
|
+
* @param {Color} [shadowOffset] */
|
|
3186
|
+
drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, cornerRadius?: number, gradientColor?: Color, shadowColor?: Color, shadowBlur?: number, shadowOffset?: Color): void;
|
|
3162
3187
|
/** Draw a line to the UI context
|
|
3163
3188
|
* @param {Vector2} posA
|
|
3164
3189
|
* @param {Vector2} posB
|
|
@@ -3204,6 +3229,9 @@ declare module "littlejsengine" {
|
|
|
3204
3229
|
* @return {Vector2}
|
|
3205
3230
|
*/
|
|
3206
3231
|
screenToNative(pos: Vector2): Vector2;
|
|
3232
|
+
/** Destroy and remove all objects
|
|
3233
|
+
* @memberof Engine */
|
|
3234
|
+
destroyObjects(): void;
|
|
3207
3235
|
}
|
|
3208
3236
|
/**
|
|
3209
3237
|
* UI Object - Base level object for all UI elements
|
|
@@ -3272,6 +3300,12 @@ declare module "littlejsengine" {
|
|
|
3272
3300
|
dragActivate: boolean;
|
|
3273
3301
|
/** @property {boolean} - True if this can be a hover object */
|
|
3274
3302
|
canBeHover: boolean;
|
|
3303
|
+
/** @property {Color} - Color for shadow, undefined if no shadow */
|
|
3304
|
+
shadowColor: Color;
|
|
3305
|
+
/** @property {number} - Size of shadow blur */
|
|
3306
|
+
shadowBlur: number;
|
|
3307
|
+
/** @property {Vector2} - Offset of shadow blur */
|
|
3308
|
+
shadowOffset: Vector2;
|
|
3275
3309
|
/** @property {Vector2} - How much to offset the text shadow or undefined */
|
|
3276
3310
|
textShadow: any;
|
|
3277
3311
|
/** Add a child UIObject to this object
|
|
@@ -3282,6 +3316,9 @@ declare module "littlejsengine" {
|
|
|
3282
3316
|
* @param {UIObject} child
|
|
3283
3317
|
*/
|
|
3284
3318
|
removeChild(child: UIObject): void;
|
|
3319
|
+
/** Destroy this object, destroy its children, detach its parent, and mark it for removal */
|
|
3320
|
+
destroy(): void;
|
|
3321
|
+
destroyed: number;
|
|
3285
3322
|
/** Check if the mouse is overlapping a box in screen space
|
|
3286
3323
|
* @return {boolean} - True if overlapping
|
|
3287
3324
|
*/
|
|
@@ -3408,6 +3445,67 @@ declare module "littlejsengine" {
|
|
|
3408
3445
|
handleColor: Color;
|
|
3409
3446
|
text: string;
|
|
3410
3447
|
}
|
|
3448
|
+
/**
|
|
3449
|
+
* VideoPlayerUIObject - A UI object that plays video
|
|
3450
|
+
* @extends UIObject
|
|
3451
|
+
* @example
|
|
3452
|
+
* // Create a video player UI object
|
|
3453
|
+
* const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), 'cutscene.mp4', true);
|
|
3454
|
+
* video.play();
|
|
3455
|
+
* @memberof UISystem
|
|
3456
|
+
*/
|
|
3457
|
+
export class UIVideo extends UIObject {
|
|
3458
|
+
/** Create a video player UI object
|
|
3459
|
+
* @param {Vector2} [pos]
|
|
3460
|
+
* @param {Vector2} [size]
|
|
3461
|
+
* @param {string} src - Video file path or URL
|
|
3462
|
+
* @param {boolean} [autoplay=false] - Start playing immediately?
|
|
3463
|
+
* @param {boolean} [loop=false] - Loop the video?
|
|
3464
|
+
* @param {number} [volume=1] - Volume percent scaled by global volume (0-1)
|
|
3465
|
+
*/
|
|
3466
|
+
constructor(pos?: Vector2, size?: Vector2, src: string, autoplay?: boolean, loop?: boolean, volume?: number);
|
|
3467
|
+
/** @property {float} - The video volume */
|
|
3468
|
+
volume: number;
|
|
3469
|
+
/** @property {HTMLVideoElement} - The video player */
|
|
3470
|
+
video: HTMLVideoElement;
|
|
3471
|
+
/** Play or resume the video
|
|
3472
|
+
* @return {Promise} Promise that resolves when playback starts */
|
|
3473
|
+
play(): Promise<any>;
|
|
3474
|
+
/** Pause the video */
|
|
3475
|
+
pause(): void;
|
|
3476
|
+
/** Stop and reset the video */
|
|
3477
|
+
stop(): void;
|
|
3478
|
+
/** Check if video is currently loading
|
|
3479
|
+
* @return {boolean} */
|
|
3480
|
+
isLoadng(): boolean;
|
|
3481
|
+
/** Check if video is currently paused
|
|
3482
|
+
* @return {boolean} */
|
|
3483
|
+
isPaused(): boolean;
|
|
3484
|
+
/** Check if video is currently playing
|
|
3485
|
+
* @return {boolean} */
|
|
3486
|
+
isPlaying(): boolean;
|
|
3487
|
+
/** Check if video has ended playing
|
|
3488
|
+
* @return {boolean} */
|
|
3489
|
+
hasEnded(): boolean;
|
|
3490
|
+
/** Set volume (0-1)
|
|
3491
|
+
* @param {number} volume - Volume level (0-1) */
|
|
3492
|
+
setVolume(volume: number): void;
|
|
3493
|
+
/** Set playback speed
|
|
3494
|
+
* @param {number} rate - Playback rate multiplier */
|
|
3495
|
+
setPlaybackRate(rate: number): void;
|
|
3496
|
+
/** Get current time in seconds
|
|
3497
|
+
* @return {number} Current playback time */
|
|
3498
|
+
getCurrentTime(): number;
|
|
3499
|
+
/** Get duration in seconds
|
|
3500
|
+
* @return {number} Total video duration */
|
|
3501
|
+
getDuration(): number;
|
|
3502
|
+
/** Get the native video dimensions
|
|
3503
|
+
* @return {Vector2} Video dimensions (may be 0,0 if metadata not loaded) */
|
|
3504
|
+
getVideoSize(): Vector2;
|
|
3505
|
+
/** Seek to time in seconds
|
|
3506
|
+
* @param {number} time - Time in seconds to seek to */
|
|
3507
|
+
setTime(time: number): void;
|
|
3508
|
+
}
|
|
3411
3509
|
/**
|
|
3412
3510
|
* LittleJS Box2D Physics Plugin
|
|
3413
3511
|
* - Box2dObject extends EngineObject with Box2D physics
|