littlejsengine 1.17.11 → 1.17.15

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 (48) hide show
  1. package/AI.md +162 -0
  2. package/README.md +50 -63
  3. package/dist/littlejs.d.ts +150 -68
  4. package/dist/littlejs.esm.js +323 -105
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +320 -104
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +318 -101
  9. package/examples/electron/{build.js → build.mjs} +26 -23
  10. package/examples/electron/game.js +5 -50
  11. package/examples/electron/index.html +2 -2
  12. package/examples/index.html +1 -0
  13. package/examples/module/{build.js → build.mjs} +22 -19
  14. package/examples/shorts/base.html +1 -1
  15. package/examples/shorts/hillGlideGame.js +1 -1
  16. package/examples/shorts/nineSlice.js +3 -3
  17. package/examples/shorts/shapes.js +1 -1
  18. package/examples/shorts/uiSystem.js +17 -16
  19. package/examples/starter/build.bat +1 -1
  20. package/examples/starter/{build.js → build.mjs} +25 -22
  21. package/examples/starter/index.html +2 -2
  22. package/examples/typescript/build.mjs +60 -0
  23. package/examples/typescript/game.js +2 -2
  24. package/examples/typescript/tsconfig.json +11 -2
  25. package/package.json +2 -2
  26. package/plugins/pluginExport.js +1 -0
  27. package/plugins/uiSystem.js +143 -20
  28. package/reference.md +0 -1
  29. package/src/engine.js +16 -14
  30. package/src/engineAudio.js +9 -6
  31. package/src/{engineBuild.js → engineBuild.mjs} +95 -78
  32. package/src/engineDebug.js +8 -5
  33. package/src/engineDraw.js +16 -14
  34. package/src/engineExport.js +2 -1
  35. package/src/engineInput.js +29 -8
  36. package/src/engineMath.js +46 -14
  37. package/src/engineMedals.js +6 -3
  38. package/src/engineObject.js +14 -3
  39. package/src/engineParticles.js +8 -3
  40. package/src/engineRelease.js +6 -2
  41. package/src/engineTileLayer.js +8 -4
  42. package/src/engineUtilities.js +6 -2
  43. package/src/engineWebGL.js +11 -8
  44. package/src/jsconfig.json +2 -1
  45. package/examples/electron/build.bat +0 -7
  46. package/examples/module/build.bat +0 -7
  47. package/examples/typescript/build.bat +0 -5
  48. package/examples/typescript/build.js +0 -31
@@ -48,18 +48,20 @@ declare module "littlejsengine" {
48
48
  * MIT License - Copyright 2021 Frank Force
49
49
  *
50
50
  * Engine Features
51
- * - Object oriented system with base class engine object
52
- * - Base class object handles update, physics, collision, rendering, etc
53
- * - Engine helper classes and functions like Vector2, Color, and Timer
54
- * - Super fast rendering system for tile sheets
55
- * - Sound effects audio with zzfx and music with zzfxm
56
- * - Input processing system with gamepad and touchscreen support
57
- * - Tile layer rendering and collision system
58
- * - Particle effect system
59
- * - Medal system tracks and displays achievements
60
- * - Debug tools and debug rendering system
61
- * - Post processing effects
62
- * - Call engineInit() to start it up!
51
+ * - Object oriented system with EngineObject base class
52
+ * - Automatic object lifecycle (update, physics, collision, rendering)
53
+ * - Engine helper classes: Vector2, Color, Timer, RandomGenerator
54
+ * - Hybrid rendering with WebGL batching and Canvas2D fallback
55
+ * - Audio system with wave, mp3, or ZzFX sound effects
56
+ * - Input system with keyboard, mouse, gamepad, and touch support
57
+ * - Tile layer rendering and collision detection
58
+ * - Particle effect system with emitters
59
+ * - Medal/achievement system with local storage
60
+ * - Comprehensive debug tools and visualizations
61
+ * - Fixed 60 FPS timestep with configurable time scale
62
+ * - Raycast and spatial query utilities
63
+ * - Plugin system for extending engine functionality
64
+ * - Start with engineInit() and provide your game callbacks
63
65
  * @namespace Engine
64
66
  */
65
67
  /** Name of engine
@@ -189,11 +191,14 @@ declare module "littlejsengine" {
189
191
  export function engineAddPlugin(update?: PluginCallback, render?: PluginCallback, glContextLost?: PluginCallback, glContextRestored?: PluginCallback): void;
190
192
  /**
191
193
  * LittleJS Debug System
192
- * - Press Esc to show debug overlay with mouse pick
193
- * - Number keys toggle debug functions
194
- * - +/- apply time scale
195
- * - Debug primitive rendering
196
- * - Save a 2d canvas as a png image
194
+ * - Press Esc to toggle debug overlay with object picking
195
+ * - Number keys toggle debug visualizations (physics, particles, etc.)
196
+ * - +/- keys control time scale for slow motion/fast forward
197
+ * - ASSERT and LOG macros for development (removed in release builds)
198
+ * - Debug primitive rendering (rectangles, circles, lines, points, text)
199
+ * - Screenshot and video capture support
200
+ * - FPS counter and performance watermark
201
+ * - Debug overlay shows mouse position and picked objects
197
202
  * @namespace Debug
198
203
  */
199
204
  /** True if debug is enabled
@@ -733,10 +738,17 @@ declare module "littlejsengine" {
733
738
  export function setDebugKey(key: string): void;
734
739
  /**
735
740
  * LittleJS Math Classes and Functions
736
- * - General purpose math library
737
- * - RandomGenerator - seeded random number generator
738
- * - Vector2 - fast, simple, easy 2D vector class
739
- * - Color - holds a rgba color with math functions
741
+ * - Comprehensive math utilities for game development
742
+ * - Vector2 class for 2D positions, directions, and math operations
743
+ * - Color class for RGBA colors with interpolation and manipulation
744
+ * - RandomGenerator for seeded pseudo-random number generation
745
+ * - Math shortcuts (PI, abs, floor, ceil, min, max, sin, cos, etc.)
746
+ * - Interpolation functions (lerp, smoothStep, percent)
747
+ * - Clamping, wrapping, and modulo operations
748
+ * - Angle utilities with wrap-around support
749
+ * - Collision detection (overlapping, intersection, line tests)
750
+ * - Random number generation and seeding
751
+ * - Type checking utilities
740
752
  * @namespace Math
741
753
  */
742
754
  /** The value of PI
@@ -897,9 +909,10 @@ declare module "littlejsengine" {
897
909
  * @param {number} [amplitude] - Amplitude (max height) of the wave
898
910
  * @param {number} [t=time] - Value to use for time of the wave
899
911
  * @param {number} [offset] - Value to use for time offset of the wave
912
+ * @param {number} [type] - Wave type: 0=sine, 1=triangle, 2=square, 3=sawtooth
900
913
  * @return {number} - Value waving between 0 and amplitude
901
914
  * @memberof Math */
902
- export function wave(frequency?: number, amplitude?: number, t?: number, offset?: number): number;
915
+ export function oscillate(frequency?: number, amplitude?: number, t?: number, offset?: number, type?: number): number;
903
916
  /** Formats seconds to mm:ss style for display purposes
904
917
  * @param {number} t - time in seconds
905
918
  * @return {string}
@@ -1159,6 +1172,10 @@ declare module "littlejsengine" {
1159
1172
  /** Returns a copy of this vector with each axis floored
1160
1173
  * @return {Vector2} */
1161
1174
  floor(): Vector2;
1175
+ /** Returns a copy of this vector snapped to a grid
1176
+ * @param {number} grid - grid size to snap to
1177
+ * @return {Vector2} */
1178
+ snap(grid: number): Vector2;
1162
1179
  /** Returns new vec2 with modded values
1163
1180
  * @param {number} [divisor]
1164
1181
  * @return {Vector2} */
@@ -1283,8 +1300,12 @@ declare module "littlejsengine" {
1283
1300
  }
1284
1301
  /**
1285
1302
  * LittleJS Utility Classes and Functions
1286
- * - General purpose utilities
1287
- * - Timer - tracks time automatically
1303
+ * - Timer - tracks time automatically with support for pause and real-time modes
1304
+ * - Time formatting helper
1305
+ * - JSON file fetching
1306
+ * - File saving (text, canvas, data URLs)
1307
+ * - Native share dialog support
1308
+ * - Local storage save data management
1288
1309
  * @namespace Utilities
1289
1310
  */
1290
1311
  /**
@@ -1547,22 +1568,23 @@ declare module "littlejsengine" {
1547
1568
  }
1548
1569
  /**
1549
1570
  * LittleJS Drawing System
1550
- * - Hybrid system with both Canvas2D and WebGL available
1551
- * - Super fast tile sheet rendering with WebGL
1552
- * - Can apply rotation, mirror, color and additive color
1553
- * - Font rendering system with built in engine font
1554
- * - Many useful utility functions
1555
- *
1556
- * LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.
1557
- * There are 3 canvas/contexts available to draw to...
1558
- * mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
1559
- * glCanvas - Used by the accelerated WebGL batch rendering system.
1571
+ * - Hybrid rendering with both Canvas2D and WebGL support
1572
+ * - Optimized tile sheet sprite rendering using WebGL batching
1573
+ * - Primitive drawing for polygons, ellipses, and lines
1574
+ * - Tile-based rendering with TileInfo and TextureInfo classes
1575
+ * - Text rendering with custom fonts and FontImage support
1576
+ * - Color and additive color blending for effects
1577
+ * - Rotation, mirroring, and scaling transformations
1578
+ * - Camera system with position, scale, and rotation
1579
+ * - Multiple canvas support (main, WebGL, work canvases)
1580
+ * - Gradient fills and outlined shapes
1581
+ * - Image manipulation and color tinting
1560
1582
  *
1561
- * The WebGL rendering system is very fast with some caveats...
1562
- * - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
1563
- * - Group additive rendering together using renderOrder to mitigate this issue
1583
+ * Rendering Architecture:
1584
+ * - glCanvas: WebGL canvas for accelerated sprite batch rendering
1585
+ * - mainCanvas: Canvas2D overlay for text, UI, and custom drawing
1586
+ * - All draw functions default to WebGL when enabled, can force Canvas2D with useWebGL parameter
1564
1587
  *
1565
- * The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!
1566
1588
  * @namespace Draw
1567
1589
  */
1568
1590
  /** The primary 2D canvas visible to the user
@@ -1845,14 +1867,17 @@ declare module "littlejsengine" {
1845
1867
  export function getCameraSize(): Vector2;
1846
1868
  /**
1847
1869
  * LittleJS WebGL Interface
1848
- * - All WebGL used by the engine is wrapped up here
1849
- * - Will fall back to 2D canvas rendering if WebGL is not supported
1850
- * - For normal stuff you won't need to see or call anything in this file
1851
- * - For advanced stuff there are helper functions to create shaders, textures, etc
1852
- * - Can be disabled with glEnable to revert to 2D canvas rendering
1853
- * - Batches sprite rendering on GPU for incredibly fast performance
1854
- * - Sprite transform math is done in the shader where possible
1855
- * - Supports shadertoy style post processing shaders via plugin
1870
+ * - WebGL2 rendering engine for high-performance graphics
1871
+ * - Batched sprite rendering for drawing thousands of sprites efficiently
1872
+ * - Instanced rendering using vertex array objects (VAOs)
1873
+ * - Polygon rendering with triangle strip support
1874
+ * - Shader system with custom vertex and fragment shaders
1875
+ * - Texture management with automatic atlas support
1876
+ * - Post-processing effects via framebuffer and shader plugins
1877
+ * - Automatic fallback to Canvas2D if WebGL is unavailable
1878
+ * - Context loss and restoration handling
1879
+ * - Can be disabled with glEnable setting
1880
+ * - Advanced users can create custom shaders and render targets
1856
1881
  * @namespace WebGL
1857
1882
  */
1858
1883
  /** The WebGL canvas which appears below the main canvas
@@ -2031,11 +2056,14 @@ declare module "littlejsengine" {
2031
2056
  export function mouseWasReleased(button: number): boolean;
2032
2057
  /**
2033
2058
  * LittleJS Input System
2034
- * - Tracks keyboard down, pressed, and released
2035
- * - Tracks mouse buttons, position, and wheel
2036
- * - Tracks multiple analog gamepads
2037
- * - Touch input is handled as mouse input
2038
- * - Virtual gamepad for touch devices
2059
+ * - Keyboard input with key down, pressed, and released states
2060
+ * - Mouse input with position (world and screen space), buttons, and wheel
2061
+ * - Gamepad support for multiple controllers with analog sticks and buttons
2062
+ * - Touch input mapped to mouse position and buttons
2063
+ * - Virtual on-screen gamepad for mobile devices
2064
+ * - Automatic gamepad vs keyboard/mouse detection
2065
+ * - Input event prevention for canvas focus
2066
+ * - Clipboard copy/paste support
2039
2067
  * @namespace Input
2040
2068
  */
2041
2069
  /** Mouse pos in world space
@@ -2135,12 +2163,15 @@ declare module "littlejsengine" {
2135
2163
  export function pointerLockIsActive(): boolean;
2136
2164
  /**
2137
2165
  * LittleJS Audio System
2138
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
2139
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
2140
- * - Caches sounds and music for fast playback
2141
- * - Can attenuate and apply stereo panning to sounds
2142
- * - Ability to play mp3, ogg, and wave files
2143
- * - Speech synthesis functions
2166
+ * - Play audio files (mp3, ogg, wave) and generate sounds with ZzFX
2167
+ * - ZzFX sound generator integration: <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX</a>
2168
+ * - Sound caching for fast playback and memory efficiency
2169
+ * - Volume control with attenuation and stereo panning
2170
+ * - 2D spatial audio based on camera position with distance-based falloff
2171
+ * - Sound instance management (pause, resume, stop)
2172
+ * - Speech synthesis for text-to-speech
2173
+ * - Music playback with ZzFXM support
2174
+ * - Web Audio API integration with master gain control
2144
2175
  * @namespace Audio
2145
2176
  */
2146
2177
  /** Audio context used by the engine
@@ -2387,6 +2418,13 @@ declare module "littlejsengine" {
2387
2418
  export function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number, filter?: number): any[];
2388
2419
  /**
2389
2420
  * LittleJS Object System
2421
+ * - EngineObject is the base class for all game objects
2422
+ * - Handles automatic updating, rendering, physics, and collision
2423
+ * - Supports parent-child hierarchies with transform inheritance
2424
+ * - 2D physics with velocity, acceleration, damping, and gravity
2425
+ * - Collision system with tiles and other objects
2426
+ * - Renders sprites from tile sheets with color and rotation
2427
+ * - Objects sorted by renderOrder for layered rendering
2390
2428
  */
2391
2429
  /**
2392
2430
  * LittleJS Object Base Object Class
@@ -2574,10 +2612,14 @@ declare module "littlejsengine" {
2574
2612
  }
2575
2613
  /**
2576
2614
  * LittleJS Tile Layer System
2577
- * - Caches arrays of tiles to off screen canvas for fast rendering
2578
- * - Unlimited numbers of layers, allocates canvases as needed
2579
- * - Tile layers can be drawn to using their context with canvas2d
2580
- * - Tile layers can also have collision with EngineObjects
2615
+ * - Renders large tile-based levels efficiently using cached canvases
2616
+ * - Unlimited tile layers with automatic canvas allocation
2617
+ * - Layers support both rendering and collision detection
2618
+ * - Direct canvas2d drawing access for custom tile rendering
2619
+ * - TileLayer for rendering, TileCollisionLayer for physics
2620
+ * - Collision callbacks for tile interactions with objects
2621
+ * - Optimized raycast support for tile-based physics
2622
+ * - Integration with Box2D physics via Box2DTileLayer plugin
2581
2623
  * @namespace TileLayers
2582
2624
  */
2583
2625
  /** Keep track of all tile layers with collision
@@ -2839,9 +2881,14 @@ declare module "littlejsengine" {
2839
2881
  }
2840
2882
  /**
2841
2883
  * LittleJS Particle System
2842
- * - A simple but fast and flexible particle system
2843
- * - Lightweight Particles are created and managed by ParticleEmitters
2844
- * - The particle design tool can be used to help create emitters
2884
+ * - Fast and flexible particle effects system
2885
+ * - ParticleEmitter spawns and manages lightweight Particle objects
2886
+ * - Particles support color gradients, fading, rotation, and scaling
2887
+ * - Physics simulation with velocity, gravity, and damping
2888
+ * - Collision detection with tile layers
2889
+ * - Additive blending for glowing effects
2890
+ * - Cone-based emission with randomization
2891
+ * - Particle design tool available for easy emitter creation
2845
2892
  * @namespace Particles
2846
2893
  */
2847
2894
  /**
@@ -3030,9 +3077,12 @@ declare module "littlejsengine" {
3030
3077
  }
3031
3078
  /**
3032
3079
  * LittleJS Medal System
3033
- * - Tracks and displays medals
3034
- * - Saves medals to local storage
3035
- * - Newgrounds integration
3080
+ * - Achievement/trophy system for games
3081
+ * - Medal class with name, description, icon, and unlock tracking
3082
+ * - Automatic saving to local storage
3083
+ * - Visual display queue with slide-in notifications
3084
+ * - Newgrounds API integration for online achievements
3085
+ * - Debug mode to unlock/reset medals during development
3036
3086
  * @namespace Medals
3037
3087
  */
3038
3088
  /** List of all medals
@@ -3345,6 +3395,8 @@ declare module "littlejsengine" {
3345
3395
  lastHoverObject: any;
3346
3396
  /** @property {UIObject} - Current confirm menu being shown */
3347
3397
  confirmDialog: any;
3398
+ /** @property {UIObject} - Object to send keyboard input to */
3399
+ keyInputObject: any;
3348
3400
  /** Draw a rectangle to the UI context
3349
3401
  * @param {Vector2} pos
3350
3402
  * @param {Vector2} size
@@ -3525,7 +3577,7 @@ declare module "littlejsengine" {
3525
3577
  /** Destroy this object, destroy its children, detach its parent, and mark it for removal */
3526
3578
  destroy(): void;
3527
3579
  destroyed: number;
3528
- /** Check if the mouse is overlapping a box in screen space
3580
+ /** Check if the mouse is overlapping this ui object
3529
3581
  * @return {boolean} - True if overlapping */
3530
3582
  isMouseOverlapping(): boolean;
3531
3583
  /** Update the object, called automatically by plugin once each frame */
@@ -3543,6 +3595,8 @@ declare module "littlejsengine" {
3543
3595
  isActiveObject(): boolean;
3544
3596
  /** @return {boolean} - Is the gamepad or keyboard navigation object */
3545
3597
  isNavigationObject(): boolean;
3598
+ /** @return {boolean} - Is this object in keyboard input mode */
3599
+ isKeyInputObject(): boolean;
3546
3600
  /** @return {boolean} - Can it be interacted with */
3547
3601
  isInteractive(): boolean;
3548
3602
  /** Returns string containing info about this object for debugging
@@ -3551,6 +3605,9 @@ declare module "littlejsengine" {
3551
3605
  /** Called if uiDebug is enabled
3552
3606
  * @param {boolean} visible */
3553
3607
  renderDebug(visible?: boolean): void;
3608
+ /** Internal function called when object is clicked
3609
+ * @param {boolean} [playSound] */
3610
+ click(playSound?: boolean): void;
3554
3611
  /** Called each frame before object updates */
3555
3612
  onUpdate(): void;
3556
3613
  /** Called each frame before object renders */
@@ -3585,6 +3642,30 @@ declare module "littlejsengine" {
3585
3642
  text: string;
3586
3643
  align: string;
3587
3644
  }
3645
+ /**
3646
+ * UITextInput - An editable text input field
3647
+ * - A simple text entry field that supports basic editing
3648
+ * - Suitable for short text input like names or numbers
3649
+ * @extends UIObject
3650
+ * @memberof UISystem
3651
+ */
3652
+ export class UITextInput extends UIObject {
3653
+ /** Create a UITextInput object
3654
+ * @param {Vector2} [pos]
3655
+ * @param {Vector2} [size]
3656
+ * @param {string} [text]
3657
+ */
3658
+ constructor(pos?: Vector2, size?: Vector2, text?: string);
3659
+ /** @property {number} - Max length of input (0 = no limit) */
3660
+ maxLength: number;
3661
+ text: string;
3662
+ click(): void;
3663
+ /** Stop editing the text edited */
3664
+ stopEditing(): void;
3665
+ /** Key down event handler if this object is being edited
3666
+ * @param {KeyboardEvent} [e] */
3667
+ onKeyDown(e?: KeyboardEvent): void;
3668
+ }
3588
3669
  /**
3589
3670
  * UITile - A UI object that displays a tile image
3590
3671
  * @extends UIObject
@@ -3641,6 +3722,7 @@ declare module "littlejsengine" {
3641
3722
  /** @property {boolean} - Current percentage value of this scrollbar 0-1 */
3642
3723
  checked: boolean;
3643
3724
  text: string;
3725
+ click(): void;
3644
3726
  }
3645
3727
  /**
3646
3728
  * UIScrollbar - A UI object that acts as a scrollbar