littlejsengine 1.18.2 → 1.18.7

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 (172) hide show
  1. package/COPYRIGHT.txt +38 -0
  2. package/FAQ.md +633 -0
  3. package/LICENSE +5 -27
  4. package/README.md +19 -1
  5. package/dist/littlejs.d.ts +550 -57
  6. package/dist/littlejs.esm.js +2208 -492
  7. package/dist/littlejs.esm.min.js +1 -1
  8. package/dist/littlejs.js +2165 -480
  9. package/dist/littlejs.min.js +1 -1
  10. package/dist/littlejs.release.js +2166 -481
  11. package/package.json +8 -1
  12. package/plugins/box2d.js +36 -9
  13. package/{src/engineMedals.js → plugins/medalSystem.js} +248 -196
  14. package/plugins/pathFinder.js +758 -0
  15. package/plugins/pluginExport.js +26 -0
  16. package/plugins/tween.js +509 -0
  17. package/plugins/tweenSystem.js +509 -0
  18. package/plugins/uiSystem.js +151 -12
  19. package/src/engine.js +9 -145
  20. package/src/engineAudio.js +8 -5
  21. package/src/engineBuild.mjs +4 -1
  22. package/src/engineDebug.js +1 -1
  23. package/src/engineDraw.js +154 -5
  24. package/src/engineExport.js +17 -12
  25. package/src/engineInput.js +27 -1
  26. package/src/engineLogo.js +146 -0
  27. package/src/engineMath.js +10 -3
  28. package/src/engineObject.js +11 -5
  29. package/src/engineParticles.js +6 -3
  30. package/src/engineRelease.js +1 -1
  31. package/src/engineSettings.js +17 -47
  32. package/src/engineUtilities.js +7 -2
  33. package/src/engineWebGL.js +31 -8
  34. package/src/jsconfig.json +3 -1
  35. package/.claude/settings.local.json +0 -7
  36. package/.github/workflows/test.yml +0 -17
  37. package/AI.md +0 -172
  38. package/CLAUDE.md +0 -1
  39. package/examples/box2d/game.js +0 -192
  40. package/examples/box2d/gameObjects.js +0 -564
  41. package/examples/box2d/index.html +0 -9
  42. package/examples/box2d/scenes.js +0 -194
  43. package/examples/box2d/tiles.png +0 -0
  44. package/examples/breakout/game.js +0 -175
  45. package/examples/breakout/gameObjects.js +0 -147
  46. package/examples/breakout/index.html +0 -8
  47. package/examples/breakout/tiles.png +0 -0
  48. package/examples/breakoutTutorial/README.md +0 -521
  49. package/examples/breakoutTutorial/game.js +0 -191
  50. package/examples/breakoutTutorial/images/1.png +0 -0
  51. package/examples/breakoutTutorial/images/10.png +0 -0
  52. package/examples/breakoutTutorial/images/11.png +0 -0
  53. package/examples/breakoutTutorial/images/2.png +0 -0
  54. package/examples/breakoutTutorial/images/3.png +0 -0
  55. package/examples/breakoutTutorial/images/4.png +0 -0
  56. package/examples/breakoutTutorial/images/5.png +0 -0
  57. package/examples/breakoutTutorial/images/6.png +0 -0
  58. package/examples/breakoutTutorial/images/7.png +0 -0
  59. package/examples/breakoutTutorial/images/8.png +0 -0
  60. package/examples/breakoutTutorial/images/9.png +0 -0
  61. package/examples/breakoutTutorial/index.html +0 -8
  62. package/examples/electron/build.mjs +0 -127
  63. package/examples/electron/electron.js +0 -35
  64. package/examples/electron/game.js +0 -54
  65. package/examples/electron/index.html +0 -13
  66. package/examples/electron/package.json +0 -5
  67. package/examples/electron/tiles.png +0 -0
  68. package/examples/empty/game.js +0 -51
  69. package/examples/empty/index.html +0 -5
  70. package/examples/empty/tiles.png +0 -0
  71. package/examples/favicon.png +0 -0
  72. package/examples/games.jpg +0 -0
  73. package/examples/htmlMenu/game.js +0 -82
  74. package/examples/htmlMenu/index.html +0 -45
  75. package/examples/htmlMenu/tiles.png +0 -0
  76. package/examples/index.html +0 -800
  77. package/examples/logo.png +0 -0
  78. package/examples/logo2.png +0 -0
  79. package/examples/module/build.mjs +0 -124
  80. package/examples/module/game.js +0 -132
  81. package/examples/module/index.html +0 -10
  82. package/examples/module/tiles.png +0 -0
  83. package/examples/particles/index.html +0 -426
  84. package/examples/particles/tiles.png +0 -0
  85. package/examples/platformer/data/gameLevelData.tmx +0 -143
  86. package/examples/platformer/data/gameLevelData.tsx +0 -4
  87. package/examples/platformer/game.js +0 -147
  88. package/examples/platformer/gameCharacter.js +0 -309
  89. package/examples/platformer/gameEffects.js +0 -278
  90. package/examples/platformer/gameLevel.js +0 -205
  91. package/examples/platformer/gameLevelData.json +0 -171
  92. package/examples/platformer/gameObjects.js +0 -378
  93. package/examples/platformer/gamePlayer.js +0 -35
  94. package/examples/platformer/index.html +0 -9
  95. package/examples/platformer/tiles.png +0 -0
  96. package/examples/platformer/tilesLevel.png +0 -0
  97. package/examples/puzzle/game.js +0 -331
  98. package/examples/puzzle/index.html +0 -8
  99. package/examples/puzzle/tiles.png +0 -0
  100. package/examples/screenshot.jpg +0 -0
  101. package/examples/shorts/animation.js +0 -18
  102. package/examples/shorts/base.html +0 -54
  103. package/examples/shorts/blending.js +0 -14
  104. package/examples/shorts/box2d.js +0 -51
  105. package/examples/shorts/box2dCar.js +0 -59
  106. package/examples/shorts/box2dPool.js +0 -107
  107. package/examples/shorts/box2dTileLayer.js +0 -48
  108. package/examples/shorts/cameraDrag.js +0 -22
  109. package/examples/shorts/clock.js +0 -21
  110. package/examples/shorts/colors.js +0 -25
  111. package/examples/shorts/debugDraw.js +0 -37
  112. package/examples/shorts/empty.js +0 -30
  113. package/examples/shorts/flappyGame.js +0 -55
  114. package/examples/shorts/fontImage.js +0 -17
  115. package/examples/shorts/fps.js +0 -90
  116. package/examples/shorts/helloWorld.js +0 -11
  117. package/examples/shorts/hillGlideGame.js +0 -63
  118. package/examples/shorts/input.js +0 -64
  119. package/examples/shorts/landerGame.js +0 -57
  120. package/examples/shorts/maze.js +0 -48
  121. package/examples/shorts/medals.js +0 -51
  122. package/examples/shorts/music.js +0 -78
  123. package/examples/shorts/musicPlayer.js +0 -137
  124. package/examples/shorts/nineSlice.js +0 -40
  125. package/examples/shorts/parallax.js +0 -72
  126. package/examples/shorts/particles.js +0 -28
  127. package/examples/shorts/piano.js +0 -44
  128. package/examples/shorts/platformer.js +0 -45
  129. package/examples/shorts/pongGame.js +0 -41
  130. package/examples/shorts/postProcess.js +0 -62
  131. package/examples/shorts/sequencer.js +0 -124
  132. package/examples/shorts/shader.js +0 -29
  133. package/examples/shorts/shapes.js +0 -21
  134. package/examples/shorts/slidingPuzzle.js +0 -52
  135. package/examples/shorts/song.mp3 +0 -0
  136. package/examples/shorts/sound.js +0 -36
  137. package/examples/shorts/spaceGame.js +0 -58
  138. package/examples/shorts/spriteAtlas.js +0 -31
  139. package/examples/shorts/starfield.js +0 -15
  140. package/examples/shorts/texture.js +0 -16
  141. package/examples/shorts/tileLayer.js +0 -48
  142. package/examples/shorts/tileRaycast.js +0 -39
  143. package/examples/shorts/tiles.png +0 -0
  144. package/examples/shorts/tiltedView.js +0 -63
  145. package/examples/shorts/timers.js +0 -53
  146. package/examples/shorts/topDown.js +0 -38
  147. package/examples/shorts/uiSystem.js +0 -61
  148. package/examples/shorts/video.webm +0 -0
  149. package/examples/shorts/videoPlayer.js +0 -34
  150. package/examples/starter/build.bat +0 -7
  151. package/examples/starter/build.mjs +0 -126
  152. package/examples/starter/game.js +0 -137
  153. package/examples/starter/index.html +0 -35
  154. package/examples/starter/tiles.png +0 -0
  155. package/examples/stress/index.html +0 -173
  156. package/examples/style.css +0 -150
  157. package/examples/typescript/build.mjs +0 -60
  158. package/examples/typescript/game.js +0 -100
  159. package/examples/typescript/game.ts +0 -132
  160. package/examples/typescript/index.html +0 -10
  161. package/examples/typescript/tiles.png +0 -0
  162. package/examples/typescript/tsconfig.json +0 -17
  163. package/examples/uiSystem/game.js +0 -139
  164. package/examples/uiSystem/index.html +0 -10
  165. package/examples/uiSystem/tiles.png +0 -0
  166. package/jsconfig.json +0 -12
  167. package/plugins/desktop.ini +0 -2
  168. package/reference.md +0 -447
  169. package/test/math.test.mjs +0 -774
  170. package/test/setup.mjs +0 -22
  171. package/test/smoke.test.mjs +0 -258
  172. package/test/util.test.mjs +0 -80
package/reference.md DELETED
@@ -1,447 +0,0 @@
1
- # LittleJS Engine Quick Reference Sheet
2
-
3
- ## This cheat sheet contains all LittleJS essentials.
4
- - [LittleJS on GitHub](https://github.com/KilledByAPixel/LittleJS) - Official LittleJS website with more info
5
- - [LittleJS Documentation](https://killedbyapixel.github.io/LittleJS/docs) - LittleJS documentation browser
6
- - [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles) - Editor for LittleJS Particle Systems
7
- - [Sound Effect Designer](https://killedbyapixel.github.io/ZzFX) - Tool for creating ZzFX sound effects
8
- - [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter) - Simple LittleJS demo to start with
9
-
10
- ## LittleJS Setup
11
-
12
- To start LittleJS, you need to create a few functions and pass them to engineInit.
13
-
14
- ```javascript
15
- // Start up LittleJS engine with your callback functions
16
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSources=[], rootElement=document.body)
17
- ```
18
-
19
- ## LittleJS Utilities Classes and Functions
20
- - General purpose math library
21
- - Vector2 - Fast, simple, easy 2D vector class
22
- - Color - Holds a rgba color with some math functions
23
- - Timer - Tracks time automatically
24
- - RandomGenerator - Seeded random number generator
25
-
26
- ```javascript
27
-
28
- // Object Constructors
29
- vec2(x=0, y=x) // Create a 2D vector with Vector or floats
30
- rgb(r=1, g=1, b=1, a=1) // Create a color object with RGBA values
31
- hsl(h=0, s=0, l=1, a=1) // Create a color object with HSLA values
32
- tile(pos, size=(16,16), texture=0, padding=0) // Create a tile info object
33
-
34
- // Helper functions
35
- abs(value) // Get absolute value
36
- min(...values) // Get lowest of values
37
- max(...values) // Get highest of values
38
- sign(value) // Get the sign of value
39
- mod(dividend, divisor=1) // Get remainder of division
40
- clamp(value, min=0, max=1) // Clamps between values
41
- percent(value, valueA, valueB) // Get percentage between values
42
- lerp(valueA, valueB, percent) // Linearly interpolates between values
43
- percentLerp(value, percentA, percentB, lerpA, lerpB) // Lerp that remaps the percent
44
- distanceWrap(valueA, valueB, wrapSize=1) // Signed wrapped distance between values
45
- lerpWrap(valueA, valueB, percent, wrapSize=1) // Linearly interpolates with wrapping
46
- distanceAngle(angleA, angleB) // Signed wrapped distance between angles
47
- lerpAngle(angleA, angleB, percent) // Linearly interpolates with wrapping
48
- smoothStep(percent) // Applies smoothstep function
49
- nearestPowerOfTwo(value) // Returns the nearest power of two
50
- isOverlapping(pointA, sizeA, pointB, sizeB) // Checks if bounding boxes overlap
51
- isIntersecting(start, end, pos, size) // Checks if ray intersects box
52
- formatTime(t) // Formats seconds for display
53
-
54
- // Random functions
55
- rand(valueA=1, valueB=0) // Random float between values
56
- randInt(valueA, valueB=0) // Random integer between values
57
- randBool(chance=.5) // Random boolean with given chance (0 to 1)
58
- randSign() // Randomly either -1 or 1
59
- randVec2(length=1) // Random Vector2 with the passed in length
60
- randInCircle(radius=1, minRadius=0) // Random Vector2 within a circle
61
- randColor(colorA, colorB, linear) // Random color between values
62
-
63
- // 2D vector math
64
- Vector2(x=0, y=0) // Create a 2D vector
65
- Vector2.copy() // Copy this vector
66
- Vector2.add(v) // Add a vector
67
- Vector2.subtract(v) // Subtract a vector
68
- Vector2.multiply(v) // Multiply by a vector
69
- Vector2.divide(v) // Divide by a vector
70
- Vector2.scale(s) // Scale by a float
71
- Vector2.length() // Get length
72
- Vector2.lengthSquared() // Get length squared
73
- Vector2.distance(v) // Get distance to vector
74
- Vector2.distanceSquared(v) // Get distance to vector squared
75
- Vector2.normalize(length=1) // Normalize this vector to length
76
- Vector2.clampLength(length=1) // Clamp this vector to length
77
- Vector2.dot(v) // Dot product with vector
78
- Vector2.cross(v) // Cross product with vector
79
- Vector2.floor() // Floor this vector
80
- Vector2.area() // Get area covered by this vector as a rectangle
81
- Vector2.lerp(v, percent) // Interpolate between vectors
82
- Vector2.arrayCheck(arraySize) // Check if in bounds of array size
83
- Vector2.angle() // Angle of this vector, up is 0
84
- Vector2.setAngle(angle=0, length=1) // Set angle and length
85
- Vector2.rotate(angle) // Rotate by angle
86
- Vector2.setDirection(direction, length=1) // Set integer direction (0-3) and length
87
- Vector2.direction() // Get integer direction (0-3)
88
- Vector2.toString(digits=3) // Get string representation
89
-
90
- // RGBA color object
91
- Color(r=1, g=1, b=1, a=1) // Create an RGBA color
92
- Color.copy() // Copy this color
93
- Color.add(c) // Add a color
94
- Color.subtract(c) // Subtract a color
95
- Color.multiply(c) // Multiply by a color
96
- Color.divide(c) // Divide by a color
97
- Color.scale(scale, alphaScale=scale) // Scale by a float
98
- Color.clamp() // Clamp this color
99
- Color.lerp(c, percent) // Interpolate between colors
100
- Color.setHSLA(h=0, s=0, l=1, a=1) // Set the color from HSLA values
101
- Color.HSLA() // Get the color in HSLA format
102
- Color.mutate(amount=.05, alphaAmount=0) // Randomly diverge from this color
103
- Color.setHex(hex) // Set this color from a hex code
104
- Color.rgbaInt() // Get this color as 32 bit RGBA value
105
- Color.toString(useAlpha=true) // Get hex color code as a string
106
-
107
- // Seeded random number generator
108
- RandomGenerator(seed) // Create a random number generator
109
- RandomGenerator.float(valueA=1, valueB=0) // Random float between values
110
- RandomGenerator.int(valueA, valueB=0) // Random integer between values
111
- RandomGenerator.sign() // Randomly either -1 or 1
112
-
113
- // Time tracking system
114
- Timer(timeLeft) // Create a timer object
115
- Timer.set(timeLeft=0) // Set the timer with seconds passed in
116
- Timer.unset() // Unset the timer
117
- Timer.isSet() // Returns true if set
118
- Timer.active() // Returns true if set and has not elapsed
119
- Timer.elapsed() // Returns true if set and elapsed
120
- Timer.get() // Get how long since elapsed, 0 if not set
121
- Timer.getPercent() // Get percent elapsed, 0 if not set
122
- Timer.toString() // Get this timer expressed as a string
123
- Timer.valueOf() // Get how long since elapsed, 0 if not set
124
- ```
125
-
126
- ## LittleJS Drawing System
127
- - Hybrid system with both Canvas2D and WebGL available
128
- - Super fast tile sheet rendering with WebGL
129
- - Can apply rotation, mirror, color and additive color
130
- - Text and font rendering system with built in engine font
131
-
132
- ```javascript
133
- // Drawing functions
134
- drawTile(pos, size, tileInfo, color=WHITE, angle=0, mirror, additiveColor)
135
- drawRect(pos, size, color=WHITE, angle=0)
136
- drawRectGradient(pos, size, colorTop=WHITE, colorBottom=BLACK, angle=0)
137
- drawLine(posA, posB, width=.1, color=WHITE, pos=(0,0), angle=0)
138
- drawLineList(points, width=.1, color, wrap=false, pos=(0,0), angle=0)
139
- drawPoly(points, color=WHITE, lineWidth=0, lineColor=BLACK, pos, angle=0)
140
- drawRegularPoly(pos, size=(1,1), sides=3, color=WHITE, lineWidth=0, lineColor=BLACK, angle=0)
141
- drawEllipse(pos, size=(1,1), color=WHITE, angle=0, lineWidth=0, lineColor=BLACK)
142
- drawCircle(pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
143
- drawCanvas2D(pos, size, angle=0, mirror, drawFunction, screenSpace, context)
144
-
145
- // Text functions
146
- drawText(text, pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
147
- drawTextScreen(text, pos, size=1, color=WHITE, lineWidth=0, lineColor=BLACK)
148
-
149
- // Utility drawing functions
150
- setBlendMode(additive)
151
- isFullscreen()
152
- toggleFullscreen()
153
-
154
- // Tile Info Object
155
- TileInfo(pos, size, textureIndex=0, padding=0) // Create a tile info object
156
- TileInfo.pos // Top left corner of tile in pixels
157
- TileInfo.size // Size of tile in pixels
158
- TileInfo.textureIndex // Texture index to use
159
- TileInfo.padding // How many pixels padding around tiles
160
- TileInfo.offset(offset) // Offset this tile by a certain amount in pixels
161
- TileInfo.frame(frame) // Offset this tile by a number of animation frames
162
- TileInfo.textureInfo // The texture info for this tile
163
-
164
- // Texture Info Object
165
- TextureInfo(image) // Created automatically for each image
166
- TextureInfo.image // Image source
167
- TextureInfo.size // Size of the image
168
- TextureInfo.glTexture // WebGL texture
169
-
170
- // Font Image Object draws text using characters in an image
171
- FontImage(image, tileSize=(8,8), paddingSize=(0,1)) // Create an image font
172
- FontImage.drawText(text, pos, scale, center) // Draw text in world space
173
- FontImage.drawTextScreen(text, pos, scale, center) // Draw text in screen space
174
-
175
- // Camera settings
176
- cameraPos = (0,0) // Position of camera in world space
177
- cameraScale = 32 // Scale of camera in world space
178
- screenToWorld(screenPos) // Convert from screen to world space coordinates
179
- worldToScreen(worldPos) // Convert from world to screen space coordinates
180
- getCameraSize() // Get the camera's visible area in world space
181
-
182
- // Display settings
183
- canvasMaxSize = (1920, 1200) // The max size of the canvas
184
- canvasFixedSize = (0, 0) // Fixed size of the canvas
185
- canvasClearColor = BLACK // Color used to clear the canvas at start of frame
186
- fontDefault = 'arial' // Default font used for text rendering
187
- canvasPixelated = true // Use nearest neighbor canvas scaling for more pixelated look
188
- tilesPixelated = true // Disable filtering for crisper pixel art
189
- showSplashScreen = false // Show the LittleJS splash screen on startup
190
- glEnable = true // Enable fast WebGL rendering
191
-
192
- // Tile sheet settings
193
- tileDefaultSize = (16,16) // Default size of tiles in pixels
194
- tileDefaultBleed = .3 // How much smaller to draw tiles to prevent bleeding
195
- ```
196
-
197
- ## LittleJS Audio System
198
- - Caches sounds and music for fast playback with frame-spread loading
199
- - Individual sound instance control with pause/resume capabilities
200
- - Can attenuate and apply stereo panning to sounds
201
- - Ability to play mp3, ogg, and wave files with loading progress tracking
202
- - [ZzFX Sound Effect Generator](https://killedbyapixel.github.io/ZzFX)
203
- - [ZzFXM Music System](https://keithclark.github.io/ZzFXM)
204
-
205
- ```javascript
206
- // Sound Object
207
- Sound(zzfxSound, randomness, range, taper) // Create a zzfx sound
208
- Sound(filename, randomness, range, taper) // Load a wave, mp3, or ogg
209
- Sound.play(pos, volume=1, pitch=1, randomness=1, loop) // Play a sound, returns SoundInstance
210
- Sound.playMusic(volume=1, loop=true) // Play as music with looping
211
- Sound.playNote(semitoneOffset, pos, volume=1) // Play as note with a semitone offset
212
- Sound.getDuration() // Get length of sound in seconds
213
- Sound.isLoaded() // Check if sound is currently loading
214
- Sound.loadedPercent // Get loading progress (0 to 1)
215
-
216
- // SoundInstance
217
- SoundInstance.start() // Start playing the sound
218
- SoundInstance.setVolume(volume) // Change volume during playback
219
- SoundInstance.stop(fadeTime=0) // Stop with optional fade out
220
- SoundInstance.pause() // Pause the sound
221
- SoundInstance.unpause() // Resume paused sound
222
- SoundInstance.isPlaying() // Check if currently playing
223
- SoundInstance.isPaused() // Check if paused
224
- SoundInstance.isStopped() // Check if stopped
225
- SoundInstance.getCurrentTime() // Get current playback position
226
- SoundInstance.getDuration() // Get total duration
227
- SoundInstance.getSource() // Get AudioBufferSourceNode
228
-
229
- // ZzFXM - Tiny music playing system
230
- Music(..zzfxMusic) // Create a zzfx music object
231
- Music.playMusic(volume=1, loop=true) // Play the music
232
-
233
- // Audio functions
234
- speak(text, language='', volume=1, rate=1, pitch=1) // Speak text line
235
- speakStop() // Stop all queued speech
236
- getNoteFrequency(semitoneOffset, rootFrequency=220) // Get frequency for musical notes
237
-
238
- // Audio settings
239
- soundEnable = true // Should sound be enabled?
240
- soundVolume = .5 // Volume scale to apply to all sound
241
- soundDefaultRange = 40 // Default range where sound no longer plays
242
- soundDefaultTaper = .7 // Default range percent to taper off sound (0-1)
243
- ```
244
-
245
- ## LittleJS Input System
246
- - Tracks keyboard down, pressed, and released
247
- - Tracks mouse buttons, position, and wheel
248
- - Tracks multiple analog gamepads
249
- - Routes touch input to mouse
250
- - Virtual gamepad for touch devices
251
-
252
- ```javascript
253
- // Keyboard
254
- keyIsDown(key) // Is key down?
255
- keyWasPressed(key) // Was key pressed this frame?
256
- keyWasReleased(key) // Was key released this frame?
257
- keyDirection(up, down, left, right) // Get input vector from arrow keys or wasd
258
-
259
- // Mouse / Touch
260
- mousePos // World space mouse position
261
- mousePosScreen // Screen space mouse position
262
- mouseDelta // World space mouse movement delta
263
- mouseDeltaScreen // Screen space mouse movement delta
264
- mouseWheel // Delta mouse wheel this frame
265
- mouseIsDown(button) // Is mouse button down?
266
- mouseWasPressed(button) // Was mouse button pressed this frame?
267
- mouseWasReleased(button) // Was mouse button released this frame?
268
-
269
- // Gamepad
270
- isUsingGamepad // Is user currently using gamepad?
271
- gamepadIsDown(button, gamepad=0) // Is gamepad button down?
272
- gamepadWasPressed(button, gamepad=0) // Was gamepad button pressed this frame?
273
- gamepadWasReleased(button, gamepad=0) // Was gamepad button released this frame?
274
- gamepadStick(stickIndex, gamepad=0) // Get gamepad analog stick value
275
-
276
- // Touch Gamepad
277
- touchGamepadEnabled // Is on screen touch gamepad enabled?
278
- touchGamepadAnalog // Is touch gamepad analog or 8 way dpad?
279
- touchGamepadSize // Size of touch gamepad
280
- touchGamepadAlpha // Alpha of touch gamepad
281
-
282
- // Vibration
283
- vibrate(pattern=100) // Pulse the vibration hardware if it exists
284
- vibrateStop() // Stop all vibration
285
-
286
- // Input settings
287
- gamepadsEnable = true // Should gamepads be allowed?
288
- gamepadDirectionEmulateStick = true // Should dpad be routed to the left analog stick?
289
- inputWASDEmulateDirection = true // Should WASD keys be routed to the direction keys?
290
- vibrateEnable = true // Allow vibration hardware if it exists?
291
- touchGamepadEnable = false // Should touch gamepad appear on mobile devices?
292
- touchGamepadAnalog = true // Should touch gamepad be analog or 8 way dpad?
293
- touchGamepadSize = 99 // Size of virtual gamepad for touch devices
294
- touchGamepadAlpha = .3 // Transparency of touch gamepad overlay
295
- ```
296
-
297
- ## LittleJS Object System
298
- - Top level object class used by the engine
299
- - Automatically adds self to object list
300
- - Will be updated and rendered each frame
301
- - Renders as a sprite from a tile sheet by default
302
- - Can have color and addtive color applied
303
- - 2D Physics and collision system
304
- - Sorted by renderOrder before drawing
305
- - Objects can have children in local space
306
- - Parents are updated before children
307
- - Call destroy() to get rid of objects
308
-
309
- ```javascript
310
- // Engine Object
311
- EngineObject(pos, size=(1,1), tileInfo, angle=0, color, renderOrder=0)
312
- EngineObject.update() // Update object, called automatically
313
- EngineObject.render() // Render object, called automatically
314
- EngineObject.destroy() // Destroy this object and children
315
- EngineObject.collideWithTile(tileData, pos) // Tile collision resolve check
316
- EngineObject.collideWithObject(object) // Object collision resolve check
317
- EngineObject.getAliveTime() // How long since object was created
318
- EngineObject.applyAcceleration(acceleration) // Apply acceleration
319
- EngineObject.applyForce(force) // Apply force
320
- EngineObject.getMirrorSign() // Get mirror direction (1 or -1)
321
- EngineObject.addChild(child, localPos, localAngle) // Attach a child
322
- EngineObject.removeChild(child) // Remove a child
323
- EngineObject.setCollision(solids, isSolid, tiles) // Set collision
324
-
325
- // Engine Object Members
326
- EngineObject.pos // World space position
327
- EngineObject.size // World space width and height
328
- EngineObject.drawSize // Size of object used for drawing if set
329
- EngineObject.tileInfo // Tile info to render object
330
- EngineObject.angle // Rotation angle for rendering
331
- EngineObject.color // Color to apply when rendered
332
- EngineObject.additiveColor // Additive color to apply when rendered
333
- EngineObject.mirror // Should it flip along y axis when rendered
334
- EngineObject.mass // Weight of object, static if 0
335
- EngineObject.damping // How much to slow velocity each frame (0-1)
336
- EngineObject.angleDamping // How much to slow rotation each frame (0-1)
337
- EngineObject.restitution // How bouncy is it when colliding (0-1)
338
- EngineObject.friction // How much friction when sliding (0-1)
339
- EngineObject.gravityScale // How much to scale gravity by
340
- EngineObject.renderOrder // Objects are sorted by render order
341
- EngineObject.velocity // Velocity of the object
342
- EngineObject.angleVelocity // Angular velocity of the object
343
-
344
- // Engine Object settings
345
- enablePhysicsSolver = true // Enable collisions between objects?
346
- objectDefaultMass = 1 // Default object mass for collisions
347
- objectDefaultDamping = 1 // How much to slow velocity by each frame (0-1)
348
- objectDefaultAngleDamping = 1 // How much to slow angular velocity each frame (0-1)
349
- objectDefaultRestitution = 0 // How much to bounce when a collision occurs (0-1)
350
- objectDefaultFriction = .8 // How much to slow when touching (0-1)
351
- objectMaxSpeed = 1 // Clamp max speed to avoid fast objects missing collisions
352
- gravity = (0,0) // How much gravity to apply to objects
353
-
354
- // Engine Object functions
355
- engineObjectsCollect(pos, size, objects=engineObjects)
356
- engineObjectsCallback(pos, size, callbackFunction, objects=engineObjects)
357
- engineObjectsRaycast(start, end, objects=engineObjects)
358
- engineObjectsDestroy()
359
- ```
360
-
361
- ## LittleJS Tile Layer System
362
- - Caches arrays of tiles to off screen canvas for fast rendering
363
- - Unlimited numbers of layers, allocates canvases as needed
364
- - Interfaces with EngineObject for collision
365
- - Collision layer is separate from visible layers
366
- - It is recommended to have a visible layer that matches the collision
367
- - Tile layers can be drawn to using their context with Canvas2d
368
- - Drawn directly to the main canvas without using WebGL
369
-
370
- ```javascript
371
-
372
- // Canvas Layer
373
- CanvasLayer(pos, size) // Create a canvas layer object
374
- CanvasLayer.canvas // The canvas used by this layer
375
- CanvasLayer.context // The 2D context of the canvas
376
- CanvasLayer.getImageData() // Get image data from canvas
377
- CanvasLayer.updateWebGL() // Creates or updates WebGL texture
378
-
379
- // LittleJS Layer System
380
- TileLayer(pos, size, tileInfo, scale) // Create a tile layer object
381
- TileLayer.setData(layerPos, data, redraw) // Set data at position
382
- TileLayer.clearData(layerPos, redraw) // Clear data at position
383
- TileLayer.getData(layerPos) // Get data at position
384
- TileLayer.redraw() // Draw to an offscreen canvas
385
- TileLayer.drawTileData(layerPos, clear=true) // Draw the tile
386
- TileLayer.drawRect(pos, size, color, angle) // Draw a rectangle to 2D canvas
387
- TileLayer.drawTile(pos, size=(1,1), tileInfo, color, angle, mirror) // Draw tile
388
- TileLayer.drawCanvas2D(pos, size, angle, mirror, drawFunction) // Draw to 2D canvas
389
-
390
- // Tile Layer Data Object
391
- TileLayerData(tile, direction=0, mirror=false, color=WHITE) // Create tile data object
392
- TileLayerData.clear() // Clear this tile data
393
-
394
- // Tile Collision Layer
395
- TileCollisionLayer(pos, size, tileInfo=tile()) // Create a tile collision layer object
396
- TileCollisionLayer.setCollisionData(pos, data=1) // Set tile collision data at pos
397
- tileCollisionGetData(pos) // Get tile collision data at pos
398
- tileCollisionTest(pos, size=(0,0), object) // Check if collision should occur
399
- tileCollisionRaycast(posStart, posEnd, object) // Return the center of tile if hit
400
- tileLayersLoad(tileMapData, tileInfo) // Load tile layers from exported data
401
-
402
- ```
403
-
404
- ## LittleJS Particle System
405
- - Simple kinematic particle system with many parameters
406
- - [Particle Effect Designer](https://killedbyapixel.github.io/LittleJS/examples/particles) - Editor for creating LittleJS Particle Systems
407
-
408
- ```javascript
409
- // Particle Emitter Object
410
- ParticleEmitter(pos, angle, ...settings) // Create a particle system
411
- ParticleEmitter.emitParticle() // Spawn one particle
412
-
413
- // Particle Settings
414
- particleEmitRateScale = 1 // Scales particles emit rate
415
- ```
416
-
417
- ## LittleJS Debugging System
418
- - Press Escape key to toggle debug overlay
419
- - Number keys toggle debug functions
420
- - +/- keys apply time scale to update
421
- - Debug primitive rendering system
422
- - Debug functions are only active in debug builds
423
-
424
- ```javascript
425
- ASSERT(assert, output) // Asserts if the expression is false
426
- debugRect(pos, size, color='#fff', time=0, angle=0, fill) // Draw debug rectangle
427
- debugCircle(pos, size, color='#fff', time=0, fill) // Draw debug circle
428
- debugPoint(pos, color, time, angle) // Draw debug point
429
- debugLine(posA, posB, color, width=.1, time) // Draw debug line
430
- debugText(text, pos, size=1, color='#fff', time=0, angle=0) // Draw debug text
431
- debugAABB(pA, sA, pB, sB, color) // Draw a debug axis aligned box
432
- debugClear() // Clear all debug primitives
433
- saveCanvas(canvas, filename) // Save canvas to a file
434
- saveText(text, filename) // Save text to a file
435
- saveDataURL(dataURL, filename) // Save url to a file
436
-
437
- // Debug settings
438
- debug // Is debug enabled?
439
- debugPointSize = .5 // Size to render debug points by default
440
- debugKey = 'Escape' // Key code used to toggle debug mode
441
- debugOverlay // Is the debug overlay is active?
442
- debugWatermark // Should watermark with FPS appear in debug mode?
443
- ```
444
-
445
- [LittleJS Engine](https://github.com/KilledByAPixel/LittleJS) Copyright 2021 Frank Force
446
-
447
- ![LittleJS Logo](examples/favicon.png)