littlejsengine 1.17.1 → 1.17.10

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 (49) hide show
  1. package/LICENSE +10 -10
  2. package/dist/littlejs.d.ts +254 -171
  3. package/dist/littlejs.esm.js +892 -628
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +889 -626
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +885 -622
  8. package/examples/box2d/gameObjects.js +3 -3
  9. package/examples/electron/index.html +2 -2
  10. package/examples/index.html +10 -9
  11. package/examples/logo.png +0 -0
  12. package/examples/logo2.png +0 -0
  13. package/examples/module/build.bat +7 -0
  14. package/examples/module/build.js +121 -0
  15. package/examples/particles/index.html +1 -1
  16. package/examples/platformer/game.js +1 -1
  17. package/examples/platformer/gameEffects.js +5 -10
  18. package/examples/platformer/gameLevel.js +3 -3
  19. package/examples/puzzle/game.js +2 -2
  20. package/examples/shorts/base.html +4 -1
  21. package/examples/shorts/box2dPool.js +2 -2
  22. package/examples/shorts/box2dTileLayer.js +48 -0
  23. package/examples/shorts/colors.js +1 -1
  24. package/examples/shorts/fps.js +1 -1
  25. package/examples/shorts/music.js +5 -4
  26. package/examples/shorts/musicPlayer.js +4 -3
  27. package/examples/shorts/parallax.js +2 -2
  28. package/examples/shorts/tiltedView.js +1 -1
  29. package/examples/starter/index.html +2 -2
  30. package/package.json +5 -5
  31. package/plugins/box2d.js +166 -63
  32. package/plugins/pluginExport.js +1 -1
  33. package/plugins/postProcess.js +1 -1
  34. package/plugins/uiSystem.js +33 -20
  35. package/plugins/zzfxm.js +2 -2
  36. package/reference.md +9 -8
  37. package/src/engine.js +111 -134
  38. package/src/engineAudio.js +44 -58
  39. package/src/engineDebug.js +4 -4
  40. package/src/engineDraw.js +7 -4
  41. package/src/engineExport.js +2 -1
  42. package/src/engineInput.js +5 -5
  43. package/src/engineMath.js +9 -9
  44. package/src/engineObject.js +25 -25
  45. package/src/engineParticles.js +241 -118
  46. package/src/engineTileLayer.js +117 -88
  47. package/src/engineUtilities.js +105 -78
  48. package/src/engineWebGL.js +2 -2
  49. package/plugins/Box2D_License.txt +0 -17
package/plugins/box2d.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * - Contact begin and end callbacks
10
10
  * - Wraps b2Vec2 type to/from Vector2
11
11
  * - Raycasting and querying
12
+ * - Box2dTileLayer for grid based collision
12
13
  * - Every type of joint
13
14
  * - Debug physics drawing
14
15
  * @namespace Box2D
@@ -60,21 +61,24 @@ class Box2dObject extends EngineObject
60
61
  bodyDef.set_type(bodyType);
61
62
  bodyDef.set_position(box2d.vec2dTo(pos));
62
63
  bodyDef.set_angle(-angle);
64
+
65
+ /** @property {Object} - The Box2d body */
63
66
  this.body = box2d.world.CreateBody(bodyDef);
64
- this.body.object = this;
67
+ /** @property {Color} - Line color used for default box2d drawing */
65
68
  this.lineColor = BLACK;
66
- box2d.objects.push(this);
67
-
68
- // edge lists and loops for drawing
69
+ /** @property {Array<Object>} - List of all edges for default box2d drawing */
69
70
  this.edgeLists = [];
71
+ /** @property {Array<Object>} - List of all edge loops for default box2d drawing */
70
72
  this.edgeLoops = [];
73
+
74
+ this.body.object = this; // link body to this object
75
+ box2d.objects.push(this); // keep track of all box2d objects
71
76
  }
72
77
 
73
78
  /** Destroy this object and its physics body */
74
79
  destroy()
75
80
  {
76
- if (this.destroyed)
77
- return;
81
+ if (this.destroyed) return;
78
82
 
79
83
  // destroy physics body, fixtures, and joints
80
84
  ASSERT(this.body, 'Box2dObject has no body to destroy');
@@ -105,11 +109,12 @@ class Box2dObject extends EngineObject
105
109
  }
106
110
 
107
111
  /** Draws all this object's fixtures
108
- * @param {Color} [color]
109
- * @param {Color} [lineColor]
110
- * @param {number} [lineWidth]
112
+ * @param {Color} [color]
113
+ * @param {Color} [lineColor]
114
+ * @param {number} [lineWidth]
115
+ * @param {boolean} [useWebGL=glEnable]
111
116
  * @param {CanvasRenderingContext2D} [context] */
112
- drawFixtures(color=WHITE, lineColor=BLACK, lineWidth=.1, context)
117
+ drawFixtures(color=WHITE, lineColor=BLACK, lineWidth=.1, useWebGL, context)
113
118
  {
114
119
  // draw non-edge fixtures
115
120
  this.getFixtureList().forEach((fixture)=>
@@ -117,7 +122,7 @@ class Box2dObject extends EngineObject
117
122
  const shape = box2d.castObjectType(fixture.GetShape());
118
123
  if (shape.GetType() !== box2d.instance.b2Shape.e_edge)
119
124
  {
120
- box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, context);
125
+ box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, useWebGL, context);
121
126
  }
122
127
  });
123
128
 
@@ -343,6 +348,14 @@ class Box2dObject extends EngineObject
343
348
  return fixtures;
344
349
  }
345
350
 
351
+ /** Destroy a fixture from the body
352
+ * @param {Object} [fixture] */
353
+ destroyFixture(fixture) { this.body.DestroyFixture(fixture); }
354
+
355
+ /** Destroy all fixture from the body */
356
+ destroyAllFixtures()
357
+ { this.getFixtureList().forEach(fixture=>this.destroyFixture(fixture)); }
358
+
346
359
  ///////////////////////////////////////////////////////////////////////////////
347
360
  // physics get functions
348
361
 
@@ -575,6 +588,135 @@ class Box2dObject extends EngineObject
575
588
  }
576
589
  }
577
590
 
591
+ ///////////////////////////////////////////////////////////////////////////////
592
+ /**
593
+ * Box2D Static Object - Box2d with a static physics body
594
+ * @extends Box2dObject
595
+ * @memberof Box2D
596
+ */
597
+ class Box2dStaticObject extends Box2dObject
598
+ {
599
+ /** Create a LittleJS object with Box2d physics
600
+ * @param {Vector2} [pos]
601
+ * @param {Vector2} [size]
602
+ * @param {TileInfo} [tileInfo]
603
+ * @param {number} [angle]
604
+ * @param {Color} [color]
605
+ * @param {number} [renderOrder] */
606
+ constructor(pos, size, tileInfo, angle=0, color, renderOrder=0)
607
+ {
608
+ const bodyType = box2d.bodyTypeStatic;
609
+ super(pos, size, tileInfo, angle, color, bodyType, renderOrder);
610
+ }
611
+ }
612
+
613
+ ///////////////////////////////////////////////////////////////////////////////
614
+ /**
615
+ * Box2D Kinematic Object - Box2d with a kinematic physics body
616
+ * @extends Box2dObject
617
+ * @memberof Box2D
618
+ */
619
+ class Box2dKinematicObject extends Box2dObject
620
+ {
621
+ /** Create a LittleJS object with Box2d physics
622
+ * @param {Vector2} [pos]
623
+ * @param {Vector2} [size]
624
+ * @param {TileInfo} [tileInfo]
625
+ * @param {number} [angle]
626
+ * @param {Color} [color]
627
+ * @param {number} [renderOrder] */
628
+ constructor(pos, size, tileInfo, angle=0, color, renderOrder=0)
629
+ {
630
+ const bodyType = box2d.bodyTypeKinematic;
631
+ super(pos, size, tileInfo, angle, color, bodyType, renderOrder);
632
+ }
633
+ }
634
+
635
+ ///////////////////////////////////////////////////////////////////////////////
636
+ /**
637
+ * Box2d Tile Layer
638
+ * - adds Box2d support to tile layers
639
+ * - creates static box2d fixtures for solid tiles
640
+ * @extends Box2dObject
641
+ * @memberof Box2D
642
+ */
643
+ class Box2dTileLayer extends Box2dStaticObject
644
+ {
645
+ /** Create a Box2d tile layer object
646
+ * @param {TileCollisionLayer} tileLayer - Tile layer for this object */
647
+ constructor(tileLayer)
648
+ {
649
+ ASSERT(tileLayer instanceof TileCollisionLayer, 'tileLayer must be a TileCollisionLayer');
650
+ super(tileLayer.pos, tileLayer.size);
651
+
652
+ /** @property {TileLayer} - The tile layer */
653
+ this.tileLayer = tileLayer;
654
+ this.addChild(tileLayer);
655
+ }
656
+
657
+ render()
658
+ {
659
+ // do not render fixtures, tile layer handles rendering
660
+ }
661
+
662
+ /** Create box2d collision fixtures for solid tiles
663
+ * @param {number} [friction]
664
+ * @param {number} [restitution] */
665
+ buildCollision(friction=.2, restitution=0)
666
+ {
667
+ // destroy all fixtures and create new ones
668
+ this.destroyAllFixtures();
669
+
670
+ // create box2d object for this layer
671
+ this.pos = this.tileLayer.pos.copy();
672
+ this.size = this.tileLayer.size.copy();
673
+
674
+ // track which tiles have been processed
675
+ const processed = [];
676
+ const getIndex = (x, y)=> x + y * this.size.x;
677
+ const isSolidUnprocessed = (x, y)=>
678
+ !processed[getIndex(x, y)] &&
679
+ this.tileLayer.getCollisionData(vec2(x, y)) > 0;
680
+
681
+ // combine tiles into larger boxes
682
+ for (let x = 0; x < this.size.x; ++x)
683
+ for (let y = 0; y < this.size.y; ++y)
684
+ {
685
+ if (!isSolidUnprocessed(x, y)) continue;
686
+
687
+ // find max width by scanning right
688
+ let width = 1, height = 1, canExpand = true;
689
+ while (isSolidUnprocessed(x + width, y))
690
+ ++width;
691
+
692
+ // find max height by scanning up, ensuring all rows have the same width
693
+ while (canExpand)
694
+ {
695
+ for (let checkX = 0; checkX < width; ++checkX)
696
+ {
697
+ if (!isSolidUnprocessed(x + checkX, y + height))
698
+ {
699
+ canExpand = false;
700
+ break;
701
+ }
702
+ }
703
+ if (canExpand)
704
+ ++height;
705
+ }
706
+
707
+ // mark all tiles in this rectangle as processed
708
+ for (let rectX = width; rectX--;)
709
+ for (let rectY = height; rectY--;)
710
+ processed[getIndex(x + rectX, y + rectY)] = true;
711
+
712
+ // create a single fixture for the entire rectangle
713
+ const shapeSize = vec2(width, height);
714
+ const offset = vec2(x + width/2, y + height/2);
715
+ this.addBox(shapeSize, offset, 0, 0, friction, restitution);
716
+ }
717
+ }
718
+ }
719
+
578
720
  ///////////////////////////////////////////////////////////////////////////////
579
721
  /**
580
722
  * Box2D Raycast Result
@@ -616,6 +758,7 @@ class Box2dJoint
616
758
  * @param {Object} jointDef */
617
759
  constructor(jointDef)
618
760
  {
761
+ /** @property {Object} - The Box2d joint */
619
762
  this.box2dJoint = box2d.castObjectType(box2d.world.CreateJoint(jointDef));
620
763
  }
621
764
 
@@ -962,7 +1105,7 @@ class Box2dGearJoint extends Box2dJoint
962
1105
  * @param {Box2dObject} objectB
963
1106
  * @param {Box2dJoint} joint1
964
1107
  * @param {Box2dJoint} joint2
965
- * @param {ratio} [ratio] */
1108
+ * @param {number} [ratio] */
966
1109
  constructor(objectA, objectB, joint1, joint2, ratio=1)
967
1110
  {
968
1111
  const jointDef = new box2d.instance.b2GearJointDef();
@@ -1104,50 +1247,6 @@ class Box2dPrismaticJoint extends Box2dJoint
1104
1247
  getMotorForce(time) { return this.box2dJoint.GetMotorForce(1/time); }
1105
1248
  }
1106
1249
 
1107
- ///////////////////////////////////////////////////////////////////////////////
1108
- /**
1109
- * Box2D Static Object - Box2d with a static physics body
1110
- * @extends Box2dObject
1111
- * @memberof Box2D
1112
- */
1113
- class Box2dStaticObject extends Box2dObject
1114
- {
1115
- /** Create a LittleJS object with Box2d physics
1116
- * @param {Vector2} [pos]
1117
- * @param {Vector2} [size]
1118
- * @param {TileInfo} [tileInfo]
1119
- * @param {number} [angle]
1120
- * @param {Color} [color]
1121
- * @param {number} [renderOrder] */
1122
- constructor(pos, size, tileInfo, angle=0, color, renderOrder=0)
1123
- {
1124
- const bodyType = box2d.bodyTypeStatic;
1125
- super(pos, size, tileInfo, angle, color, bodyType, renderOrder);
1126
- }
1127
- }
1128
-
1129
- ///////////////////////////////////////////////////////////////////////////////
1130
- /**
1131
- * Box2D Kiematic Object - Box2d with a kinematic physics body
1132
- * @extends Box2dObject
1133
- * @memberof Box2D
1134
- */
1135
- class Box2dKiematicObject extends Box2dObject
1136
- {
1137
- /** Create a LittleJS object with Box2d physics
1138
- * @param {Vector2} [pos]
1139
- * @param {Vector2} [size]
1140
- * @param {TileInfo} [tileInfo]
1141
- * @param {number} [angle]
1142
- * @param {Color} [color]
1143
- * @param {number} [renderOrder] */
1144
- constructor(pos, size, tileInfo, angle=0, color, renderOrder=0)
1145
- {
1146
- const bodyType = box2d.bodyTypeKinematic;
1147
- super(pos, size, tileInfo, angle, color, bodyType, renderOrder);
1148
- }
1149
- }
1150
-
1151
1250
  ///////////////////////////////////////////////////////////////////////////////
1152
1251
  /**
1153
1252
  * Box2D Wheel Joint
@@ -1508,10 +1607,13 @@ class Box2dPlugin
1508
1607
  {
1509
1608
  ASSERT(!box2d, 'Box2D already initialized');
1510
1609
  box2d = this;
1610
+
1611
+ /** @property {Object} - The Box2d instance */
1511
1612
  this.instance = instance;
1613
+ /** @property {Object} - The Box2d world */
1512
1614
  this.world = new box2d.instance.b2World();
1615
+ /** @property {Array<Box2dObject>} - List of all Box2d objects */
1513
1616
  this.objects = [];
1514
-
1515
1617
  /** @property {number} - Velocity iterations per update*/
1516
1618
  this.velocityIterations = 8;
1517
1619
  /** @property {number} - Position iterations per update*/
@@ -1710,8 +1812,9 @@ class Box2dPlugin
1710
1812
  * @param {Color} [color]
1711
1813
  * @param {Color} [lineColor]
1712
1814
  * @param {number} [lineWidth]
1815
+ * @param {boolean} [useWebGL=glEnable]
1713
1816
  * @param {CanvasRenderingContext2D} [context] */
1714
- drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, context)
1817
+ drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, useWebgl, context)
1715
1818
  {
1716
1819
  const shape = box2d.castObjectType(fixture.GetShape());
1717
1820
  switch (shape.GetType())
@@ -1721,20 +1824,20 @@ class Box2dPlugin
1721
1824
  let points = [];
1722
1825
  for (let i=shape.GetVertexCount(); i--;)
1723
1826
  points.push(box2d.vec2From(shape.GetVertex(i)));
1724
- drawPoly(points, color, lineWidth, lineColor, pos, angle);
1827
+ drawPoly(points, color, lineWidth, lineColor, pos, angle, useWebgl, false, context);
1725
1828
  break;
1726
1829
  }
1727
1830
  case box2d.instance.b2Shape.e_circle:
1728
1831
  {
1729
1832
  const radius = shape.get_m_radius();
1730
- drawCircle(pos, radius*2, color, lineWidth, lineColor);
1833
+ drawCircle(pos, radius*2, color, lineWidth, lineColor, useWebgl, false, context);
1731
1834
  break;
1732
1835
  }
1733
1836
  case box2d.instance.b2Shape.e_edge:
1734
1837
  {
1735
1838
  const v1 = box2d.vec2From(shape.get_m_vertex1());
1736
1839
  const v2 = box2d.vec2From(shape.get_m_vertex2());
1737
- drawLine(v1, v2, lineWidth, lineColor, pos, angle);
1840
+ drawLine(v1, v2, lineWidth, lineColor, pos, angle, useWebgl, false, context);
1738
1841
  break;
1739
1842
  }
1740
1843
  }
@@ -1752,7 +1855,7 @@ class Box2dPlugin
1752
1855
  }
1753
1856
 
1754
1857
  /** converts a box2d vec2 pointer to a Vector2
1755
- * @param {Object} v */
1858
+ * @param {Object} vp */
1756
1859
  vec2FromPointer(vp)
1757
1860
  {
1758
1861
  const v = box2d.instance.wrapPointer(vp, box2d.instance.b2Vec2);
@@ -1864,7 +1967,7 @@ async function box2dInit()
1864
1967
  const box2dColorPointer = (c)=>
1865
1968
  box2dColor(box2d.instance.wrapPointer(c, box2d.instance.b2Color));
1866
1969
  const getDebugColor = (color)=>box2dColorPointer(color).scale(1,.8);
1867
- const getPointsList = (vertices, vertexCount) =>
1970
+ const getPointsList = (vertices, vertexCount)=>
1868
1971
  {
1869
1972
  const points = [];
1870
1973
  for (let i=vertexCount; i--;)
@@ -37,7 +37,7 @@ export
37
37
  Box2dPlugin,
38
38
  Box2dObject,
39
39
  Box2dStaticObject,
40
- Box2dKiematicObject,
40
+ Box2dKinematicObject,
41
41
  Box2dRaycastResult,
42
42
  Box2dJoint,
43
43
  Box2dTargetJoint,
@@ -24,7 +24,7 @@ class PostProcessPlugin
24
24
  {
25
25
  /** Create global post processing shader
26
26
  * @param {string} shaderCode
27
- * @param {boolean} [includeMainCanvas] - combine mainCanvs onto glCanvas
27
+ * @param {boolean} [includeMainCanvas] - combine mainCanvas onto glCanvas
28
28
  * @param {boolean} [feedbackTexture] - use glCanvas from previous frame as the texture
29
29
  * @example
30
30
  * // create the post process plugin object
@@ -30,7 +30,7 @@ let uiDebug = 0;
30
30
 
31
31
  /** Enable UI system debug drawing
32
32
  * 0=off, 1=normal, 2=show invisible
33
- * @param {number|boolean} enable
33
+ * @param {number|boolean} debugMode
34
34
  * @memberof UISystem */
35
35
  function uiSetDebug(debugMode)
36
36
  { uiDebug = typeof debugMode === 'boolean' ? (debugMode ? 1 : 0) : debugMode; }
@@ -96,7 +96,7 @@ class UISystemPlugin
96
96
  // navigation properties
97
97
  /** @property {UIObject} - Object currently selected by navigation (gamepad or keyboard) */
98
98
  this.navigationObject = undefined;
99
- /** @property {Timer} - Cooldown timer for navigation inputs */
99
+ /** @property {Timer} - Cool down timer for navigation inputs */
100
100
  this.navigationTimer = new Timer(undefined, true);
101
101
  /** @property {number} - Time between navigation inputs in seconds */
102
102
  this.navigationDelay = .2;
@@ -562,7 +562,7 @@ class UISystemPlugin
562
562
 
563
563
  const savedNavigationDirection = uiSystem.navigationDirection;
564
564
 
565
- // allow both axies for navigation
565
+ // allow both axes for navigation
566
566
  uiSystem.navigationDirection = 2;
567
567
 
568
568
  // confirm menu
@@ -657,7 +657,7 @@ class UIObject
657
657
  this.lineWidth = uiSystem.defaultLineWidth;
658
658
  /** @property {number} - Corner radius for rounded rects */
659
659
  this.cornerRadius = uiSystem.defaultCornerRadius;
660
- /** @property {string} - Font for this objecct */
660
+ /** @property {string} - Font for this object */
661
661
  this.font = uiSystem.defaultFont;
662
662
  /** @property {string} - Font style for this object or undefined */
663
663
  this.fontStyle = undefined;
@@ -1145,6 +1145,8 @@ class UIScrollbar extends UIObject
1145
1145
  this.value = value;
1146
1146
  /** @property {Color} - Color for the handle part of the scrollbar */
1147
1147
  this.handleColor = handleColor.copy();
1148
+ /** @property {boolean} - Should it fill up like a progress bar? */
1149
+ this.fillMode = false;
1148
1150
 
1149
1151
  // set properties
1150
1152
  this.text = text;
@@ -1190,19 +1192,30 @@ class UIScrollbar extends UIObject
1190
1192
 
1191
1193
  // handle horizontal or vertical scrollbar
1192
1194
  const isHorizontal = this.size.x > this.size.y;
1193
- const handleSize = isHorizontal ? this.size.y : this.size.x;
1194
- const barSize = isHorizontal ? this.size.x : this.size.y;
1195
- const centerPos = isHorizontal ? this.pos.x : this.pos.y;
1196
-
1197
- // draw the scrollbar handle
1198
- const handleWidth = barSize - handleSize;
1199
- const p1 = centerPos - handleWidth/2;
1200
- const p2 = centerPos + handleWidth/2;
1201
- const handlePos = isHorizontal ?
1202
- vec2(lerp(p1, p2, this.value), this.pos.y) :
1203
- vec2(this.pos.x, lerp(p2, p1, this.value))
1204
- const handleColor = this.disabled ? this.disabledColor : this.handleColor;
1205
- uiSystem.drawRect(handlePos, vec2(handleSize), handleColor, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
1195
+ const barWidth = isHorizontal ? this.size.x : this.size.y;
1196
+ const handleWidth = isHorizontal ? this.size.y : this.size.x;
1197
+ if (this.fillMode)
1198
+ {
1199
+ // draw progress bar
1200
+ const minWidth = min(handleWidth, this.cornerRadius * 2);
1201
+ const progressWidth = lerp(minWidth, barWidth, this.value);
1202
+ const p = (progressWidth - barWidth) * (isHorizontal ? .5 : -.5);
1203
+ const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
1204
+ const color = this.disabled ? this.disabledColor : this.handleColor;
1205
+ const drawSize = isHorizontal ?
1206
+ vec2(progressWidth, this.size.y) : vec2(this.size.x, progressWidth);
1207
+ uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
1208
+ }
1209
+ else
1210
+ {
1211
+ // draw the scrollbar handle
1212
+ const value = isHorizontal ? this.value : 1 - this.value;
1213
+ const p = (barWidth - handleWidth) * (value - .5);
1214
+ const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
1215
+ const color = this.disabled ? this.disabledColor : this.handleColor;
1216
+ const drawSize = vec2(handleWidth);
1217
+ uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
1218
+ }
1206
1219
 
1207
1220
  // draw the text scaled to fit on the scrollbar
1208
1221
  const textSize = this.getTextSize();
@@ -1224,15 +1237,15 @@ class UIScrollbar extends UIObject
1224
1237
  * @extends UIObject
1225
1238
  * @example
1226
1239
  * // Create a video player UI object
1227
- * const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), 'cutscene.mp4', true);
1240
+ * const video = new VideoPlayerUIObject(vec2(400, 300), vec2(320, 240), 'video.mp4', true);
1228
1241
  * video.play();
1229
1242
  * @memberof UISystem
1230
1243
  */
1231
1244
  class UIVideo extends UIObject
1232
1245
  {
1233
1246
  /** Create a video player UI object
1234
- * @param {Vector2} [pos]
1235
- * @param {Vector2} [size]
1247
+ * @param {Vector2} pos
1248
+ * @param {Vector2} size
1236
1249
  * @param {string} src - Video file path or URL
1237
1250
  * @param {boolean} [autoplay=false] - Start playing immediately?
1238
1251
  * @param {boolean} [loop=false] - Loop the video?
package/plugins/zzfxm.js CHANGED
@@ -55,7 +55,7 @@ class ZzFXMusic extends Sound
55
55
  /** Play the music that loops by default
56
56
  * @param {number} [volume] - Volume to play the music at
57
57
  * @param {boolean} [loop] - Should the music loop?
58
- * @return {AudioBufferSourceNode} - The audio source node
58
+ * @return {SoundInstance} - The sound instance
59
59
  */
60
60
  playMusic(volume=1, loop=true)
61
61
  { return super.play(undefined, volume, 1, 0, loop); }
@@ -102,7 +102,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
102
102
  sampleBuffer = [hasMore = notFirstBeat = outSampleOffset = 0];
103
103
 
104
104
  // for each pattern in sequence
105
- sequence.forEach((patternIndex, sequenceIndex) => {
105
+ sequence.forEach((patternIndex, sequenceIndex)=> {
106
106
  // get pattern for current channel, use empty 1 note pattern if none found
107
107
  patternChannel = patterns[patternIndex][channelIndex] || [0, 0, 0];
108
108
 
package/reference.md CHANGED
@@ -205,8 +205,8 @@ tileDefaultBleed = .3 // How much smaller to draw tiles to prevent bleeding
205
205
 
206
206
  ```javascript
207
207
  // Sound Object
208
- Sound(zzfxSound, range, taper) // Create a zzfx sound
209
- SoundWave(filename, randomness=0, range, taper) // Load a wave, mp3, or ogg
208
+ Sound(zzfxSound, randomness, range, taper) // Create a zzfx sound
209
+ Sound(filename, randomness, range, taper) // Load a wave, mp3, or ogg
210
210
  Sound.play(pos, volume=1, pitch=1, randomness=1, loop) // Play a sound, returns SoundInstance
211
211
  Sound.playMusic(volume=1, loop=true) // Play as music with looping
212
212
  Sound.playNote(semitoneOffset, pos, volume=1) // Play as note with a semitone offset
@@ -371,15 +371,16 @@ engineObjectsDestroy()
371
371
  ```javascript
372
372
 
373
373
  // Canvas Layer
374
- CanvasLayer(position, size) // Create a canvas layer object
374
+ CanvasLayer(pos, size) // Create a canvas layer object
375
375
  CanvasLayer.canvas // The canvas used by this layer
376
376
  CanvasLayer.context // The 2D context of the canvas
377
377
  CanvasLayer.getImageData() // Get image data from canvas
378
378
  CanvasLayer.updateWebGL() // Creates or updates WebGL texture
379
379
 
380
380
  // LittleJS Layer System
381
- TileLayer(position, size, tileInfo, scale) // Create a tile layer object
381
+ TileLayer(pos, size, tileInfo, scale) // Create a tile layer object
382
382
  TileLayer.setData(layerPos, data, redraw) // Set data at position
383
+ TileLayer.clearData(layerPos, redraw) // Clear data at position
383
384
  TileLayer.getData(layerPos) // Get data at position
384
385
  TileLayer.redraw() // Draw to an offscreen canvas
385
386
  TileLayer.drawTileData(layerPos, clear=true) // Draw the tile
@@ -392,12 +393,12 @@ TileLayerData(tile, direction=0, mirror=false, color=WHITE) // Create tile data
392
393
  TileLayerData.clear() // Clear this tile data
393
394
 
394
395
  // Tile Collision Layer
395
- TileCollisionLayer(position, size, tileInfo=tile()) // Create a tile collision layer object
396
+ TileCollisionLayer(pos, size, tileInfo=tile()) // Create a tile collision layer object
396
397
  TileCollisionLayer.setCollisionData(pos, data=1) // Set tile collision data at pos
397
398
  tileCollisionGetData(pos) // Get tile collision data at pos
398
399
  tileCollisionTest(pos, size=(0,0), object) // Check if collision should occur
399
400
  tileCollisionRaycast(posStart, posEnd, object) // Return the center of tile if hit
400
- tileLayersLoad(tileMapData, tileInfo) // Load tile layers from exported data
401
+ tileLayersLoad(tileMapData, tileInfo) // Load tile layers from exported data
401
402
 
402
403
  ```
403
404
 
@@ -407,8 +408,8 @@ tileLayersLoad(tileMapData, tileInfo) // Load tile layers from export
407
408
 
408
409
  ```javascript
409
410
  // Particle Emitter Object
410
- ParticleEmitter(position, angle, ...settings) // Create a particle system
411
- ParticleEmitter.emitParticle() // Spawn one particle
411
+ ParticleEmitter(pos, angle, ...settings) // Create a particle system
412
+ ParticleEmitter.emitParticle() // Spawn one particle
412
413
 
413
414
  // Particle Settings
414
415
  particleEmitRateScale = 1 // Scales particles emit rate