littlejsengine 1.13.1 → 1.14.2

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 (83) hide show
  1. package/README.md +15 -11
  2. package/copyToGithub.bat +28 -0
  3. package/dist/littlejs.d.ts +430 -304
  4. package/dist/littlejs.esm.js +1745 -982
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +1716 -965
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +1673 -922
  9. package/examples/box2d/game.js +2 -2
  10. package/examples/box2d/gameObjects.js +2 -2
  11. package/examples/box2d/scenes.js +1 -1
  12. package/examples/breakout/game.js +30 -25
  13. package/examples/breakoutTutorial/README.md +44 -41
  14. package/examples/breakoutTutorial/game.js +2 -2
  15. package/examples/electron/build.bat +7 -0
  16. package/examples/electron/build.js +124 -0
  17. package/examples/electron/electron.js +35 -0
  18. package/examples/electron/game.js +140 -0
  19. package/examples/electron/index.html +13 -0
  20. package/examples/electron/package.json +12 -0
  21. package/examples/electron/tiles.png +0 -0
  22. package/examples/empty/game.js +1 -0
  23. package/examples/htmlMenu/game.js +1 -1
  24. package/examples/index.html +332 -160
  25. package/examples/module/game.js +5 -2
  26. package/examples/particles/index.html +12 -3
  27. package/examples/platformer/gameEffects.js +20 -19
  28. package/examples/platformer/gameLevel.js +6 -1
  29. package/examples/shorts/base.html +1 -1
  30. package/examples/shorts/blending.js +9 -5
  31. package/examples/shorts/box2d.js +1 -1
  32. package/examples/shorts/box2dCar.js +1 -1
  33. package/examples/shorts/clock.js +1 -1
  34. package/examples/shorts/colors.js +2 -2
  35. package/examples/shorts/flappyGame.js +2 -1
  36. package/examples/shorts/helloWorld.js +1 -1
  37. package/examples/shorts/maze.js +1 -1
  38. package/examples/shorts/music.js +106 -0
  39. package/examples/shorts/nineSlice.js +9 -9
  40. package/examples/shorts/parallax.js +71 -0
  41. package/examples/shorts/piano.js +9 -10
  42. package/examples/shorts/postProcess.js +25 -8
  43. package/examples/shorts/raycasting.js +2 -2
  44. package/examples/shorts/shapes.js +7 -15
  45. package/examples/shorts/slidingPuzzle.js +2 -2
  46. package/examples/shorts/song.mp3 +0 -0
  47. package/examples/shorts/starfield.js +5 -7
  48. package/examples/shorts/systemFont.js +1 -1
  49. package/examples/shorts/uiSystem.js +16 -8
  50. package/examples/starter/build.js +9 -8
  51. package/examples/starter/game.js +5 -2
  52. package/examples/starter/index.html +2 -2
  53. package/examples/stress/index.html +13 -8
  54. package/examples/style.css +19 -6
  55. package/examples/typescript/build.js +1 -1
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +5 -2
  58. package/examples/uiSystem/game.js +13 -12
  59. package/package.json +2 -2
  60. package/plugins/box2d.js +24 -97
  61. package/plugins/drawUtilities.js +29 -23
  62. package/plugins/newgrounds.js +6 -6
  63. package/plugins/pluginExport.js +1 -1
  64. package/plugins/postProcess.js +7 -0
  65. package/plugins/uiSystem.js +106 -82
  66. package/plugins/zzfxm.js +10 -10
  67. package/reference.md +90 -54
  68. package/src/engine.js +28 -23
  69. package/src/engineAudio.js +285 -110
  70. package/src/engineBuild.js +9 -9
  71. package/src/engineDebug.js +28 -28
  72. package/src/engineDraw.js +346 -202
  73. package/src/engineExport.js +28 -16
  74. package/src/engineInput.js +58 -68
  75. package/src/engineMedals.js +29 -29
  76. package/src/engineObject.js +28 -25
  77. package/src/engineParticles.js +67 -60
  78. package/src/engineRelease.js +1 -1
  79. package/src/engineSettings.js +70 -16
  80. package/src/engineTileLayer.js +34 -34
  81. package/src/engineUtilities.js +69 -62
  82. package/src/engineWebGL.js +467 -65
  83. /package/examples/shorts/{playSound.js → sound.js} +0 -0
@@ -1,10 +1,10 @@
1
- /**
1
+ /**
2
2
  * LittleJS Object System
3
3
  */
4
4
 
5
5
  'use strict';
6
6
 
7
- /**
7
+ /**
8
8
  * LittleJS Object Base Object Class
9
9
  * - Top level object class used by the engine
10
10
  * - Automatically adds self to object list
@@ -27,7 +27,7 @@
27
27
  * @example
28
28
  * // create an engine object, normally you would first extend the class with your own
29
29
  * const pos = vec2(2,3);
30
- * const object = new EngineObject(pos);
30
+ * const object = new EngineObject(pos);
31
31
  */
32
32
  class EngineObject
33
33
  {
@@ -45,9 +45,9 @@ class EngineObject
45
45
  ASSERT(isVector2(pos) && pos.isValid(), 'object pos should be a vec2');
46
46
  ASSERT(isVector2(size) && size.isValid(), 'object size should be a vec2');
47
47
  ASSERT(!tileInfo || tileInfo instanceof TileInfo, 'object tileInfo should be a TileInfo or undefined');
48
- ASSERT(typeof angle == 'number' && isFinite(angle), 'object angle should be a number');
48
+ ASSERT(typeof angle === 'number' && isFinite(angle), 'object angle should be a number');
49
49
  ASSERT(isColor(color) && color.isValid(), 'object color should be a valid rgba color');
50
- ASSERT(typeof renderOrder == 'number', 'object renderOrder should be a number');
50
+ ASSERT(typeof renderOrder === 'number', 'object renderOrder should be a number');
51
51
 
52
52
  /** @property {Vector2} - World space position of the object */
53
53
  this.pos = pos.copy();
@@ -115,7 +115,7 @@ class EngineObject
115
115
  // add to list of objects
116
116
  engineObjects.push(this);
117
117
  }
118
-
118
+
119
119
  /** Update the object transform, called automatically by engine even when paused */
120
120
  updateTransforms()
121
121
  {
@@ -184,7 +184,7 @@ class EngineObject
184
184
  for (const o of engineObjectsCollide)
185
185
  {
186
186
  // non solid objects don't collide with each other
187
- if (!this.isSolid && !o.isSolid || o.destroyed || o.parent || o == this)
187
+ if (!this.isSolid && !o.isSolid || o.destroyed || o.parent || o === this)
188
188
  continue;
189
189
 
190
190
  // check collision
@@ -207,8 +207,8 @@ class EngineObject
207
207
  this.velocity = this.velocity.add(velocity);
208
208
  if (o.mass) // push away if not fixed
209
209
  o.velocity = o.velocity.subtract(velocity);
210
-
211
- debugOverlay && debugPhysics && debugOverlap(this.pos, this.size, o.pos, o.size, '#f00');
210
+
211
+ debugPhysics && debugOverlap(this.pos, this.size, o.pos, o.size, '#f00');
212
212
  continue;
213
213
  }
214
214
 
@@ -218,7 +218,7 @@ class EngineObject
218
218
  const isBlockedX = abs(oldPos.y - o.pos.y)*2 < sizeBoth.y;
219
219
  const isBlockedY = abs(oldPos.x - o.pos.x)*2 < sizeBoth.x;
220
220
  const restitution = max(this.restitution, o.restitution);
221
-
221
+
222
222
  if (smallStepUp || isBlockedY || !isBlockedX) // resolve y collision
223
223
  {
224
224
  // push outside object collision
@@ -270,7 +270,7 @@ class EngineObject
270
270
  else // bounce if other object is fixed
271
271
  this.velocity.x *= -restitution;
272
272
  }
273
- debugOverlay && debugPhysics && debugOverlap(this.pos, this.size, o.pos, o.size, '#f0f');
273
+ debugPhysics && debugOverlap(this.pos, this.size, o.pos, o.size, '#f0f');
274
274
  }
275
275
  }
276
276
  if (this.collideTiles)
@@ -306,7 +306,7 @@ class EngineObject
306
306
  {
307
307
  // move to previous position
308
308
  this.pos.y = oldPos.y;
309
- this.groundObject = undefined;
309
+ this.groundObject = undefined;
310
310
  }
311
311
  }
312
312
  if (blockedLayerX)
@@ -315,25 +315,25 @@ class EngineObject
315
315
  this.pos.x = oldPos.x;
316
316
  this.velocity.x *= -this.restitution;
317
317
  }
318
- debugOverlay && debugPhysics && debugRect(this.pos, this.size, '#f00');
318
+ debugPhysics && debugRect(this.pos, this.size, '#f00');
319
319
  }
320
320
  }
321
321
  }
322
322
  }
323
-
323
+
324
324
  /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
325
325
  render()
326
326
  {
327
327
  // default object render
328
328
  drawTile(this.pos, this.drawSize || this.size, this.tileInfo, this.color, this.angle, this.mirror, this.additiveColor);
329
329
  }
330
-
330
+
331
331
  /** Destroy this object, destroy its children, detach it's parent, and mark it for removal */
332
332
  destroy()
333
- {
333
+ {
334
334
  if (this.destroyed)
335
335
  return;
336
-
336
+
337
337
  // disconnect from parent and destroy children
338
338
  this.destroyed = 1;
339
339
  this.parent && this.parent.removeChild(this);
@@ -359,7 +359,7 @@ class EngineObject
359
359
  /** Convert from world space to local space for a vector (rotation only)
360
360
  * @param {Vector2} vec - world space vector */
361
361
  worldToLocalVector(vec) { return vec.rotate(-this.angle); }
362
-
362
+
363
363
  /** Called to check if a tile collision should be resolved
364
364
  * @param {number} tileData - the value of the tile at the position
365
365
  * @param {Vector2} pos - tile where the collision occurred
@@ -378,16 +378,19 @@ class EngineObject
378
378
 
379
379
  /** Apply acceleration to this object (adjust velocity, not affected by mass)
380
380
  * @param {Vector2} acceleration */
381
- applyAcceleration(acceleration) { if (this.mass) this.velocity = this.velocity.add(acceleration); }
381
+ applyAcceleration(acceleration)
382
+ { if (this.mass) this.velocity = this.velocity.add(acceleration); }
382
383
 
383
- /** Apply angular acceleration to this object
384
+ /** Apply angular acceleration to this object
384
385
  * @param {number} acceleration */
385
- applyAngularAcceleration(acceleration) { if (this.mass) this.angleVelocity += acceleration; }
386
+ applyAngularAcceleration(acceleration)
387
+ { if (this.mass) this.angleVelocity += acceleration; }
386
388
 
387
389
  /** Apply force to this object (adjust velocity, affected by mass)
388
390
  * @param {Vector2} force */
389
- applyForce(force) { this.applyAcceleration(force.scale(1/this.mass)); }
390
-
391
+ applyForce(force)
392
+ { if (this.mass) this.applyAcceleration(force.scale(1/this.mass)); }
393
+
391
394
  /** Get the direction of the mirror
392
395
  * @return {number} -1 if this.mirror is true, or 1 if not mirrored */
393
396
  getMirrorSign() { return this.mirror ? -1 : 1; }
@@ -409,7 +412,7 @@ class EngineObject
409
412
  * @param {EngineObject} child */
410
413
  removeChild(child)
411
414
  {
412
- ASSERT(child.parent == this && this.children.includes(child));
415
+ ASSERT(child.parent === this && this.children.includes(child));
413
416
  this.children.splice(this.children.indexOf(child), 1);
414
417
  child.parent = 0;
415
418
  }
@@ -455,7 +458,7 @@ class EngineObject
455
458
  {
456
459
  if (!debug)
457
460
  return;
458
-
461
+
459
462
  // show object info for debugging
460
463
  const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
461
464
  const color = rgb(this.collideTiles?1:0, this.collideSolidObjects?1:0, this.isSolid?1:0, .5);
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * LittleJS Particle System
3
3
  */
4
4
 
@@ -17,7 +17,7 @@
17
17
  * rgb(1,1,1,1), rgb(0,0,0,1), // colorStartA, colorStartB
18
18
  * rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
19
19
  * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
20
- * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
20
+ * .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate,
21
21
  * .5, 1 // randomness, collide, additive, randomColorLinear, renderOrder
22
22
  * );
23
23
  */
@@ -25,35 +25,35 @@ class ParticleEmitter extends EngineObject
25
25
  {
26
26
  /** Create a particle system with the given settings
27
27
  * @param {Vector2} position - World space position of the emitter
28
- * @param {Number} [angle] - Angle to emit the particles
29
- * @param {Number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
30
- * @param {Number} [emitTime] - How long to stay alive (0 is forever)
31
- * @param {Number} [emitRate] - How many particles per second to spawn, does not emit if 0
32
- * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
28
+ * @param {number} [angle] - Angle to emit the particles
29
+ * @param {number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
30
+ * @param {number} [emitTime] - How long to stay alive (0 is forever)
31
+ * @param {number} [emitRate] - How many particles per second to spawn, does not emit if 0
32
+ * @param {number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
33
33
  * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
34
34
  * @param {Color} [colorStartA=(1,1,1,1)] - Color at start of life 1, randomized between start colors
35
35
  * @param {Color} [colorStartB=(1,1,1,1)] - Color at start of life 2, randomized between start colors
36
36
  * @param {Color} [colorEndA=(1,1,1,0)] - Color at end of life 1, randomized between end colors
37
37
  * @param {Color} [colorEndB=(1,1,1,0)] - Color at end of life 2, randomized between end colors
38
- * @param {Number} [particleTime] - How long particles live
39
- * @param {Number} [sizeStart] - How big are particles at start
40
- * @param {Number} [sizeEnd] - How big are particles at end
41
- * @param {Number} [speed] - How fast are particles when spawned
42
- * @param {Number} [angleSpeed] - How fast are particles rotating
43
- * @param {Number} [damping] - How much to dampen particle speed
44
- * @param {Number} [angleDamping] - How much to dampen particle angular speed
45
- * @param {Number} [gravityScale] - How much gravity effect particles
46
- * @param {Number} [particleConeAngle] - Cone for start particle angle
47
- * @param {Number} [fadeRate] - How quick to fade particles at start/end in percent of life
48
- * @param {Number} [randomness] - Apply extra randomness percent
38
+ * @param {number} [particleTime] - How long particles live
39
+ * @param {number} [sizeStart] - How big are particles at start
40
+ * @param {number} [sizeEnd] - How big are particles at end
41
+ * @param {number} [speed] - How fast are particles when spawned
42
+ * @param {number} [angleSpeed] - How fast are particles rotating
43
+ * @param {number} [damping] - How much to dampen particle speed
44
+ * @param {number} [angleDamping] - How much to dampen particle angular speed
45
+ * @param {number} [gravityScale] - How much gravity effect particles
46
+ * @param {number} [particleConeAngle] - Cone for start particle angle
47
+ * @param {number} [fadeRate] - How quick to fade particles at start/end in percent of life
48
+ * @param {number} [randomness] - Apply extra randomness percent
49
49
  * @param {boolean} [collideTiles] - Do particles collide against tiles
50
50
  * @param {boolean} [additive] - Should particles use additive blend
51
51
  * @param {boolean} [randomColorLinear] - Should color be randomized linearly or across each component
52
- * @param {Number} [renderOrder] - Render order for particles (additive is above other stuff by default)
52
+ * @param {number} [renderOrder] - Render order for particles (additive is above other stuff by default)
53
53
  * @param {boolean} [localSpace] - Should it be in local space of emitter (world space is default)
54
54
  */
55
55
  constructor
56
- (
56
+ (
57
57
  position,
58
58
  angle,
59
59
  emitSize = 0,
@@ -75,7 +75,7 @@ class ParticleEmitter extends EngineObject
75
75
  gravityScale = 0,
76
76
  particleConeAngle = PI,
77
77
  fadeRate = .1,
78
- randomness = .2,
78
+ randomness = .2,
79
79
  collideTiles = false,
80
80
  additive = false,
81
81
  randomColorLinear = true,
@@ -86,13 +86,13 @@ class ParticleEmitter extends EngineObject
86
86
  super(position, vec2(), tileInfo, angle, undefined, renderOrder);
87
87
 
88
88
  // emitter settings
89
- /** @property {Number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
89
+ /** @property {number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
90
90
  this.emitSize = emitSize
91
- /** @property {Number} - How long to stay alive (0 is forever) */
91
+ /** @property {number} - How long to stay alive (0 is forever) */
92
92
  this.emitTime = emitTime;
93
- /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
93
+ /** @property {number} - How many particles per second to spawn, does not emit if 0 */
94
94
  this.emitRate = emitRate;
95
- /** @property {Number} - Local angle to apply velocity to particles from emitter */
95
+ /** @property {number} - Local angle to apply velocity to particles from emitter */
96
96
  this.emitConeAngle = emitConeAngle;
97
97
 
98
98
  // color settings
@@ -108,27 +108,27 @@ class ParticleEmitter extends EngineObject
108
108
  this.randomColorLinear = randomColorLinear;
109
109
 
110
110
  // particle settings
111
- /** @property {Number} - How long particles live */
111
+ /** @property {number} - How long particles live */
112
112
  this.particleTime = particleTime;
113
- /** @property {Number} - How big are particles at start */
113
+ /** @property {number} - How big are particles at start */
114
114
  this.sizeStart = sizeStart;
115
- /** @property {Number} - How big are particles at end */
115
+ /** @property {number} - How big are particles at end */
116
116
  this.sizeEnd = sizeEnd;
117
- /** @property {Number} - How fast are particles when spawned */
117
+ /** @property {number} - How fast are particles when spawned */
118
118
  this.speed = speed;
119
- /** @property {Number} - How fast are particles rotating */
119
+ /** @property {number} - How fast are particles rotating */
120
120
  this.angleSpeed = angleSpeed;
121
- /** @property {Number} - How much to dampen particle speed */
121
+ /** @property {number} - How much to dampen particle speed */
122
122
  this.damping = damping;
123
- /** @property {Number} - How much to dampen particle angular speed */
123
+ /** @property {number} - How much to dampen particle angular speed */
124
124
  this.angleDamping = angleDamping;
125
- /** @property {Number} - How much does gravity effect particles */
125
+ /** @property {number} - How much gravity affects particles */
126
126
  this.gravityScale = gravityScale;
127
- /** @property {Number} - Cone for start particle angle */
127
+ /** @property {number} - Cone for start particle angle */
128
128
  this.particleConeAngle = particleConeAngle;
129
- /** @property {Number} - How quick to fade in particles at start/end in percent of life */
129
+ /** @property {number} - How quick to fade in particles at start/end in percent of life */
130
130
  this.fadeRate = fadeRate;
131
- /** @property {Number} - Apply extra randomness percent */
131
+ /** @property {number} - Apply extra randomness percent */
132
132
  this.randomness = randomness;
133
133
  /** @property {boolean} - Do particles collide against tiles */
134
134
  this.collideTiles = collideTiles;
@@ -136,16 +136,16 @@ class ParticleEmitter extends EngineObject
136
136
  this.additive = additive;
137
137
  /** @property {boolean} - Should it be in local space of emitter */
138
138
  this.localSpace = localSpace;
139
- /** @property {Number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
139
+ /** @property {number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
140
140
  this.trailScale = 0;
141
141
  /** @property {Function} - Callback when particle is destroyed */
142
142
  this.particleDestroyCallback = undefined;
143
143
  /** @property {Function} - Callback when particle is created */
144
144
  this.particleCreateCallback = undefined;
145
- /** @property {Number} - Track particle emit time */
145
+ /** @property {number} - Track particle emit time */
146
146
  this.emitTimeBuffer = 0;
147
147
  }
148
-
148
+
149
149
  /** Update the emitter to spawn particles, called automatically by engine once each frame */
150
150
  update()
151
151
  {
@@ -169,7 +169,7 @@ class ParticleEmitter extends EngineObject
169
169
  if (debugParticles)
170
170
  {
171
171
  // show emitter bounds
172
- const emitSize = typeof this.emitSize == 'number' ? vec2(this.emitSize) : this.emitSize;
172
+ const emitSize = typeof this.emitSize === 'number' ? vec2(this.emitSize) : this.emitSize;
173
173
  debugRect(this.pos, emitSize, '#0f0', 0, this.angle);
174
174
  }
175
175
  }
@@ -179,7 +179,7 @@ class ParticleEmitter extends EngineObject
179
179
  emitParticle()
180
180
  {
181
181
  // spawn a particle
182
- let pos = typeof this.emitSize == 'number' ? // check if number was used
182
+ let pos = typeof this.emitSize === 'number' ? // check if number was used
183
183
  randInCircle(this.emitSize/2) // circle emitter
184
184
  : vec2(rand(-.5,.5), rand(-.5,.5)) // box emitter
185
185
  .multiply(this.emitSize).rotate(this.angle)
@@ -204,15 +204,22 @@ class ParticleEmitter extends EngineObject
204
204
  const colorStart = randColor(this.colorStartA, this.colorStartB, this.randomColorLinear);
205
205
  const colorEnd = randColor(this.colorEndA, this.colorEndB, this.randomColorLinear);
206
206
  const velocityAngle = this.localSpace ? coneAngle : this.angle + coneAngle;
207
-
207
+
208
208
  // build particle
209
209
  const particle = new Particle(pos, this.tileInfo, angle, colorStart, colorEnd, particleTime, sizeStart, sizeEnd, this.fadeRate, this.additive, this.trailScale, this.localSpace && this, this.particleDestroyCallback);
210
210
  particle.velocity = vec2().setAngle(velocityAngle, speed);
211
211
  particle.angleVelocity = angleSpeed;
212
+ if (!this.localSpace)
213
+ {
214
+ // apply emitter velocity to particle
215
+ particle.velocity.x += this.velocity.x;
216
+ particle.velocity.y += this.velocity.y;
217
+ particle.angleVelocity += this.angleVelocity;
218
+ }
212
219
  particle.fadeRate = this.fadeRate;
213
220
  particle.damping = this.damping;
214
221
  particle.angleDamping = this.angleDamping;
215
- particle.restitution = this.restitution;
222
+ particle.restitution = this.restitution;
216
223
  particle.friction = this.friction;
217
224
  particle.gravityScale = this.gravityScale;
218
225
  particle.collideTiles = this.collideTiles;
@@ -242,38 +249,38 @@ class Particle extends EngineObject
242
249
  * Typically this is created automatically by a ParticleEmitter
243
250
  * @param {Vector2} position - World space position of the particle
244
251
  * @param {TileInfo} tileInfo - Tile info to render particles
245
- * @param {Number} angle - Angle to rotate the particle
252
+ * @param {number} angle - Angle to rotate the particle
246
253
  * @param {Color} colorStart - Color at start of life
247
254
  * @param {Color} colorEnd - Color at end of life
248
- * @param {Number} lifeTime - How long to live for
249
- * @param {Number} sizeStart - Size at start of life
250
- * @param {Number} sizeEnd - Size at end of life
251
- * @param {Number} fadeRate - How quick to fade in/out
255
+ * @param {number} lifeTime - How long to live for
256
+ * @param {number} sizeStart - Size at start of life
257
+ * @param {number} sizeEnd - Size at end of life
258
+ * @param {number} fadeRate - How quick to fade in/out
252
259
  * @param {boolean} additive - Does it use additive blend mode
253
- * @param {Number} trailScale - If a trail, how long to make it
260
+ * @param {number} trailScale - If a trail, how long to make it
254
261
  * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
255
262
  * @param {Function} [destroyCallback] - Callback when particle dies
256
263
  */
257
264
  constructor(position, tileInfo, angle, colorStart, colorEnd, lifeTime, sizeStart, sizeEnd, fadeRate, additive, trailScale, localSpaceEmitter, destroyCallback
258
265
  )
259
- {
260
- super(position, vec2(), tileInfo, angle);
261
-
266
+ {
267
+ super(position, vec2(), tileInfo, angle);
268
+
262
269
  /** @property {Color} - Color at start of life */
263
270
  this.colorStart = colorStart;
264
271
  /** @property {Color} - Calculated change in color */
265
272
  this.colorEndDelta = colorEnd.subtract(colorStart);
266
- /** @property {Number} - How long to live for */
273
+ /** @property {number} - How long to live for */
267
274
  this.lifeTime = lifeTime;
268
- /** @property {Number} - Size at start of life */
275
+ /** @property {number} - Size at start of life */
269
276
  this.sizeStart = sizeStart;
270
- /** @property {Number} - Calculated change in size */
277
+ /** @property {number} - Calculated change in size */
271
278
  this.sizeEndDelta = sizeEnd - sizeStart;
272
- /** @property {Number} - How quick to fade in/out */
279
+ /** @property {number} - How quick to fade in/out */
273
280
  this.fadeRate = fadeRate;
274
281
  /** @property {boolean} - Is it additive */
275
282
  this.additive = additive;
276
- /** @property {Number} - If a trail, how long to make it */
283
+ /** @property {number} - If a trail, how long to make it */
277
284
  this.trailScale = trailScale;
278
285
  /** @property {ParticleEmitter} - Parent emitter if local space */
279
286
  this.localSpaceEmitter = localSpaceEmitter;
@@ -313,7 +320,7 @@ class Particle extends EngineObject
313
320
  this.colorStart.r + p * this.colorEndDelta.r,
314
321
  this.colorStart.g + p * this.colorEndDelta.g,
315
322
  this.colorStart.b + p * this.colorEndDelta.b,
316
- (this.colorStart.a + p * this.colorEndDelta.a) *
323
+ (this.colorStart.a + p * this.colorEndDelta.a) *
317
324
  (p < fadeRate ? p/fadeRate : p > 1-fadeRate ? (1-p)/fadeRate : 1)); // fade alpha
318
325
 
319
326
  // draw the particle
@@ -323,7 +330,7 @@ class Particle extends EngineObject
323
330
  if (this.localSpaceEmitter)
324
331
  {
325
332
  // in local space of emitter
326
- pos = this.localSpaceEmitter.pos.add(pos.rotate(-this.localSpaceEmitter.angle));
333
+ pos = this.localSpaceEmitter.pos.add(pos.rotate(-this.localSpaceEmitter.angle));
327
334
  angle += this.localSpaceEmitter.angle;
328
335
  }
329
336
  if (this.trailScale)
@@ -347,7 +354,7 @@ class Particle extends EngineObject
347
354
  this.additive && setBlendMode();
348
355
  debugParticles && debugRect(pos, size, '#f005', 0, angle);
349
356
 
350
- if (p == 1)
357
+ if (p === 1)
351
358
  {
352
359
  // destroy particle when it's time runs out
353
360
  this.color = color;
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * LittleJS - Release Mode
3
3
  * - This file is used for release builds in place of engineDebug.js
4
4
  * - Debug functionality is disabled to reduce size and increase performance
@@ -30,6 +30,13 @@ let cameraScale = 32;
30
30
  ///////////////////////////////////////////////////////////////////////////////
31
31
  // Display settings
32
32
 
33
+ /** Enable applying color to tiles when using canvas2d
34
+ * - This is slower but should be the same as WebGL rendering
35
+ * @type {boolean}
36
+ * @default
37
+ * @memberof Settings */
38
+ let canvasColorTiles = true;
39
+
33
40
  /** The max size of the canvas, centered if window is larger
34
41
  * @type {Vector2}
35
42
  * @default Vector2(1920,1080)
@@ -43,14 +50,21 @@ let canvasMaxSize = vec2(1920, 1080);
43
50
  * @memberof Settings */
44
51
  let canvasFixedSize = vec2();
45
52
 
46
- /** Use nearest neighbor canvas scaling for more pixelated look
47
- * - Must be set before startup to take effect
53
+ /** Use nearest canvas scaling for more pixelated look
48
54
  * - If enabled sets css image-rendering:pixelated
49
55
  * @type {boolean}
50
56
  * @default
51
57
  * @memberof Settings */
52
58
  let canvasPixelated = true;
53
59
 
60
+ /** Use nearest canvas scaling for more pixelated look
61
+ * - If enabled sets css image-rendering:pixelated
62
+ * - This defaults to false because text looks better with smoothing
63
+ * @type {boolean}
64
+ * @default
65
+ * @memberof Settings */
66
+ let overlayCanvasPixelated = false;
67
+
54
68
  /** Disables texture filtering for crisper pixel art
55
69
  * @type {boolean}
56
70
  * @default
@@ -63,14 +77,13 @@ let tilesPixelated = true;
63
77
  * @memberof Settings */
64
78
  let fontDefault = 'arial';
65
79
 
66
- /** Enable to show the LittleJS splash screen be shown on startup
80
+ /** Enable to show the LittleJS splash screen on startup
67
81
  * @type {boolean}
68
82
  * @default
69
83
  * @memberof Settings */
70
84
  let showSplashScreen = false;
71
85
 
72
86
  /** Disables all rendering, audio, and input for servers
73
- * - Must be set before startup to take effect
74
87
  * @type {boolean}
75
88
  * @default
76
89
  * @memberof Settings */
@@ -79,13 +92,18 @@ let headlessMode = false;
79
92
  ///////////////////////////////////////////////////////////////////////////////
80
93
  // WebGL settings
81
94
 
82
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
83
- * - Must be set before startup to take effect
95
+ /** Enable WebGL accelerated rendering
84
96
  * @type {boolean}
85
97
  * @default
86
98
  * @memberof Settings */
87
99
  let glEnable = true;
88
100
 
101
+ /** How many sided poly to use when drawing circles and ellipses with WebGL
102
+ * @type {number}
103
+ * @default
104
+ * @memberof Settings */
105
+ let glCircleSides = 32;
106
+
89
107
  ///////////////////////////////////////////////////////////////////////////////
90
108
  // Tile sheet settings
91
109
 
@@ -167,13 +185,13 @@ let particleEmitRateScale = 1;
167
185
  * @memberof Settings */
168
186
  let gamepadsEnable = true;
169
187
 
170
- /** If true, the dpad input is also routed to the left analog stick (for better accessability)
188
+ /** If true, the dpad input is also routed to the left analog stick (for better accessibility)
171
189
  * @type {boolean}
172
190
  * @default
173
191
  * @memberof Settings */
174
192
  let gamepadDirectionEmulateStick = true;
175
193
 
176
- /** If true the WASD keys are also routed to the direction keys (for better accessability)
194
+ /** If true the WASD keys are also routed to the direction keys (for better accessibility)
177
195
  * @type {boolean}
178
196
  * @default
179
197
  * @memberof Settings */
@@ -181,7 +199,6 @@ let inputWASDEmulateDirection = true;
181
199
 
182
200
  /** True if touch input is enabled for mobile devices
183
201
  * - Touch events will be routed to mouse events
184
- * - Must be set before startup to take effect
185
202
  * @type {boolean}
186
203
  * @default
187
204
  * @memberof Settings */
@@ -189,7 +206,6 @@ let touchInputEnable = true;
189
206
 
190
207
  /** True if touch gamepad should appear on mobile devices
191
208
  * - Supports left analog stick, 4 face buttons and start button (button 9)
192
- * - Must be set before startup to take effect
193
209
  * @type {boolean}
194
210
  * @default
195
211
  * @memberof Settings */
@@ -291,6 +307,14 @@ function setCameraAngle(angle) { cameraAngle = angle; }
291
307
  * @memberof Settings */
292
308
  function setCameraScale(scale) { cameraScale = scale; }
293
309
 
310
+ /** Set if tiles should be colorized when using canvas2d
311
+ * This can be slower but results should look nearly identical to WebGL rendering
312
+ * It can be enabled/disabled at any time
313
+ * Optimized for performance, and will use faster method if color is white or untextured
314
+ * @param {boolean} colorTiles
315
+ * @memberof Settings */
316
+ function setCanvasColorTiles(colorTiles) { canvasColorTiles = colorTiles; }
317
+
294
318
  /** Set max size of the canvas
295
319
  * @param {Vector2} size
296
320
  * @memberof Settings */
@@ -301,10 +325,30 @@ function setCanvasMaxSize(size) { canvasMaxSize = size; }
301
325
  * @memberof Settings */
302
326
  function setCanvasFixedSize(size) { canvasFixedSize = size; }
303
327
 
304
- /** Use nearest neighbor scaling algorithm for canvas for more pixelated look
328
+ /** Use nearest scaling algorithm for canvas for more pixelated look
329
+ * - If enabled sets css image-rendering:pixelated
330
+ * @param {boolean} pixelated
331
+ * @memberof Settings */
332
+ function setCanvasPixelated(pixelated)
333
+ {
334
+ canvasPixelated = pixelated;
335
+ if (mainCanvas)
336
+ mainCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
337
+ if (glCanvas)
338
+ glCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
339
+ }
340
+
341
+ /** Use nearest scaling algorithm for canvas for more pixelated look
342
+ * - If enabled sets css image-rendering:pixelated
343
+ * - This defaults to false because text looks better with smoothing
305
344
  * @param {boolean} pixelated
306
345
  * @memberof Settings */
307
- function setCanvasPixelated(pixelated) { canvasPixelated = pixelated; }
346
+ function setOverlayCanvasPixelated(pixelated)
347
+ {
348
+ overlayCanvasPixelated = pixelated;
349
+ if (overlayCanvas)
350
+ overlayCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
351
+ }
308
352
 
309
353
  /** Disables texture filtering for crisper pixel art
310
354
  * @param {boolean} pixelated
@@ -316,7 +360,7 @@ function setTilesPixelated(pixelated) { tilesPixelated = pixelated; }
316
360
  * @memberof Settings */
317
361
  function setFontDefault(font) { fontDefault = font; }
318
362
 
319
- /** Set if the LittleJS splash screen be shown on startup
363
+ /** Set if the LittleJS splash screen should be shown on startup
320
364
  * @param {boolean} show
321
365
  * @memberof Settings */
322
366
  function setShowSplashScreen(show) { showSplashScreen = show; }
@@ -326,10 +370,20 @@ function setShowSplashScreen(show) { showSplashScreen = show; }
326
370
  * @memberof Settings */
327
371
  function setHeadlessMode(headless) { headlessMode = headless; }
328
372
 
329
- /** Set if webgl rendering is enabled
373
+ /** Set if WebGL rendering is enabled
330
374
  * @param {boolean} enable
331
375
  * @memberof Settings */
332
- function setGLEnable(enable) { glEnable = enable; }
376
+ function setGLEnable(enable)
377
+ {
378
+ glEnable = enable;
379
+ if (glCanvas) // hide glCanvas if WebGL is disabled
380
+ glCanvas.style.visibility = enable ? 'visible' : 'hidden';
381
+ }
382
+
383
+ /** Set how many sided polygons to use when drawing circles and elipses with WebGL
384
+ * @param {number} sides
385
+ * @memberof Settings */
386
+ function setGLCircleSides(sides) { glCircleSides = sides; }
333
387
 
334
388
  /** Set default size of tiles in pixels
335
389
  * @param {Vector2} size
@@ -361,7 +415,7 @@ function setObjectDefaultDamping(damp) { objectDefaultDamping = damp; }
361
415
  * @memberof Settings */
362
416
  function setObjectDefaultAngleDamping(damp) { objectDefaultAngleDamping = damp; }
363
417
 
364
- /** Set how much to bounce when a collision occur
418
+ /** Set how much to bounce when a collision occurs
365
419
  * @param {number} restitution
366
420
  * @memberof Settings */
367
421
  function setObjectDefaultRestitution(restitution) { objectDefaultRestitution = restitution; }