littlejsengine 1.2.3 → 1.3.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.
Files changed (94) hide show
  1. package/README.md +4 -3
  2. package/build.bat +6 -6
  3. package/buildSetup.bat +7 -0
  4. package/docs/Audio.html +2268 -0
  5. package/docs/Color.html +3376 -0
  6. package/docs/Debug.html +2933 -0
  7. package/docs/Draw.html +4480 -0
  8. package/docs/EngineObject.html +4734 -0
  9. package/docs/FontImage.html +1055 -0
  10. package/docs/Input.html +2806 -0
  11. package/docs/Medal.html +1007 -0
  12. package/docs/Medals.html +628 -0
  13. package/docs/Music.html +584 -0
  14. package/docs/Newgrounds.html +1399 -0
  15. package/docs/Particle.html +4825 -0
  16. package/docs/ParticleEmitter.html +8099 -0
  17. package/docs/Random.html +1774 -0
  18. package/docs/Settings.html +3140 -0
  19. package/docs/Sound.html +1249 -0
  20. package/docs/TileCollision.html +1409 -0
  21. package/docs/TileLayer.html +7310 -0
  22. package/docs/TileLayerData.html +1052 -0
  23. package/docs/Timer.html +1295 -0
  24. package/docs/Utilities.html +3278 -0
  25. package/docs/Vector2.html +4266 -0
  26. package/docs/WebGL.html +2307 -0
  27. package/docs/engine.js.html +443 -0
  28. package/docs/engineAudio.js.html +627 -0
  29. package/docs/engineDebug.js.html +554 -0
  30. package/docs/engineDraw.js.html +539 -0
  31. package/docs/engineInput.js.html +571 -0
  32. package/docs/engineMedals.js.html +460 -0
  33. package/docs/engineObject.js.html +533 -0
  34. package/docs/engineParticles.js.html +443 -0
  35. package/docs/engineSettings.js.html +381 -0
  36. package/docs/engineTileLayer.js.html +503 -0
  37. package/docs/engineUtilities.js.html +700 -0
  38. package/docs/engineWebGL.js.html +511 -0
  39. package/docs/fonts/MavenPro-Regular.ttf +0 -0
  40. package/docs/fonts/Montserrat-Regular.ttf +0 -0
  41. package/docs/fonts/Muli-Black.ttf +0 -0
  42. package/docs/fonts/OFL-hind.txt +93 -0
  43. package/docs/fonts/OFL-montserrat.txt +93 -0
  44. package/docs/global.html +1771 -0
  45. package/docs/index.css +6 -0
  46. package/docs/index.html +267 -0
  47. package/docs/scripts/fix-code-block.js +53 -0
  48. package/docs/scripts/fix-navbar.js +25 -0
  49. package/docs/scripts/linenumber.js +25 -0
  50. package/docs/scripts/misc.js +217 -0
  51. package/docs/scripts/resize.js +85 -0
  52. package/docs/scripts/search.js +83 -0
  53. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  54. package/docs/scripts/third-party/fuse.js +9 -0
  55. package/docs/scripts/third-party/lang-css.js +2 -0
  56. package/docs/scripts/third-party/prettify.js +28 -0
  57. package/docs/static/favicon.png +0 -0
  58. package/docs/static/index.css +4 -0
  59. package/docs/styles/clean-jsdoc-theme-base.css +393 -0
  60. package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
  61. package/docs/styles/clean-jsdoc-theme-light.css +319 -0
  62. package/docs/styles/reset.css +346 -0
  63. package/docs/styles/third-party/ionicons.min.css +11 -0
  64. package/docs/styles/third-party/prettify-jsdoc.css +111 -0
  65. package/docs/styles/third-party/prettify-tomorrow.css +5 -0
  66. package/engine/engine.all.js +171 -67
  67. package/engine/engine.all.min.js +1 -1
  68. package/engine/engine.all.release.js +162 -53
  69. package/engine/engine.js +3 -3
  70. package/engine/engineAudio.js +5 -7
  71. package/engine/engineBuild.bat +3 -4
  72. package/engine/engineDebug.js +9 -14
  73. package/engine/engineDraw.js +32 -13
  74. package/engine/engineInput.js +5 -1
  75. package/engine/engineMedals.js +5 -2
  76. package/engine/engineObject.js +24 -5
  77. package/engine/engineParticles.js +2 -2
  78. package/engine/engineSettings.js +5 -0
  79. package/engine/engineTileLayer.js +11 -10
  80. package/engine/engineUtilities.js +67 -7
  81. package/engine/engineWebGL.js +3 -3
  82. package/engine/index.d.ts +57 -18
  83. package/examples/breakout/index.html +3 -3
  84. package/examples/particles/index.html +366 -0
  85. package/examples/particles/tiles.png +0 -0
  86. package/examples/platformer/gameEffects.js +6 -6
  87. package/examples/platformer/index.html +6 -6
  88. package/examples/puzzle/game.js +4 -2
  89. package/examples/puzzle/index.html +2 -2
  90. package/examples/stress/index.html +1 -1
  91. package/game.js +3 -14
  92. package/index.html +13 -13
  93. package/package.json +1 -1
  94. package/engine/engineBuildSetup.bat +0 -7
@@ -110,7 +110,7 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, col
110
110
  if (tileIndex < 0)
111
111
  {
112
112
  // if negative tile index, force untextured
113
- context.fillStyle = color.rgba();
113
+ context.fillStyle = color;
114
114
  context.fillRect(-.5, -.5, 1, 1);
115
115
  }
116
116
  else
@@ -165,7 +165,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
165
165
  * @memberof Draw */
166
166
  function drawRectScreenSpace(pos, size, color, angle, useWebGL)
167
167
  {
168
- drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
168
+ drawTileScreenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
169
169
  }
170
170
 
171
171
  /** Draw colored line between two points
@@ -215,7 +215,8 @@ function setBlendMode(additive, useWebGL=glEnable)
215
215
  mainContext.globalCompositeOperation = additive ? 'lighter' : 'source-over';
216
216
  }
217
217
 
218
- /** Draw text on overlay canvas in world space
218
+ /** Draw text on overlay canvas in screen space
219
+ * Automatically splits new lines into rows
219
220
  * @param {String} text
220
221
  * @param {Vector2} pos
221
222
  * @param {Number} [size=1]
@@ -224,20 +225,38 @@ function setBlendMode(additive, useWebGL=glEnable)
224
225
  * @param {Color} [lineColor=new Color(0,0,0)]
225
226
  * @param {String} [textAlign='center']
226
227
  * @memberof Draw */
227
- function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
228
+ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
228
229
  {
229
- pos = worldToScreen(pos);
230
- overlayContext.font = size*cameraScale + 'px '+ font;
230
+ overlayContext.fillStyle = color;
231
+ overlayContext.lineWidth = lineWidth;
232
+ overlayContext.strokeStyle = lineColor;
231
233
  overlayContext.textAlign = textAlign;
234
+ overlayContext.font = size + 'px '+ font;
232
235
  overlayContext.textBaseline = 'middle';
233
- if (lineWidth)
236
+ overlayContext.lineJoin = 'round';
237
+
238
+ pos = pos.copy();
239
+ text.split('\n').forEach(line=>
234
240
  {
235
- overlayContext.lineWidth = lineWidth*cameraScale;
236
- overlayContext.strokeStyle = lineColor.rgba();
237
- overlayContext.strokeText(text, pos.x, pos.y);
238
- }
239
- overlayContext.fillStyle = color.rgba();
240
- overlayContext.fillText(text, pos.x, pos.y);
241
+ lineWidth && overlayContext.strokeText(line, pos.x, pos.y);
242
+ overlayContext.fillText(line, pos.x, pos.y);
243
+ pos.y += size;
244
+ });
245
+ }
246
+
247
+ /** Draw text on overlay canvas in world space
248
+ * Automatically splits new lines into rows
249
+ * @param {String} text
250
+ * @param {Vector2} pos
251
+ * @param {Number} [size=1]
252
+ * @param {Color} [color=new Color(1,1,1)]
253
+ * @param {Number} [lineWidth=0]
254
+ * @param {Color} [lineColor=new Color(0,0,0)]
255
+ * @param {String} [textAlign='center']
256
+ * @memberof Draw */
257
+ function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, font)
258
+ {
259
+ drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font);
241
260
  }
242
261
 
243
262
  ///////////////////////////////////////////////////////////////////////////////
@@ -70,6 +70,10 @@ let mouseWheel = 0;
70
70
  * @memberof Input */
71
71
  let isUsingGamepad = 0;
72
72
 
73
+ /** Prevents input continuing to the default browser handling (false by default)
74
+ * @memberof Input */
75
+ let preventDefaultInput = 0;
76
+
73
77
  /** Returns true if gamepad button is down
74
78
  * @param {Number} button
75
79
  * @param {Number} [gamepad=0]
@@ -133,7 +137,7 @@ onkeydown = (e)=>
133
137
  {
134
138
  if (debug && e.target != document.body) return;
135
139
  e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
136
- debug || e.preventDefault();
140
+ preventDefaultInput && e.preventDefault();
137
141
  }
138
142
  onkeyup = (e)=>
139
143
  {
@@ -35,7 +35,7 @@ function medalsInit(saveName)
35
35
  {
36
36
  // check if medals are unlocked
37
37
  medalsSaveName = saveName;
38
- debugMedals || medals.forEach(medal=> medal.unlocked = 1 || localStorage[medal.storageKey()]);
38
+ debugMedals || medals.forEach(medal=> localStorage[medal.storageKey()]);
39
39
  }
40
40
 
41
41
  /**
@@ -192,7 +192,7 @@ class Newgrounds
192
192
  cipher && (this.cryptoJS = CryptoJS());
193
193
 
194
194
  // get session id from url search params
195
- const url = new URL(window.location.href);
195
+ const url = new URL(location.href);
196
196
  this.session_id = url.searchParams.get('ngio_session_id') || 0;
197
197
 
198
198
  if (this.session_id == 0)
@@ -224,6 +224,9 @@ class Newgrounds
224
224
  const scoreboardResult = this.call('ScoreBoard.getBoards');
225
225
  this.scoreboards = scoreboardResult ? scoreboardResult.result.data.scoreboards : [];
226
226
  debugMedals && console.log(this.scoreboards);
227
+
228
+ const keepAliveMS = 5 * 60 * 1e3;
229
+ setInterval(()=>this.call('Gateway.ping', 0, 1), keepAliveMS);
227
230
  }
228
231
 
229
232
  /** Send message to unlock a medal by id
@@ -34,9 +34,9 @@ class EngineObject
34
34
  /** Create an engine object and adds it to the list of objects
35
35
  * @param {Vector2} [position=new Vector2()] - World space position of the object
36
36
  * @param {Vector2} [size=objectDefaultSize] - World space size of the object
37
- * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
37
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
38
38
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
39
- * @param {Number} [angle=0] - Angle to rotate the object
39
+ * @param {Number} [angle=0] - Angle the object is rotated by
40
40
  * @param {Color} [color] - Color to apply to tile when rendered
41
41
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
42
42
  */
@@ -51,7 +51,7 @@ class EngineObject
51
51
  this.size = size;
52
52
  /** @property {Vector2} - Size of object used for drawing, uses size if not set */
53
53
  this.drawSize;
54
- /** @property {Number} - Tile to use to render object, untextured if -1 */
54
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
55
55
  this.tileIndex = tileIndex;
56
56
  /** @property {Vector2} - Size of tile in source pixels */
57
57
  this.tileSize = tileSize;
@@ -63,7 +63,7 @@ class EngineObject
63
63
  this.additiveColor;
64
64
 
65
65
  // set object defaults
66
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
66
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
67
67
  this.mass = objectDefaultMass;
68
68
  /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
69
69
  this.damping = objectDefaultDamping;
@@ -117,7 +117,7 @@ class EngineObject
117
117
  ASSERT(this.angleDamping >= 0 && this.angleDamping <= 1);
118
118
  ASSERT(this.damping >= 0 && this.damping <= 1);
119
119
 
120
- if (!this.mass) // do not update collision for fixed objects
120
+ if (!enablePhysicsSolver || !this.mass) // do not update collision for fixed objects
121
121
  return;
122
122
 
123
123
  const wasMovingDown = this.velocity.y < 0;
@@ -352,4 +352,23 @@ class EngineObject
352
352
  this.isSolid = isSolid;
353
353
  this.collideTiles = collideTiles;
354
354
  }
355
+
356
+ toString()
357
+ {
358
+ if (debug)
359
+ {
360
+ let text = 'type = ' + this.constructor.name;
361
+ if (this.pos.x || this.pos.y)
362
+ text += '\npos = ' + this.pos;
363
+ if (this.velocity.x || this.velocity.y)
364
+ text += '\nvelocity = ' + this.velocity;
365
+ if (this.size.x || this.size.y)
366
+ text += '\nsize = ' + this.size;
367
+ if (this.angle)
368
+ text += '\nangle = ' + this.angle.toFixed(3);
369
+ if (this.color)
370
+ text += '\ncolor = ' + this.color;
371
+ return text;
372
+ }
373
+ }
355
374
  }
@@ -28,7 +28,7 @@ class ParticleEmitter extends EngineObject
28
28
  {
29
29
  /** Create a particle system with the given settings
30
30
  * @param {Vector2} position - World space position of the emitter
31
- * @param {Number} [angle=0] - Angle to rotate the object
31
+ * @param {Number} [angle=0] - Angle to emit the particles
32
32
  * @param {Number} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
33
33
  * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
34
34
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
@@ -113,7 +113,7 @@ class ParticleEmitter extends EngineObject
113
113
  // particle settings
114
114
  /** @property {Number} - How long particles live */
115
115
  this.particleTime = particleTime;
116
- /** @property {Number} - How big are particles at start */
116
+ /** @property {Number} - How big are particles at start */
117
117
  this.sizeStart = sizeStart;
118
118
  /** @property {Number} - How big are particles at end */
119
119
  this.sizeEnd = sizeEnd;
@@ -53,6 +53,11 @@ let tileFixBleedScale = .3;
53
53
  * @memberof Settings */
54
54
  let objectDefaultSize = vec2(1);
55
55
 
56
+ /** Enable physics solver for collisions between objects
57
+ * @default
58
+ * @memberof Settings */
59
+ let enablePhysicsSolver = 1;
60
+
56
61
  /** Default object mass for collison calcuations (how heavy objects are)
57
62
  * @default
58
63
  * @memberof Settings */
@@ -153,14 +153,14 @@ class TileLayerData
153
153
  */
154
154
  class TileLayer extends EngineObject
155
155
  {
156
- /** Create a tile layer object
157
- * @param {Vector2} [position=new Vector2()] - World space position
158
- * @param {Vector2} [size=objectDefaultSize] - World space size
159
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
160
- * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
161
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
162
- */
163
- constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
156
+ /** Create a tile layer object
157
+ * @param {Vector2} [position=new Vector2()] - World space position
158
+ * @param {Vector2} [size=tileCollisionSize] - World space size
159
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
160
+ * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
161
+ * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
162
+ */
163
+ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
164
164
  {
165
165
  super(pos, size, -1, tileSize, 0, undefined, renderOrder);
166
166
 
@@ -320,7 +320,7 @@ class TileLayer extends EngineObject
320
320
  if (tileIndex < 0)
321
321
  {
322
322
  // untextured
323
- context.fillStyle = color.rgba();
323
+ context.fillStyle = color;
324
324
  context.fillRect(-.5, -.5, 1, 1);
325
325
  }
326
326
  else
@@ -339,5 +339,6 @@ class TileLayer extends EngineObject
339
339
  * @param {Vector2} [size=new Vector2(1,1)]
340
340
  * @param {Color} [color=new Color(1,1,1)]
341
341
  * @param {Number} [angle=0] */
342
- drawRect(pos, size, color, angle) { this.drawTile(pos, size, -1, 0, color, angle); }
342
+ drawRect(pos, size, color, angle)
343
+ { this.drawTile(pos, size, -1, 0, color, angle); }
343
344
  }
@@ -300,7 +300,7 @@ class Vector2
300
300
 
301
301
  /** Returns the area this vector covers as a rectangle
302
302
  * @return {Number} */
303
- area() { return this.x * this.y; }
303
+ area() { return abs(this.x * this.y); }
304
304
 
305
305
  /** Returns a new vector that is p percent between this and the vector passed in
306
306
  * @param {Vector2} vector
@@ -311,7 +311,13 @@ class Vector2
311
311
  /** Returns true if this vector is within the bounds of an array size passed in
312
312
  * @param {Vector2} arraySize
313
313
  * @return {Boolean} */
314
- arrayCheck(arraySize) { return this.x >= 0 && this.y >= 0 && this.x < arraySize.x && this.y < arraySize.y; }
314
+ arrayCheck(arraySize) { return this.x >= 0 && this.y >= 0 && this.x < arraySize.x && this.y < arraySize.y; }
315
+
316
+ /** Returns this vector expressed as a string
317
+ * @param {float} digits - precision to display
318
+ * @return {String} */
319
+ toString(digits=3)
320
+ { return `(${(this.x<0?'':' ') + this.x.toFixed(digits)},${(this.y<0?'':' ') + this.y.toFixed(digits)} )`; }
315
321
  }
316
322
 
317
323
  ///////////////////////////////////////////////////////////////////////////////
@@ -382,7 +388,7 @@ class Color
382
388
  * @return {Color} */
383
389
  lerp(c, p) { return this.add(c.subtract(this).scale(clamp(p))); }
384
390
 
385
- /** Sets this color given a hue, saturation, lightness , and alpha
391
+ /** Sets this color given a hue, saturation, lightness, and alpha
386
392
  * @param {Number} [hue=0]
387
393
  * @param {Number} [saturation=0]
388
394
  * @param {Number} [lightness=1]
@@ -418,21 +424,71 @@ class Color
418
424
  ).clamp();
419
425
  }
420
426
 
421
- /** Returns this color expressed as an rgba string
427
+ /** Returns this color expressed as an CSS color value
422
428
  * @return {String} */
423
- rgba()
429
+ toString()
424
430
  {
425
431
  ASSERT(this.r>=0 && this.r<=1 && this.g>=0 && this.g<=1 && this.b>=0 && this.b<=1 && this.a>=0 && this.a<=1);
426
432
  return `rgb(${this.r*255|0},${this.g*255|0},${this.b*255|0},${this.a})`;
427
433
  }
428
434
 
429
- /** Returns this color expressed as 32 bit integer value
435
+ /** Returns this color expressed as 32 bit integer RGBA value
430
436
  * @return {Number} */
431
437
  rgbaInt()
432
438
  {
433
439
  ASSERT(this.r>=0 && this.r<=1 && this.g>=0 && this.g<=1 && this.b>=0 && this.b<=1 && this.a>=0 && this.a<=1);
434
440
  return (this.r*255|0) + (this.g*255<<8) + (this.b*255<<16) + (this.a*255<<24);
435
441
  }
442
+
443
+ /** Returns this color expressed as a hex code
444
+ * @return {String} */
445
+ hex()
446
+ {
447
+ const toHex = (c)=> ((c=c*255|0)<16 ? '0' : '') + c.toString(16);
448
+ return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b);
449
+ }
450
+
451
+ /** Returns this color expressed in hsla format
452
+ * @return {Array} */
453
+ getHSLA()
454
+ {
455
+ const r = this.r;
456
+ const g = this.g;
457
+ const b = this.b;
458
+ const a = this.a;
459
+ const max = Math.max(r, g, b);
460
+ const min = Math.min(r, g, b);
461
+ const l = (max + min) / 2;
462
+
463
+ let h = 0, s = 0;
464
+ if (max != min)
465
+ {
466
+ let d = max - min;
467
+ s = l > .5 ? d / (2 - max - min) : d / (max + min);
468
+ if (r == max)
469
+ h = (g - b) / d + (g < b ? 6 : 0);
470
+ else if (g == max)
471
+ h = (b - r) / d + 2;
472
+ else if (b == max)
473
+ h = (r - g) / d + 4;
474
+ }
475
+
476
+ return [h / 6, s, l, a];
477
+ }
478
+
479
+ /** Set this color from a hex code
480
+ * @param {String} hex - html hex code
481
+ * @return {Color} */
482
+ setHex(hex)
483
+ {
484
+ const fromHex = (a)=> parseInt(hex.slice(a,a+2), 16)/255;
485
+ this.r = fromHex(1);
486
+ this.g = fromHex(3),
487
+ this.b = fromHex(5);
488
+ this.a = 1;
489
+ ASSERT(this.r>=0 && this.r<=1 && this.g>=0 && this.g<=1 && this.b>=0 && this.b<=1);
490
+ return this;
491
+ }
436
492
  }
437
493
 
438
494
  ///////////////////////////////////////////////////////////////////////////////
@@ -469,7 +525,7 @@ class Timer
469
525
 
470
526
  /** Returns true if set and elapsed
471
527
  * @return {Boolean} */
472
- elapsed() { return time > this.time; }
528
+ elapsed() { return time > this.time; }
473
529
 
474
530
  /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
475
531
  * @return {Number} */
@@ -478,4 +534,8 @@ class Timer
478
534
  /** Get percentage elapsed based on time it was set to, returns 0 if not set
479
535
  * @return {Number} */
480
536
  getPercent() { return this.isSet()? percent(this.time - time, this.setTime, 0) : 0; }
537
+
538
+ /** Returns this timer expressed as a string
539
+ * @return {String} */
540
+ toString() { if (debug) { return this.unset() ? 'unset' : Math.abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ); } }
481
541
  }
@@ -47,7 +47,7 @@ function glInit()
47
47
 
48
48
  // setup vertex and fragment shaders
49
49
  glShader = glCreateProgram(
50
- 'precision highp float;'+ // use highp for better accuracy, lowp for better perf
50
+ 'precision highp float;'+ // use highp for better accuracy
51
51
  'uniform mat4 m;'+ // transform matrix
52
52
  'attribute vec2 p,t;'+ // position, uv
53
53
  'attribute vec4 c,a;'+ // color, additiveColor
@@ -58,7 +58,7 @@ function glInit()
58
58
  'v=t;d=c;e=a;'+ // pass stuff to fragment shader
59
59
  '}' // end of shader
60
60
  ,
61
- 'precision highp float;'+ // use highp for better accuracy, lowp for better perf
61
+ 'precision highp float;'+ // use highp for better accuracy
62
62
  'varying vec2 v;'+ // uv
63
63
  'varying vec4 d,e;'+ // color, additiveColor
64
64
  'uniform sampler2D s;'+ // texture
@@ -244,7 +244,7 @@ function glFlush()
244
244
  * @memberof WebGL */
245
245
  function glCopyToContext(context, forceDraw)
246
246
  {
247
- if (!glEnable || !glBatchCount) return;
247
+ if ((!glEnable || !glBatchCount) && !forceDraw) return;
248
248
 
249
249
  glFlush();
250
250
 
package/engine/index.d.ts CHANGED
@@ -60,7 +60,19 @@ declare function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror
60
60
  * @param {Boolean} [useWebGL=glEnable]
61
61
  * @memberof Draw */
62
62
  declare function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
63
+ /** Draw text on overlay canvas in screen space
64
+ * Automatically splits new lines into rows
65
+ * @param {String} text
66
+ * @param {Vector2} pos
67
+ * @param {Number} [size=1]
68
+ * @param {Color} [color=new Color(1,1,1)]
69
+ * @param {Number} [lineWidth=0]
70
+ * @param {Color} [lineColor=new Color(0,0,0)]
71
+ * @param {String} [textAlign='center']
72
+ * @memberof Draw */
73
+ declare function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string): void;
63
74
  /** Draw text on overlay canvas in world space
75
+ * Automatically splits new lines into rows
64
76
  * @param {String} text
65
77
  * @param {Vector2} pos
66
78
  * @param {Number} [size=1]
@@ -69,7 +81,7 @@ declare function setBlendMode(additive?: boolean, useWebGL?: boolean): void;
69
81
  * @param {Color} [lineColor=new Color(0,0,0)]
70
82
  * @param {String} [textAlign='center']
71
83
  * @memberof Draw */
72
- declare function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font?: string): void;
84
+ declare function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: string, font: any): void;
73
85
  /** Toggle fullsceen mode
74
86
  * @memberof Draw */
75
87
  declare function toggleFullscreen(): void;
@@ -551,6 +563,10 @@ declare class Vector2 {
551
563
  * @param {Vector2} arraySize
552
564
  * @return {Boolean} */
553
565
  arrayCheck(arraySize: Vector2): boolean;
566
+ /** Returns this vector expressed as a string
567
+ * @param {float} digits - precision to display
568
+ * @return {String} */
569
+ toString(digits?: float): string;
554
570
  }
555
571
  /**
556
572
  * Color object (red, green, blue, alpha) with some helpful functions
@@ -606,7 +622,7 @@ declare class Color {
606
622
  * @param {Number} percent
607
623
  * @return {Color} */
608
624
  lerp(c: any, p: any): Color;
609
- /** Sets this color given a hue, saturation, lightness , and alpha
625
+ /** Sets this color given a hue, saturation, lightness, and alpha
610
626
  * @param {Number} [hue=0]
611
627
  * @param {Number} [saturation=0]
612
628
  * @param {Number} [lightness=1]
@@ -618,12 +634,22 @@ declare class Color {
618
634
  * @param {Number} [alphaAmount=0]
619
635
  * @return {Color} */
620
636
  mutate(amount?: number, alphaAmount?: number): Color;
621
- /** Returns this color expressed as an rgba string
637
+ /** Returns this color expressed as an CSS color value
622
638
  * @return {String} */
623
- rgba(): string;
624
- /** Returns this color expressed as 32 bit integer value
639
+ toString(): string;
640
+ /** Returns this color expressed as 32 bit integer RGBA value
625
641
  * @return {Number} */
626
642
  rgbaInt(): number;
643
+ /** Returns this color expressed as a hex code
644
+ * @return {String} */
645
+ hex(): string;
646
+ /** Returns this color expressed in hsla format
647
+ * @return {Array} */
648
+ getHSLA(): any[];
649
+ /** Set this color from a hex code
650
+ * @param {String} hex - html hex code
651
+ * @return {Color} */
652
+ setHex(hex: string): Color;
627
653
  }
628
654
  /**
629
655
  * Timer object tracks how long has passed since it was set
@@ -660,6 +686,9 @@ declare class Timer {
660
686
  /** Get percentage elapsed based on time it was set to, returns 0 if not set
661
687
  * @return {Number} */
662
688
  getPercent(): number;
689
+ /** Returns this timer expressed as a string
690
+ * @return {String} */
691
+ toString(): string;
663
692
  }
664
693
  /** The max size of the canvas, centered if window is larger
665
694
  * @type {Vector2}
@@ -693,6 +722,10 @@ declare let tileFixBleedScale: number;
693
722
  * @default
694
723
  * @memberof Settings */
695
724
  declare let objectDefaultSize: Vector2;
725
+ /** Enable physics solver for collisions between objects
726
+ * @default
727
+ * @memberof Settings */
728
+ declare let enablePhysicsSolver: number;
696
729
  /** Default object mass for collison calcuations (how heavy objects are)
697
730
  * @default
698
731
  * @memberof Settings */
@@ -841,9 +874,9 @@ declare class EngineObject {
841
874
  /** Create an engine object and adds it to the list of objects
842
875
  * @param {Vector2} [position=new Vector2()] - World space position of the object
843
876
  * @param {Vector2} [size=objectDefaultSize] - World space size of the object
844
- * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
877
+ * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
845
878
  * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
846
- * @param {Number} [angle=0] - Angle to rotate the object
879
+ * @param {Number} [angle=0] - Angle the object is rotated by
847
880
  * @param {Color} [color] - Color to apply to tile when rendered
848
881
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
849
882
  */
@@ -852,7 +885,7 @@ declare class EngineObject {
852
885
  pos: Vector2;
853
886
  /** @property {Vector2} - World space width and height of the object */
854
887
  size: Vector2;
855
- /** @property {Number} - Tile to use to render object, untextured if -1 */
888
+ /** @property {Number} - Tile to use to render object (-1 is untextured) */
856
889
  tileIndex: number;
857
890
  /** @property {Vector2} - Size of tile in source pixels */
858
891
  tileSize: Vector2;
@@ -860,7 +893,7 @@ declare class EngineObject {
860
893
  angle: number;
861
894
  /** @property {Color} - Color to apply when rendered */
862
895
  color: Color;
863
- /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
896
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is, static if 0 */
864
897
  mass: number;
865
898
  /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
866
899
  damping: number;
@@ -931,6 +964,7 @@ declare class EngineObject {
931
964
  setCollision(collideSolidObjects?: boolean, isSolid?: boolean, collideTiles?: boolean): void;
932
965
  collideSolidObjects: boolean;
933
966
  isSolid: boolean;
967
+ toString(): string;
934
968
  }
935
969
  /** Tile sheet for batch rendering system
936
970
  * @type {Image}
@@ -1065,6 +1099,9 @@ declare let mouseWheel: number;
1065
1099
  /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1066
1100
  * @memberof Input */
1067
1101
  declare let isUsingGamepad: number;
1102
+ /** Prevents input continuing to the default browser handling (false by default)
1103
+ * @memberof Input */
1104
+ declare let preventDefaultInput: number;
1068
1105
  /** Returns true if gamepad button is down
1069
1106
  * @param {Number} button
1070
1107
  * @param {Number} [gamepad=0]
@@ -1272,12 +1309,12 @@ declare class TileLayerData {
1272
1309
  */
1273
1310
  declare class TileLayer extends EngineObject {
1274
1311
  /** Create a tile layer object
1275
- * @param {Vector2} [position=new Vector2()] - World space position
1276
- * @param {Vector2} [size=objectDefaultSize] - World space size
1277
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
1278
- * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
1279
- * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1280
- */
1312
+ * @param {Vector2} [position=new Vector2()] - World space position
1313
+ * @param {Vector2} [size=tileCollisionSize] - World space size
1314
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
1315
+ * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
1316
+ * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1317
+ */
1281
1318
  constructor(pos: any, size?: Vector2, tileSize?: Vector2, scale?: Vector2, renderOrder?: number);
1282
1319
  /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1283
1320
  canvas: HTMLCanvasElement;
@@ -1353,7 +1390,7 @@ declare class TileLayer extends EngineObject {
1353
1390
  declare class ParticleEmitter extends EngineObject {
1354
1391
  /** Create a particle system with the given settings
1355
1392
  * @param {Vector2} position - World space position of the emitter
1356
- * @param {Number} [angle=0] - Angle to rotate the object
1393
+ * @param {Number} [angle=0] - Angle to emit the particles
1357
1394
  * @param {Number} [emitSize=0] - World space size of the emitter (float for circle diameter, vec2 for rect)
1358
1395
  * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
1359
1396
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
@@ -1401,7 +1438,7 @@ declare class ParticleEmitter extends EngineObject {
1401
1438
  randomColorLinear: boolean;
1402
1439
  /** @property {Number} - How long particles live */
1403
1440
  particleTime: number;
1404
- /** @property {Number} - How big are particles at start */
1441
+ /** @property {Number} - How big are particles at start */
1405
1442
  sizeStart: number;
1406
1443
  /** @property {Number} - How big are particles at end */
1407
1444
  sizeEnd: number;
@@ -1415,6 +1452,8 @@ declare class ParticleEmitter extends EngineObject {
1415
1452
  fadeRate: number;
1416
1453
  /** @property {Number} - Apply extra randomness percent */
1417
1454
  randomness: number;
1455
+ /** @property {Number} - Do particles collide against tiles */
1456
+ collideTiles: boolean;
1418
1457
  /** @property {Number} - Should particles use addtive blend */
1419
1458
  additive: boolean;
1420
1459
  /** @property {Number} - If set the partile is drawn as a trail, stretched in the drection of velocity */
@@ -1588,7 +1627,7 @@ declare const gl_VERTEX_BYTE_STRIDE: number;
1588
1627
  /** Name of engine */
1589
1628
  declare const engineName: "LittleJS";
1590
1629
  /** Version of engine */
1591
- declare const engineVersion: "1.2.3";
1630
+ declare const engineVersion: "1.3.3";
1592
1631
  /** Frames per second to update objects
1593
1632
  * @default */
1594
1633
  declare const frameRate: 60;
@@ -5,6 +5,6 @@
5
5
  <link rel=icon type=image/png href=../../favicon.png>
6
6
  </head><body>
7
7
 
8
- <script src=../../engine/engine.all.js?102></script>
9
- <script src=game.js?102></script>
10
- <script src=gameObjects.js?102></script>
8
+ <script src=../../engine/engine.all.js?108></script>
9
+ <script src=game.js?108></script>
10
+ <script src=gameObjects.js?108></script>