littlejsengine 1.14.23 → 1.14.28

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.
Files changed (49) hide show
  1. package/dist/littlejs.d.ts +99 -20
  2. package/dist/littlejs.esm.js +378 -130
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +373 -130
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +336 -130
  7. package/examples/box2d/gameObjects.js +6 -10
  8. package/examples/box2d/scenes.js +2 -2
  9. package/examples/breakout/gameObjects.js +1 -1
  10. package/examples/electron/index.html +2 -2
  11. package/examples/index.html +10 -7
  12. package/examples/platformer/gameCharacter.js +3 -2
  13. package/examples/platformer/gameObjects.js +3 -8
  14. package/examples/shorts/base.html +1 -1
  15. package/examples/shorts/box2d.js +2 -2
  16. package/examples/shorts/box2dCar.js +18 -7
  17. package/examples/shorts/box2dPool.js +108 -0
  18. package/examples/shorts/debugDraw.js +2 -3
  19. package/examples/shorts/flappyGame.js +1 -0
  20. package/examples/shorts/fps.js +1 -1
  21. package/examples/shorts/hillGlideGame.js +0 -2
  22. package/examples/shorts/input.js +59 -0
  23. package/examples/shorts/landerGame.js +1 -3
  24. package/examples/shorts/medals.js +15 -9
  25. package/examples/shorts/music.js +15 -17
  26. package/examples/shorts/musicPlayer.js +24 -24
  27. package/examples/shorts/platformer.js +0 -2
  28. package/examples/shorts/slidingPuzzle.js +1 -1
  29. package/examples/shorts/spaceGame.js +0 -2
  30. package/examples/shorts/spriteAtlas.js +0 -2
  31. package/examples/shorts/tiltedView.js +0 -3
  32. package/examples/shorts/timers.js +1 -2
  33. package/examples/shorts/topDown.js +0 -2
  34. package/examples/starter/index.html +2 -2
  35. package/package.json +1 -1
  36. package/plugins/box2d.js +170 -50
  37. package/plugins/pluginExport.js +2 -0
  38. package/plugins/uiSystem.js +55 -27
  39. package/src/engine.js +17 -14
  40. package/src/engineAudio.js +14 -2
  41. package/src/engineDebug.js +37 -0
  42. package/src/engineDraw.js +20 -12
  43. package/src/engineExport.js +3 -0
  44. package/src/engineInput.js +24 -12
  45. package/src/engineMedals.js +2 -2
  46. package/src/engineObject.js +24 -4
  47. package/src/engineParticles.js +1 -6
  48. package/src/engineTileLayer.js +2 -0
  49. package/src/engineUtilities.js +7 -1
@@ -904,6 +904,11 @@ declare module "littlejsengine" {
904
904
  * @return {number}
905
905
  * @memberof Random */
906
906
  export function randInt(valueA: number, valueB?: number): number;
907
+ /** Randomly returns true or false given the chance of true passed in
908
+ * @param {number} [chance]
909
+ * @return {boolean}
910
+ * @memberof Random */
911
+ export function randBool(chance?: number): boolean;
907
912
  /** Randomly returns either -1 or 1
908
913
  * @return {number}
909
914
  * @memberof Random */
@@ -1312,6 +1317,12 @@ declare module "littlejsengine" {
1312
1317
  * @return {boolean}
1313
1318
  * @memberof Utilities */
1314
1319
  export function isString(s: any): boolean;
1320
+ /**
1321
+ * Check if object is an array
1322
+ * @param {any} a
1323
+ * @return {boolean}
1324
+ * @memberof Utilities */
1325
+ export function isArray(a: any): boolean;
1315
1326
  /** Color - White #ffffff
1316
1327
  * @type {Color}
1317
1328
  * @memberof Utilities */
@@ -1646,9 +1657,10 @@ declare module "littlejsengine" {
1646
1657
  * @param {string} [font=fontDefault]
1647
1658
  * @param {string} [fontStyle]
1648
1659
  * @param {number} [maxWidth]
1660
+ * @param {number} [angle]
1649
1661
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1650
1662
  * @memberof Draw */
1651
- 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;
1663
+ export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1652
1664
  /** Draw text on overlay canvas in world space
1653
1665
  * Automatically splits new lines into rows
1654
1666
  * @param {string} text
@@ -1661,8 +1673,9 @@ declare module "littlejsengine" {
1661
1673
  * @param {string} [font=fontDefault]
1662
1674
  * @param {string} [fontStyle]
1663
1675
  * @param {number} [maxWidth]
1676
+ * @param {number} [angle]
1664
1677
  * @memberof Draw */
1665
- export function drawTextOverlay(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number): void;
1678
+ export function drawTextOverlay(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number): void;
1666
1679
  /** Draw text on overlay canvas in screen space
1667
1680
  * Automatically splits new lines into rows
1668
1681
  * @param {string} text
@@ -1675,9 +1688,10 @@ declare module "littlejsengine" {
1675
1688
  * @param {string} [font=fontDefault]
1676
1689
  * @param {string} [fontStyle]
1677
1690
  * @param {number} [maxWidth]
1691
+ * @param {number} [angle]
1678
1692
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
1679
1693
  * @memberof Draw */
1680
- 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;
1694
+ export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1681
1695
  /** Enable normal or additive blend mode
1682
1696
  * @param {boolean} [additive]
1683
1697
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
@@ -1960,6 +1974,10 @@ declare module "littlejsengine" {
1960
1974
  * @type {number}
1961
1975
  * @memberof Input */
1962
1976
  export let mouseWheel: number;
1977
+ /** True if mouse was inside the document window, set to false when mouse leaves
1978
+ * @type {boolean}
1979
+ * @memberof Input */
1980
+ export let mouseInWindow: boolean;
1963
1981
  /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1964
1982
  * @type {boolean}
1965
1983
  * @memberof Input */
@@ -2381,6 +2399,8 @@ declare module "littlejsengine" {
2381
2399
  /** Update the object transform, called automatically by engine even when paused */
2382
2400
  updateTransforms(): void;
2383
2401
  /** Update the object physics, called automatically by engine once each frame */
2402
+ updatePhysics(): void;
2403
+ /** Update the object, called automatically by engine once each frame. Does nothing by default. */
2384
2404
  update(): void;
2385
2405
  /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
2386
2406
  render(): void;
@@ -2420,6 +2440,9 @@ declare module "littlejsengine" {
2420
2440
  /** How long since the object was created
2421
2441
  * @return {number} */
2422
2442
  getAliveTime(): number;
2443
+ /** Get the speed of this object
2444
+ * @return {number} */
2445
+ getSpeed(): number;
2423
2446
  /** Apply acceleration to this object (adjust velocity, not affected by mass)
2424
2447
  * @param {Vector2} acceleration */
2425
2448
  applyAcceleration(acceleration: Vector2): void;
@@ -2440,6 +2463,16 @@ declare module "littlejsengine" {
2440
2463
  /** Removes a child from this one
2441
2464
  * @param {EngineObject} child */
2442
2465
  removeChild(child: EngineObject): void;
2466
+ /** Check if overlapping another engine object
2467
+ * Collisions are resoloved to prevent overlaps
2468
+ * @param {EngineObject} object
2469
+ * @return {boolean} */
2470
+ isOverlappingObject(object: EngineObject): boolean;
2471
+ /** Check if overlapping a point or aligned bounding box
2472
+ * @param {Vector2} pos - Center of box
2473
+ * @param {Vector2} [size=(0,0)] - Size of box, uses a point if undefined
2474
+ * @return {boolean} */
2475
+ isOverlapping(pos: Vector2, size?: Vector2): boolean;
2443
2476
  /** Set how this object collides
2444
2477
  * @param {boolean} [collideSolidObjects] - Does it collide with solid objects?
2445
2478
  * @param {boolean} [isSolid] - Does it collide with and block other objects? (expensive in large numbers)
@@ -2478,6 +2511,7 @@ declare module "littlejsengine" {
2478
2511
  * @memberof TileLayers */
2479
2512
  export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject, solidOnly?: boolean): TileCollisionLayer;
2480
2513
  /** Return the exact position of the boudnary of first tile hit, undefined if nothing was hit.
2514
+ * The point will be inside the colliding tile if it hits (may have a tiny shift)
2481
2515
  * @param {Vector2} posStart
2482
2516
  * @param {Vector2} posEnd
2483
2517
  * @param {EngineObject} [object] - An object or undefined for generic test
@@ -2671,6 +2705,7 @@ declare module "littlejsengine" {
2671
2705
  * @return {boolean} */
2672
2706
  collisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
2673
2707
  /** Return the exact position of the boudnary of first tile hit, undefined if nothing was hit.
2708
+ * The point will be inside the colliding tile if it hits (may have a tiny shift)
2674
2709
  * @param {Vector2} posStart
2675
2710
  * @param {Vector2} posEnd
2676
2711
  * @param {EngineObject} [object] - An object or undefined for generic test
@@ -3118,11 +3153,11 @@ declare module "littlejsengine" {
3118
3153
  /** Draw a rectangle to the UI context
3119
3154
  * @param {Vector2} pos
3120
3155
  * @param {Vector2} size
3121
- * @param {Color} [color=uiSystem.defaultColor]
3122
- * @param {number} [lineWidth=uiSystem.defaultLineWidth]
3123
- * @param {Color} [lineColor=uiSystem.defaultLineColor]
3124
- * @param {number} [cornerRadius=uiSystem.defaultCornerRadius]
3125
- * @param {Color} [gradientColor=uiSystem.defaultGradientColor] */
3156
+ * @param {Color} [color]
3157
+ * @param {number} [lineWidth]
3158
+ * @param {Color} [lineColor]
3159
+ * @param {number} [cornerRadius]
3160
+ * @param {Color} [gradientColor] */
3126
3161
  drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, cornerRadius?: number, gradientColor?: Color): void;
3127
3162
  /** Draw a line to the UI context
3128
3163
  * @param {Vector2} posA
@@ -3148,8 +3183,10 @@ declare module "littlejsengine" {
3148
3183
  * @param {string} [align]
3149
3184
  * @param {string} [font=uiSystem.defaultFont]
3150
3185
  * @param {string} [fontStyle]
3151
- * @param {boolean} [applyMaxWidth=true] */
3152
- drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string, fontStyle?: string, applyMaxWidth?: boolean): void;
3186
+ * @param {boolean} [applyMaxWidth=true]
3187
+ * @param {Vector2} [textShadow]
3188
+ */
3189
+ drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string, fontStyle?: string, applyMaxWidth?: boolean, textShadow?: Vector2): void;
3153
3190
  /**
3154
3191
  * @callback DragAndDropCallback - Callback for drag and drop events
3155
3192
  * @param {DragEvent} event - The drag event
@@ -3162,6 +3199,11 @@ declare module "littlejsengine" {
3162
3199
  * @param {DragAndDropCallback} [onDragLeave] - when a file is dragged off the window
3163
3200
  * @param {DragAndDropCallback} [onDragOver] - continously when dragging over */
3164
3201
  setupDragAndDrop(onDrop?: (event: DragEvent) => any, onDragEnter?: (event: DragEvent) => any, onDragLeave?: (event: DragEvent) => any, onDragOver?: (event: DragEvent) => any): void;
3202
+ /** Convert a screen space position to native UI position
3203
+ * @param {Vector2} pos
3204
+ * @return {Vector2}
3205
+ */
3206
+ screenToNative(pos: Vector2): Vector2;
3165
3207
  }
3166
3208
  /**
3167
3209
  * UI Object - Base level object for all UI elements
@@ -3230,6 +3272,8 @@ declare module "littlejsengine" {
3230
3272
  dragActivate: boolean;
3231
3273
  /** @property {boolean} - True if this can be a hover object */
3232
3274
  canBeHover: boolean;
3275
+ /** @property {Vector2} - How much to offset the text shadow or undefined */
3276
+ textShadow: any;
3233
3277
  /** Add a child UIObject to this object
3234
3278
  * @param {UIObject} child
3235
3279
  */
@@ -3256,6 +3300,8 @@ declare module "littlejsengine" {
3256
3300
  isHoverObject(): boolean;
3257
3301
  /** @return {boolean} - Is the mouse held onto this element */
3258
3302
  isActiveObject(): boolean;
3303
+ /** Called each frame when object updates */
3304
+ onUpdate(): void;
3259
3305
  /** Called when the mouse enters the object */
3260
3306
  onEnter(): void;
3261
3307
  /** Called when the mouse leaves the object */
@@ -3365,9 +3411,9 @@ declare module "littlejsengine" {
3365
3411
  /**
3366
3412
  * LittleJS Box2D Physics Plugin
3367
3413
  * - Box2dObject extends EngineObject with Box2D physics
3368
- * - Call box2dInit() before engineInit() to enable
3414
+ * - Call box2dInit() to enable
3369
3415
  * - You will also need to include box2d.wasm.js
3370
- * - Uses a super fast web assembly port of Box2D
3416
+ * - Uses a super fast web assembly port of Box2D v2.3.1
3371
3417
  * - More info: https://github.com/kripken/box2d.js
3372
3418
  * - Functions to create polygon, circle, and edge shapes
3373
3419
  * - Contact begin and end callbacks
@@ -3407,6 +3453,7 @@ declare module "littlejsengine" {
3407
3453
  constructor(instance: any);
3408
3454
  instance: any;
3409
3455
  world: any;
3456
+ objects: any[];
3410
3457
  /** @property {number} - Velocity iterations per update*/
3411
3458
  velocityIterations: number;
3412
3459
  /** @property {number} - Position iterations per update*/
@@ -3462,7 +3509,7 @@ declare module "littlejsengine" {
3462
3509
  vec2From(v: any): Vector2;
3463
3510
  /** converts a box2d vec2 pointer to a Vector2
3464
3511
  * @param {Object} v */
3465
- vec2FromPointer(v: any): Vector2;
3512
+ vec2FromPointer(vp: any): Vector2;
3466
3513
  /** converts a Vector2 to a box2 vec2
3467
3514
  * @param {Vector2} v */
3468
3515
  vec2dTo(v: Vector2): any;
@@ -3475,9 +3522,9 @@ declare module "littlejsengine" {
3475
3522
  }
3476
3523
  /**
3477
3524
  * Box2D Object - extend with your own custom physics objects
3478
- * - A LittleJS object with Box2D physics
3479
- * - Each object has a Box2D body which can have multiple fixtures and joints
3525
+ * - A LittleJS object with Box2D physics, dynamic by default
3480
3526
  * - Provides interface for Box2D body and fixture functions
3527
+ * - Each object can have multiple fixtures and joints
3481
3528
  * @extends EngineObject
3482
3529
  * @memberof Box2D
3483
3530
  */
@@ -3493,6 +3540,8 @@ declare module "littlejsengine" {
3493
3540
  constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, bodyType?: number, renderOrder?: number);
3494
3541
  body: any;
3495
3542
  lineColor: Color;
3543
+ edgeLists: any[];
3544
+ edgeLoops: any[];
3496
3545
  /** Draws all this object's fixtures
3497
3546
  * @param {Color} [color]
3498
3547
  * @param {Color} [lineColor]
@@ -3559,20 +3608,20 @@ declare module "littlejsengine" {
3559
3608
  * @param {number} [restitution]
3560
3609
  * @param {boolean} [isSensor] */
3561
3610
  addEdge(point1: Vector2, point2: Vector2, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
3562
- /** Add an edge loop to the body, an edge loop connects the end points
3611
+ /** Add an edge list to the body
3563
3612
  * @param {Array<Vector2>} points
3564
3613
  * @param {number} [density]
3565
3614
  * @param {number} [friction]
3566
3615
  * @param {number} [restitution]
3567
3616
  * @param {boolean} [isSensor] */
3568
- addEdgeLoop(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3569
- /** Add an edge list to the body
3617
+ addEdgeList(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3618
+ /** Add an edge loop to the body, an edge loop connects the end points
3570
3619
  * @param {Array<Vector2>} points
3571
3620
  * @param {number} [density]
3572
3621
  * @param {number} [friction]
3573
3622
  * @param {number} [restitution]
3574
3623
  * @param {boolean} [isSensor] */
3575
- addEdgeList(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3624
+ addEdgeLoop(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3576
3625
  /** Gets the center of mass
3577
3626
  * @return {Vector2} */
3578
3627
  getCenterOfMass(): Vector2;
@@ -3619,7 +3668,7 @@ declare module "littlejsengine" {
3619
3668
  /** Sets the gravity scale
3620
3669
  * @param {number} [scale] */
3621
3670
  setGravityScale(scale?: number): void;
3622
- /** Should this body be treated like a bullet for continuous collision detection?
3671
+ /** Should be like a bullet for continuous collision detection?
3623
3672
  * @param {boolean} [isBullet] */
3624
3673
  setBullet(isBullet?: boolean): void;
3625
3674
  /** Set the sleep state of the body
@@ -3682,6 +3731,36 @@ declare module "littlejsengine" {
3682
3731
  * @return {Array<Object>} */
3683
3732
  getJointList(): Array<any>;
3684
3733
  }
3734
+ /**
3735
+ * Box2D Static Object - Box2d with a static physics body
3736
+ * @extends Box2dObject
3737
+ * @memberof Box2D
3738
+ */
3739
+ export class Box2dStaticObject extends Box2dObject {
3740
+ /** Create a LittleJS object with Box2d physics
3741
+ * @param {Vector2} [pos]
3742
+ * @param {Vector2} [size]
3743
+ * @param {TileInfo} [tileInfo]
3744
+ * @param {number} [angle]
3745
+ * @param {Color} [color]
3746
+ * @param {number} [renderOrder] */
3747
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
3748
+ }
3749
+ /**
3750
+ * Box2D Kiematic Object - Box2d with a kinematic physics body
3751
+ * @extends Box2dObject
3752
+ * @memberof Box2D
3753
+ */
3754
+ export class Box2dKiematicObject extends Box2dObject {
3755
+ /** Create a LittleJS object with Box2d physics
3756
+ * @param {Vector2} [pos]
3757
+ * @param {Vector2} [size]
3758
+ * @param {TileInfo} [tileInfo]
3759
+ * @param {number} [angle]
3760
+ * @param {Color} [color]
3761
+ * @param {number} [renderOrder] */
3762
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
3763
+ }
3685
3764
  /**
3686
3765
  * Box2D Raycast Result
3687
3766
  * - Holds results from a box2d raycast queries