littlejsengine 1.8.9 → 1.9.0

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 (45) hide show
  1. package/README.md +17 -17
  2. package/build/littlejs.d.ts +312 -250
  3. package/build/littlejs.esm.js +633 -599
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +632 -599
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +567 -535
  8. package/examples/breakout/game.js +4 -4
  9. package/examples/breakout/index.html +3 -3
  10. package/examples/breakoutTutorial/index.html +2 -2
  11. package/examples/electron/game.js +1 -1
  12. package/examples/electron/index.html +2 -2
  13. package/examples/favicon.png +0 -0
  14. package/examples/js13k/index.html +13 -13
  15. package/examples/module/game.js +1 -1
  16. package/examples/module/index.html +1 -1
  17. package/examples/particles/index.html +1 -1
  18. package/examples/platformer/game.js +6 -6
  19. package/examples/platformer/gameCharacter.js +293 -0
  20. package/examples/platformer/gameEffects.js +8 -5
  21. package/examples/platformer/gameObjects.js +13 -13
  22. package/examples/platformer/gamePlayer.js +9 -293
  23. package/examples/platformer/index.html +7 -6
  24. package/examples/puzzle/game.js +3 -2
  25. package/examples/puzzle/index.html +2 -2
  26. package/examples/starter/game.js +2 -2
  27. package/examples/starter/index.html +13 -13
  28. package/examples/stress/index.html +34 -26
  29. package/examples/typescript/index.html +1 -1
  30. package/package.json +1 -1
  31. package/src/engine.js +28 -28
  32. package/src/engineAudio.js +57 -57
  33. package/src/engineDebug.js +66 -65
  34. package/src/engineDraw.js +47 -56
  35. package/src/engineExport.js +1 -0
  36. package/src/engineInput.js +57 -40
  37. package/src/engineMedals.js +32 -29
  38. package/src/engineObject.js +41 -26
  39. package/src/engineParticles.js +98 -72
  40. package/src/engineRelease.js +1 -1
  41. package/src/engineSettings.js +22 -22
  42. package/src/engineTileLayer.js +34 -33
  43. package/src/engineUtilities.js +44 -44
  44. package/src/engineWebGL.js +105 -126
  45. package/src/jsconfig.json +10 -0
@@ -14,13 +14,13 @@
14
14
  * @type {Boolean}
15
15
  * @default
16
16
  * @memberof Debug */
17
- const debug = 1;
17
+ const debug = true;
18
18
 
19
19
  /** True if asserts are enaled
20
20
  * @type {Boolean}
21
21
  * @default
22
22
  * @memberof Debug */
23
- const enableAsserts = 1;
23
+ const enableAsserts = true;
24
24
 
25
25
  /** Size to render debug points by default
26
26
  * @type {Number}
@@ -32,82 +32,87 @@ const debugPointSize = .5;
32
32
  * @type {Boolean}
33
33
  * @default
34
34
  * @memberof Debug */
35
- let showWatermark = 1;
35
+ let showWatermark = true;
36
36
 
37
37
  /** Key code used to toggle debug mode, Esc by default
38
+ * @type {String}
39
+ * @default
40
+ * @memberof Debug */
41
+ let debugKey = 'Escape';
42
+
43
+ /** True if the debug overlay is active, always false in release builds
38
44
  * @type {Boolean}
39
45
  * @default
40
46
  * @memberof Debug */
41
- let debugKey = 27;
47
+ let debugOverlay = false;
42
48
 
43
49
  // Engine internal variables not exposed to documentation
44
- let debugPrimitives = [], debugOverlay = 0, debugPhysics = 0, debugRaycast = 0,
45
- debugParticles = 0, debugGamepads = 0, debugMedals = 0, debugTakeScreenshot, downloadLink;
50
+ let debugPrimitives = [], debugPhysics = false, debugRaycast = false, debugParticles = false, debugGamepads = false, debugMedals = false, debugTakeScreenshot, downloadLink;
46
51
 
47
52
  ///////////////////////////////////////////////////////////////////////////////
48
53
  // Debug helper functions
49
54
 
50
55
  /** Asserts if the experssion is false, does not do anything in release builds
51
- * @param {Boolean} assertion
52
- * @param {Object} output
56
+ * @param {Boolean} assert
57
+ * @param {Object} output
53
58
  * @memberof Debug */
54
- function ASSERT(...assert) { enableAsserts && console.assert(...assert); }
59
+ function ASSERT(assert, output) { enableAsserts && console.assert(assert, output); }
55
60
 
56
61
  /** Draw a debug rectangle in world space
57
62
  * @param {Vector2} pos
58
63
  * @param {Vector2} [size=Vector2()]
59
- * @param {String} [color='#fff']
60
- * @param {Number} [time=0]
61
- * @param {Number} [angle=0]
62
- * @param {Boolean} [fill=false]
64
+ * @param {String} [color]
65
+ * @param {Number} [time]
66
+ * @param {Number} [angle]
67
+ * @param {Boolean} [fill]
63
68
  * @memberof Debug */
64
69
  function debugRect(pos, size=vec2(), color='#fff', time=0, angle=0, fill=false)
65
70
  {
66
- ASSERT(typeof color == 'string'); // pass in regular html strings as colors
71
+ ASSERT(typeof color == 'string', 'pass in css color strings');
67
72
  debugPrimitives.push({pos, size:vec2(size), color, time:new Timer(time), angle, fill});
68
73
  }
69
74
 
70
75
  /** Draw a debug circle in world space
71
76
  * @param {Vector2} pos
72
- * @param {Number} [radius=0]
73
- * @param {String} [color='#fff']
74
- * @param {Number} [time=0]
75
- * @param {Boolean} [fill=false]
77
+ * @param {Number} [radius]
78
+ * @param {String} [color]
79
+ * @param {Number} [time]
80
+ * @param {Boolean} [fill]
76
81
  * @memberof Debug */
77
82
  function debugCircle(pos, radius=0, color='#fff', time=0, fill=false)
78
83
  {
79
- ASSERT(typeof color == 'string'); // pass in regular html strings as colors
84
+ ASSERT(typeof color == 'string', 'pass in css color strings');
80
85
  debugPrimitives.push({pos, size:radius, color, time:new Timer(time), angle:0, fill});
81
86
  }
82
87
 
83
88
  /** Draw a debug point in world space
84
89
  * @param {Vector2} pos
85
- * @param {String} [color='#fff']
86
- * @param {Number} [time=0]
87
- * @param {Number} [angle=0]
90
+ * @param {String} [color]
91
+ * @param {Number} [time]
92
+ * @param {Number} [angle]
88
93
  * @memberof Debug */
89
- function debugPoint(pos, color, time, angle) {debugRect(pos, 0, color, time, angle);}
94
+ function debugPoint(pos, color, time, angle) {debugRect(pos, undefined, color, time, angle);}
90
95
 
91
96
  /** Draw a debug line in world space
92
97
  * @param {Vector2} posA
93
98
  * @param {Vector2} posB
94
- * @param {String} [color='#fff']
95
- * @param {Number} [thickness=.1]
96
- * @param {Number} [time=0]
99
+ * @param {String} [color]
100
+ * @param {Number} [thickness]
101
+ * @param {Number} [time]
97
102
  * @memberof Debug */
98
103
  function debugLine(posA, posB, color, thickness=.1, time)
99
104
  {
100
105
  const halfDelta = vec2((posB.x - posA.x)/2, (posB.y - posA.y)/2);
101
106
  const size = vec2(thickness, halfDelta.length()*2);
102
- debugRect(posA.add(halfDelta), size, color, time, halfDelta.angle(), 1);
107
+ debugRect(posA.add(halfDelta), size, color, time, halfDelta.angle(), true);
103
108
  }
104
109
 
105
110
  /** Draw a debug axis aligned bounding box in world space
106
- * @param {Vector2} posA
107
- * @param {Vector2} sizeA
108
- * @param {Vector2} posB
109
- * @param {Vector2} sizeB
110
- * @param {String} [color='#fff']
111
+ * @param {Vector2} pA - position A
112
+ * @param {Vector2} sA - size A
113
+ * @param {Vector2} pB - position B
114
+ * @param {Vector2} sB - size B
115
+ * @param {String} [color]
111
116
  * @memberof Debug */
112
117
  function debugAABB(pA, sA, pB, sB, color)
113
118
  {
@@ -119,15 +124,15 @@ function debugAABB(pA, sA, pB, sB, color)
119
124
  /** Draw a debug axis aligned bounding box in world space
120
125
  * @param {String} text
121
126
  * @param {Vector2} pos
122
- * @param {Number} [size=1]
123
- * @param {String} [color='#fff']
124
- * @param {Number} [time=0]
125
- * @param {Number} [angle=0]
126
- * @param {String} [font='monospace']
127
+ * @param {Number} [size]
128
+ * @param {String} [color]
129
+ * @param {Number} [time]
130
+ * @param {Number} [angle]
131
+ * @param {String} [font]
127
132
  * @memberof Debug */
128
133
  function debugText(text, pos, size=1, color='#fff', time=0, angle=0, font='monospace')
129
134
  {
130
- ASSERT(typeof color == 'string'); // pass in regular html strings as colors
135
+ ASSERT(typeof color == 'string', 'pass in css color strings');
131
136
  debugPrimitives.push({text, pos, size, color, time:new Timer(time), angle, font});
132
137
  }
133
138
 
@@ -138,7 +143,7 @@ function debugClear() { debugPrimitives = []; }
138
143
  /** Save a canvas to disk
139
144
  * @param {HTMLCanvasElement} canvas
140
145
  * @param {String} [filename]
141
- * @param {String} [type='image/png']
146
+ * @param {String} [type]
142
147
  * @memberof Debug */
143
148
  function debugSaveCanvas(canvas, filename=engineName, type='image/png')
144
149
  { debugSaveDataURL(canvas.toDataURL(type), filename); }
@@ -146,7 +151,7 @@ function debugSaveCanvas(canvas, filename=engineName, type='image/png')
146
151
  /** Save a text file to disk
147
152
  * @param {String} text
148
153
  * @param {String} [filename]
149
- * @param {String} [type='text/plain']
154
+ * @param {String} [type]
150
155
  * @memberof Debug */
151
156
  function debugSaveText(text, filename=engineName, type='text/plain')
152
157
  { debugSaveDataURL(URL.createObjectURL(new Blob([text], {'type':type})), filename); }
@@ -181,22 +186,18 @@ function debugUpdate()
181
186
  debugOverlay = !debugOverlay;
182
187
  if (debugOverlay)
183
188
  {
184
- if (keyWasPressed(48)) // 0
189
+ if (keyWasPressed('Digit0'))
185
190
  showWatermark = !showWatermark;
186
- if (keyWasPressed(49)) // 1
187
- debugPhysics = !debugPhysics, debugParticles = 0;
188
- if (keyWasPressed(50)) // 2
189
- debugParticles = !debugParticles, debugPhysics = 0;
190
- if (keyWasPressed(51)) // 3
191
+ if (keyWasPressed('Digit1'))
192
+ debugPhysics = !debugPhysics, debugParticles = false;
193
+ if (keyWasPressed('Digit2'))
194
+ debugParticles = !debugParticles, debugPhysics = false;
195
+ if (keyWasPressed('Digit3'))
191
196
  debugGamepads = !debugGamepads;
192
- if (keyWasPressed(52)) // 4
197
+ if (keyWasPressed('Digit4'))
193
198
  debugRaycast = !debugRaycast;
194
- if (keyWasPressed(53)) // 5
199
+ if (keyWasPressed('Digit5'))
195
200
  debugTakeScreenshot = 1;
196
- //if (keyWasPressed(54)) // 6
197
- //if (keyWasPressed(55)) // 7
198
- //if (keyWasPressed(56)) // 8
199
- //if (keyWasPressed(57)) // 9
200
201
  }
201
202
  }
202
203
 
@@ -207,7 +208,7 @@ function debugRender()
207
208
  if (debugTakeScreenshot)
208
209
  {
209
210
  // composite canvas
210
- glCopyToContext(mainContext, 1);
211
+ glCopyToContext(mainContext, true);
211
212
  mainContext.drawImage(overlayCanvas, 0, 0);
212
213
  overlayCanvas.width |= 0;
213
214
 
@@ -236,7 +237,7 @@ function debugRender()
236
237
  {
237
238
  const drawPos = centerPos.add(vec2(j*stickScale*2, i*stickScale*3));
238
239
  const stickPos = drawPos.add(sticks[j].scale(stickScale));
239
- debugCircle(drawPos, stickScale, '#fff7',0,1);
240
+ debugCircle(drawPos, stickScale, '#fff7',0,true);
240
241
  debugLine(drawPos, stickPos, '#f00');
241
242
  debugPoint(stickPos, '#f00');
242
243
  }
@@ -244,8 +245,8 @@ function debugRender()
244
245
  {
245
246
  const drawPos = centerPos.add(vec2(j*buttonScale*2, i*stickScale*3-stickScale-buttonScale));
246
247
  const pressed = gamepad.buttons[j].pressed;
247
- debugCircle(drawPos, buttonScale, pressed ? '#f00' : '#fff7', 0, 1);
248
- debugText(j, drawPos, .2);
248
+ debugCircle(drawPos, buttonScale, pressed ? '#f00' : '#fff7', 0, true);
249
+ debugText(''+j, drawPos, .2);
249
250
  }
250
251
  }
251
252
  }
@@ -274,25 +275,25 @@ function debugRender()
274
275
 
275
276
  // show object info
276
277
  const size = vec2(max(o.size.x, .2), max(o.size.y, .2));
277
- const color1 = new Color(!!o.collideTiles, !!o.collideSolidObjects, !!o.isSolid, o.parent?.2:.5);
278
+ const color1 = new Color(o.collideTiles?1:0, o.collideSolidObjects?1:0, o.isSolid?1:0, o.parent?.2:.5);
278
279
  const color2 = o.parent ? new Color(1,1,1,.5) : new Color(0,0,0,.8);
279
- drawRect(o.pos, size, color1, o.angle, 0);
280
- drawRect(o.pos, size.scale(.8), color2, o.angle, 0);
281
- o.parent && drawLine(o.pos, o.parent.pos, .1, new Color(0,0,1,.5), 0);
280
+ drawRect(o.pos, size, color1, o.angle, false);
281
+ drawRect(o.pos, size.scale(.8), color2, o.angle, false);
282
+ o.parent && drawLine(o.pos, o.parent.pos, .1, new Color(0,0,1,.5), false);
282
283
  }
283
284
 
284
285
  if (bestObject)
285
286
  {
286
287
  const raycastHitPos = tileCollisionRaycast(bestObject.pos, mousePos);
287
288
  raycastHitPos && drawRect(raycastHitPos.floor().add(vec2(.5)), vec2(1), new Color(0,1,1,.3));
288
- drawRect(mousePos.floor().add(vec2(.5)), vec2(1), new Color(0,0,1,.5), 0, 0);
289
- drawLine(mousePos, bestObject.pos, .1, raycastHitPos ? new Color(1,0,0,.5) : new Color(0,1,0,.5), 0);
289
+ drawRect(mousePos.floor().add(vec2(.5)), vec2(1), new Color(0,0,1,.5), 0, false);
290
+ drawLine(mousePos, bestObject.pos, .1, raycastHitPos ? new Color(1,0,0,.5) : new Color(0,1,0,.5), false);
290
291
 
291
292
  const debugText = 'mouse pos = ' + mousePos +
292
293
  '\nmouse collision = ' + getTileCollisionData(mousePos) +
293
294
  '\n\n--- object info ---\n' +
294
295
  bestObject.toString();
295
- drawTextScreen(debugText, mousePosScreen, 24, new Color, .05, 0, 0, 'monospace');
296
+ drawTextScreen(debugText, mousePosScreen, 24, new Color, .05, undefined, 'center', 'monospace');
296
297
  }
297
298
 
298
299
  glCopyToContext(mainContext = saveContext);
@@ -381,7 +382,7 @@ function debugRender()
381
382
  let keysPressed = '';
382
383
  for(const i in inputData[0])
383
384
  {
384
- if (i && keyIsDown(i, 0))
385
+ if (keyIsDown(i, 0))
385
386
  keysPressed += i + ' ' ;
386
387
  }
387
388
  keysPressed && overlayContext.fillText('Keys Down: ' + keysPressed, x, y += h);
@@ -390,7 +391,7 @@ function debugRender()
390
391
  if (inputData[1])
391
392
  for(const i in inputData[1])
392
393
  {
393
- if (i && keyIsDown(i, 1))
394
+ if (keyIsDown(i, 1))
394
395
  buttonsPressed += i + ' ' ;
395
396
  }
396
397
  buttonsPressed && overlayContext.fillText('Gamepad: ' + buttonsPressed, x, y += h);
package/src/engineDraw.js CHANGED
@@ -61,9 +61,9 @@ let drawCount;
61
61
  * Create a tile info object
62
62
  * - This can take vecs or floats for easier use and conversion
63
63
  * - If an index is passed in, the tile size and index will determine the position
64
- * @param {(Number|Vector2)} [pos=Vector2()] - Top left corner of tile in pixels or index
65
- * @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
66
- * @param {Number} [textureIndex=0] - Texture index to use
64
+ * @param {(Number|Vector2)} [pos=Vector2()] - Top left corner of tile in pixels or index
65
+ * @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
66
+ * @param {Number} [textureIndex] - Texture index to use
67
67
  * @return {TileInfo}
68
68
  * @example
69
69
  * tile(2) // a tile at index 2 using the default tile size of 16
@@ -75,14 +75,14 @@ let drawCount;
75
75
  function tile(pos=vec2(), size=tileSizeDefault, textureIndex=0)
76
76
  {
77
77
  // if size is a number, make it a vector
78
- if (size.x == undefined)
78
+ if (typeof size === 'number')
79
79
  {
80
80
  ASSERT(size > 0);
81
81
  size = vec2(size);
82
82
  }
83
83
 
84
84
  // if pos is a number, use it as a tile index
85
- if (pos.x == undefined)
85
+ if (typeof pos === 'number')
86
86
  {
87
87
  const textureInfo = textureInfos[textureIndex];
88
88
  if (textureInfo)
@@ -106,7 +106,7 @@ class TileInfo
106
106
  /** Create a tile info object
107
107
  * @param {Vector2} [pos=Vector2()] - Top left corner of tile in pixels
108
108
  * @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
109
- * @param {Number} [textureIndex=0] - Texture index to use
109
+ * @param {Number} [textureIndex] - Texture index to use
110
110
  */
111
111
  constructor(pos=vec2(), size=tileSizeDefault, textureIndex=0)
112
112
  {
@@ -135,10 +135,13 @@ class TileInfo
135
135
  /** Texture Info - Stores info about each texture */
136
136
  class TextureInfo
137
137
  {
138
- // create a TextureInfo, called automatically by the engine
138
+ /**
139
+ * Create a TextureInfo, called automatically by the engine
140
+ * @param {HTMLImageElement} image
141
+ */
139
142
  constructor(image)
140
143
  {
141
- /** @property {CanvasImageSource} - image source */
144
+ /** @property {HTMLImageElement} - image source */
142
145
  this.image = image;
143
146
  /** @property {Vector2} - size of the image */
144
147
  this.size = vec2(image.width, image.height);
@@ -181,23 +184,21 @@ function worldToScreen(worldPos)
181
184
  * @param {Vector2} pos - Center of the tile in world space
182
185
  * @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
183
186
  * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
184
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
185
187
  * @param {Color} [color=Color()] - Color to modulate with
186
- * @param {Number} [angle=0] - Angle to rotate by
187
- * @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
188
+ * @param {Number} [angle] - Angle to rotate by
189
+ * @param {Boolean} [mirror] - If true image is flipped along the Y axis
188
190
  * @param {Color} [additiveColor=Color(0,0,0,0)] - Additive color to be applied
189
191
  * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
190
- * @param {Boolean} [screenSpace=0] - If true the pos and size are in screen space
192
+ * @param {Boolean} [screenSpace] - If true the pos and size are in screen space
191
193
  * @param {CanvasRenderingContext2D} [context] - Canvas 2D context to draw to
192
194
  * @memberof Draw */
193
195
  function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
194
196
  angle=0, mirror, additiveColor=new Color(0,0,0,0), useWebGL=glEnable, screenSpace, context)
195
197
  {
196
- ASSERT(!context || !useWebGL); // context only supported in canvas 2D mode
197
- ASSERT(typeof tileInfo !== 'number' || !tileInfo); // prevent old style calls
198
- // to fix old calls, replace with tile(tileIndex, tileSize)
198
+ ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
199
+ ASSERT(typeof tileInfo !== 'number' || !tileInfo,
200
+ 'this is an old style calls, to fix replace it with tile(tileIndex, tileSize)');
199
201
 
200
- showWatermark && ++drawCount;
201
202
  const textureInfo = tileInfo && tileInfo.getTextureInfo();
202
203
  if (useWebGL)
203
204
  {
@@ -231,6 +232,7 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
231
232
  else
232
233
  {
233
234
  // normal canvas 2D rendering method (slower)
235
+ showWatermark && ++drawCount;
234
236
  drawCanvas2D(pos, size, angle, mirror, (context)=>
235
237
  {
236
238
  if (textureInfo)
@@ -258,49 +260,38 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
258
260
  * @param {Vector2} pos
259
261
  * @param {Vector2} [size=Vector2(1,1)]
260
262
  * @param {Color} [color=Color()]
261
- * @param {Number} [angle=0]
263
+ * @param {Number} [angle]
262
264
  * @param {Boolean} [useWebGL=glEnable]
263
- * @param {Boolean} [screenSpace=0]
265
+ * @param {Boolean} [screenSpace]
264
266
  * @param {CanvasRenderingContext2D} [context]
265
267
  * @memberof Draw */
266
268
  function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
267
269
  {
268
- drawTile(pos, size, undefined, color, angle, 0, undefined, useWebGL, screenSpace, context);
270
+ drawTile(pos, size, undefined, color, angle, false, undefined, useWebGL, screenSpace, context);
269
271
  }
270
272
 
271
273
  /** Draw colored polygon using passed in points
272
274
  * @param {Array} points - Array of Vector2 points
273
275
  * @param {Color} [color=Color()]
274
- * @param {Boolean} [useWebGL=glEnable]
275
- * @param {Boolean} [screenSpace=0]
276
- * @param {CanvasRenderingContext2D} [context]
276
+ * @param {Boolean} [screenSpace]
277
+ * @param {CanvasRenderingContext2D} [context=mainContext]
277
278
  * @memberof Draw */
278
- function drawPoly(points, color=new Color, useWebGL=glEnable, screenSpace, context)
279
+ function drawPoly(points, color=new Color, screenSpace, context=mainContext)
279
280
  {
280
- ASSERT(!context || !useWebGL); // context only supported in canvas 2D mode
281
-
282
- if (useWebGL)
283
- glDrawPoints(screenSpace ? points.map(screenToWorld) : points, color.rgbaInt());
284
- else
285
- {
286
- // draw using canvas
287
- if (!context)
288
- context = mainContext;
289
- context.fillStyle = color;
290
- context.beginPath();
291
- for (const point of screenSpace ? points : points.map(worldToScreen))
292
- context.lineTo(point.x, point.y);
293
- context.fill();
294
- }
281
+ context.fillStyle = color.toString();
282
+ context.beginPath();
283
+ for (const point of screenSpace ? points : points.map(worldToScreen))
284
+ context.lineTo(point.x, point.y);
285
+ context.fill();
295
286
  }
296
287
 
297
288
  /** Draw colored line between two points
298
289
  * @param {Vector2} posA
299
290
  * @param {Vector2} posB
300
- * @param {Number} [thickness=.1]
291
+ * @param {Number} [thickness]
301
292
  * @param {Color} [color=Color()]
302
293
  * @param {Boolean} [useWebGL=glEnable]
303
- * @param {Boolean} [screenSpace=0]
294
+ * @param {Boolean} [screenSpace]
304
295
  * @param {CanvasRenderingContext2D} [context]
305
296
  * @memberof Draw */
306
297
  function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, context)
@@ -316,7 +307,7 @@ function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, contex
316
307
  * @param {Number} angle
317
308
  * @param {Boolean} mirror
318
309
  * @param {Function} drawFunction
319
- * @param {Boolean} [screenSpace=0]
310
+ * @param {Boolean} [screenSpace]
320
311
  * @param {CanvasRenderingContext2D} [context=mainContext]
321
312
  * @memberof Draw */
322
313
  function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, context=mainContext)
@@ -336,13 +327,13 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, conte
336
327
  }
337
328
 
338
329
  /** Enable normal or additive blend mode
339
- * @param {Boolean} [additive=0]
330
+ * @param {Boolean} [additive]
340
331
  * @param {Boolean} [useWebGL=glEnable]
341
332
  * @param {CanvasRenderingContext2D} [context=mainContext]
342
333
  * @memberof Draw */
343
334
  function setBlendMode(additive, useWebGL=glEnable, context)
344
335
  {
345
- ASSERT(!context || !useWebGL); // context only supported in canvas 2D mode
336
+ ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode');
346
337
  if (useWebGL)
347
338
  glAdditive = additive;
348
339
  else
@@ -357,11 +348,11 @@ function setBlendMode(additive, useWebGL=glEnable, context)
357
348
  * Automatically splits new lines into rows
358
349
  * @param {String} text
359
350
  * @param {Vector2} pos
360
- * @param {Number} [size=1]
351
+ * @param {Number} [size]
361
352
  * @param {Color} [color=Color()]
362
- * @param {Number} [lineWidth=0]
353
+ * @param {Number} [lineWidth]
363
354
  * @param {Color} [lineColor=Color(0,0,0)]
364
- * @param {String} [textAlign='center']
355
+ * @param {CanvasTextAlign} [textAlign='center']
365
356
  * @param {String} [font=fontDefault]
366
357
  * @param {CanvasRenderingContext2D} [context=overlayContext]
367
358
  * @memberof Draw */
@@ -374,19 +365,19 @@ function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, f
374
365
  * Automatically splits new lines into rows
375
366
  * @param {String} text
376
367
  * @param {Vector2} pos
377
- * @param {Number} [size=1]
368
+ * @param {Number} [size]
378
369
  * @param {Color} [color=Color()]
379
- * @param {Number} [lineWidth=0]
370
+ * @param {Number} [lineWidth]
380
371
  * @param {Color} [lineColor=Color(0,0,0)]
381
- * @param {String} [textAlign='center']
372
+ * @param {CanvasTextAlign} [textAlign]
382
373
  * @param {String} [font=fontDefault]
383
374
  * @param {CanvasRenderingContext2D} [context=overlayContext]
384
375
  * @memberof Draw */
385
376
  function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, context=overlayContext)
386
377
  {
387
- context.fillStyle = color;
378
+ context.fillStyle = color.toString();
388
379
  context.lineWidth = lineWidth;
389
- context.strokeStyle = lineColor;
380
+ context.strokeStyle = lineColor.toString();
390
381
  context.textAlign = textAlign;
391
382
  context.font = size + 'px '+ font;
392
383
  context.textBaseline = 'middle';
@@ -421,8 +412,8 @@ class FontImage
421
412
  {
422
413
  /** Create an image font
423
414
  * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
424
- * @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
425
- * @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
415
+ * @param {Vector2} [tileSize=Vector2(8)] - Size of the font source tiles
416
+ * @param {Vector2} [paddingSize=Vector2(0,1)] - How much extra space to add between characters
426
417
  * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
427
418
  */
428
419
  constructor(image, tileSize=vec2(8), paddingSize=vec2(0,1), context=overlayContext)
@@ -451,7 +442,7 @@ class FontImage
451
442
  /** Draw text in screen space using the image font
452
443
  * @param {String} text
453
444
  * @param {Vector2} pos
454
- * @param {Number} [scale=4]
445
+ * @param {Number} [scale]
455
446
  * @param {Boolean} [center]
456
447
  */
457
448
  drawTextScreen(text, pos, scale=4, center)
@@ -469,7 +460,7 @@ class FontImage
469
460
  for(let j=line.length; j--;)
470
461
  {
471
462
  // draw each character
472
- let charCode = line[j].charCodeAt();
463
+ let charCode = line[j].charCodeAt(0);
473
464
  if (charCode < 32 || charCode > 127)
474
465
  charCode = 127; // unknown character
475
466
 
@@ -493,7 +484,7 @@ class FontImage
493
484
  /** Returns true if fullscreen mode is active
494
485
  * @return {Boolean}
495
486
  * @memberof Draw */
496
- function isFullscreen() { return document.fullscreenElement; }
487
+ function isFullscreen() { return !!document.fullscreenElement; }
497
488
 
498
489
  /** Toggle fullsceen mode
499
490
  * @memberof Draw */
@@ -23,6 +23,7 @@ export {
23
23
 
24
24
  // Globals
25
25
  debug,
26
+ debugOverlay,
26
27
  showWatermark,
27
28
 
28
29
  // Debug