littlejsengine 1.14.11 → 1.14.19

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 (80) hide show
  1. package/dist/littlejs.d.ts +303 -137
  2. package/dist/littlejs.esm.js +936 -463
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +934 -462
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +859 -417
  7. package/examples/box2d/game.js +3 -2
  8. package/examples/box2d/gameObjects.js +2 -2
  9. package/examples/box2d/tiles.png +0 -0
  10. package/examples/breakout/game.js +5 -5
  11. package/examples/breakout/gameObjects.js +2 -2
  12. package/examples/breakoutTutorial/README.md +32 -32
  13. package/examples/breakoutTutorial/game.js +1 -1
  14. package/examples/electron/game.js +4 -4
  15. package/examples/electron/index.html +2 -2
  16. package/examples/electron/package.json +1 -8
  17. package/examples/index.html +67 -56
  18. package/examples/module/game.js +4 -4
  19. package/examples/platformer/gameEffects.js +5 -5
  20. package/examples/platformer/gameLevel.js +1 -1
  21. package/examples/platformer/gameObjects.js +4 -4
  22. package/examples/puzzle/game.js +1 -1
  23. package/examples/shorts/animation.js +1 -1
  24. package/examples/shorts/base.html +1 -1
  25. package/examples/shorts/blending.js +8 -14
  26. package/examples/shorts/box2d.js +7 -3
  27. package/examples/shorts/box2dCar.js +2 -1
  28. package/examples/shorts/empty.js +30 -0
  29. package/examples/shorts/helloWorld.js +1 -1
  30. package/examples/shorts/hillGlideGame.js +10 -4
  31. package/examples/shorts/landerGame.js +11 -8
  32. package/examples/shorts/medals.js +4 -4
  33. package/examples/shorts/music.js +29 -56
  34. package/examples/shorts/musicPlayer.js +135 -0
  35. package/examples/shorts/nineSlice.js +34 -15
  36. package/examples/shorts/parallax.js +5 -4
  37. package/examples/shorts/particles.js +15 -15
  38. package/examples/shorts/piano.js +15 -21
  39. package/examples/shorts/pongGame.js +6 -4
  40. package/examples/shorts/raycasting.js +9 -4
  41. package/examples/shorts/sequencer.js +122 -0
  42. package/examples/shorts/shader.js +29 -0
  43. package/examples/shorts/shapes.js +7 -4
  44. package/examples/shorts/slidingPuzzle.js +4 -2
  45. package/examples/shorts/sound.js +18 -9
  46. package/examples/shorts/spaceGame.js +12 -8
  47. package/examples/shorts/spriteAtlas.js +7 -7
  48. package/examples/shorts/starfield.js +1 -1
  49. package/examples/shorts/systemFont.js +2 -2
  50. package/examples/shorts/texture.js +2 -2
  51. package/examples/shorts/tileLayer.js +10 -10
  52. package/examples/shorts/tiltedView.js +24 -5
  53. package/examples/shorts/timers.js +10 -0
  54. package/examples/shorts/topDown.js +4 -1
  55. package/examples/shorts/uiSystem.js +8 -5
  56. package/examples/starter/game.js +4 -4
  57. package/examples/starter/index.html +2 -2
  58. package/examples/style.css +1 -0
  59. package/examples/typescript/game.js +4 -4
  60. package/examples/typescript/game.ts +4 -4
  61. package/examples/uiSystem/game.js +4 -3
  62. package/package.json +4 -2
  63. package/plugins/box2d.js +17 -2
  64. package/plugins/newgrounds.js +7 -5
  65. package/plugins/postProcess.js +76 -53
  66. package/plugins/uiSystem.js +192 -53
  67. package/plugins/zzfxm.js +5 -1
  68. package/reference.md +1 -1
  69. package/src/engine.js +60 -23
  70. package/src/engineAudio.js +44 -17
  71. package/src/engineDebug.js +75 -45
  72. package/src/engineDraw.js +94 -59
  73. package/src/engineExport.js +2 -1
  74. package/src/engineMedals.js +10 -2
  75. package/src/engineObject.js +14 -10
  76. package/src/engineParticles.js +60 -47
  77. package/src/engineSettings.js +7 -7
  78. package/src/engineTileLayer.js +73 -56
  79. package/src/engineUtilities.js +67 -20
  80. package/src/engineWebGL.js +134 -63
@@ -9,8 +9,10 @@ class GameObject extends EngineObject
9
9
  render()
10
10
  {
11
11
  // adjust draw postion to be at the bottom of the object
12
- const pos = this.pos.add(vec2(0,this.size.y/2).rotate(this.angle));
13
- drawTile(pos, this.size, this.tileInfo, this.color, this.angle);
12
+ const drawSize = this.drawSize || this.size;
13
+ const offset = vec2(0,drawSize.y/2).rotate(this.angle);
14
+ const pos = this.pos.add(offset);
15
+ drawTile(pos, drawSize, this.tileInfo, this.color, this.angle);
14
16
  }
15
17
  }
16
18
 
@@ -23,6 +25,7 @@ class Player extends GameObject
23
25
  // apply movement controls
24
26
  const moveInput = keyDirection().clampLength(1).scale(.2);
25
27
  this.velocity = this.velocity.add(moveInput);
28
+ this.setCollision(); // make object collide
26
29
 
27
30
  // move camera with player
28
31
  cameraPos = this.pos.add(vec2(0,2));
@@ -33,13 +36,29 @@ function gameInit()
33
36
  {
34
37
  // setup level
35
38
  objectDefaultDamping = .7;
36
- new Player(vec2(), vec2(3), tile(5), 0, RED);
39
+ const player = new Player(vec2(), vec2(3,1), tile(5), 0, RED);
40
+ player.drawSize = vec2(3);
37
41
 
38
42
  // create background objects
39
43
  for (let i=1; i<300; ++i)
40
- new EngineObject(randInCircle(90), vec2(rand(59),rand(59)), 0, 0, hsl(.4,.2,rand(.4,.5),.8), -1e5);
44
+ {
45
+ const pos = randInCircle(90);
46
+ const size = vec2(rand(59), rand(59));
47
+ const color = hsl(.4,.2,rand(.4,.5),.8);
48
+ new EngineObject(pos, size, 0, 0, color, -1e5);
49
+ }
41
50
 
42
51
  // create world objects
43
52
  for (let i=1; i<1e3; ++i)
44
- new GameObject(randInCircle(7+i,7), vec2(rand(1,2),rand(4,9)), 0, 0, hsl(.1,.5,rand(.2,.3)));
53
+ {
54
+ const pos = randInCircle(7+i,7);
55
+ const isRock = randBool();
56
+ const size = vec2(isRock ? rand(2,4) : rand(1,2));
57
+ const color = hsl(.1,isRock ? 0 : .5,rand(.2,.3));
58
+ const o = new GameObject(pos, size, 0, 0, color);
59
+ o.setCollision(); // make object collide
60
+ o.mass = 0; // make object have static physics
61
+ o.angle = rand(-.1,.1); // random tilt
62
+ o.drawSize = vec2(size.x, isRock ? rand(2,4) : rand(5,10));
63
+ }
45
64
  }
@@ -1,4 +1,5 @@
1
1
  let timerButton, timerSlider;
2
+ let timerSound = new Sound([2,0,999,,,,,1.5,,.3,-99,.1,1.63,,,.11]);
2
3
 
3
4
  function gameInit()
4
5
  {
@@ -13,13 +14,16 @@ function gameInit()
13
14
  timerButton.timer = new Timer;
14
15
  timerButton.onClick = ()=>
15
16
  {
17
+ timerButton.isSet = true;
16
18
  if (timerButton.timer.isSet())
17
19
  {
20
+ timerSound.play(0, .5, 2);
18
21
  timerButton.timer.unset();
19
22
  timerButton.text = 'Start';
20
23
  }
21
24
  else
22
25
  {
26
+ timerSound.play(0, .5, .5);
23
27
  timerButton.timer.set(3);
24
28
  timerButton.text = 'Stop';
25
29
  }
@@ -30,6 +34,12 @@ function gameInit()
30
34
  timerSlider.interactive = false;
31
35
  timerSlider.update = ()=>
32
36
  {
37
+ if (timerButton.isSet && timerButton.timer.elapsed())
38
+ {
39
+ timerSound.play();
40
+ timerButton.isSet = 0;
41
+ }
42
+
33
43
  // update the timer display
34
44
  const t = timerButton.timer.get();
35
45
  const timeText = t.toFixed(2) + 's';
@@ -30,7 +30,10 @@ function gameInit()
30
30
  // create collision objects
31
31
  for (let i=300; i--;)
32
32
  {
33
- const o = new EngineObject(randInCircle(15+i,7), vec2(rand(4,9),rand(4,9)), 0, 0, hsl(0,0,rand(.1,.3)));
33
+ const pos = randInCircle(15+i,7);
34
+ const size = vec2(rand(4,9),rand(4,9));
35
+ const color = hsl(.1,.5,rand(.2));
36
+ const o = new EngineObject(pos, size, 0, 0, color);
34
37
  o.setCollision(); // make object collide
35
38
  o.mass = 0; // make object have static physics
36
39
  }
@@ -2,12 +2,13 @@ function gameInit()
2
2
  {
3
3
  // setup ui system plugin
4
4
  new UISystemPlugin;
5
- uiSystem.defaultSoundPress = new Sound([1,0,220]);
6
- uiSystem.defaultSoundClick = new Sound([1,0,440]);
5
+ uiSystem.defaultSoundPress = new Sound([.5,0,220]);
6
+ uiSystem.defaultSoundClick = new Sound([.5,0,440]);
7
7
  uiSystem.defaultCornerRadius = 8;
8
8
 
9
9
  // example button that returns to menu
10
- const buttonBack = new UIButton(mainCanvasSize.scale(.5), vec2(200), 'Back\nto\nMenu');
10
+ const buttonBack = new UIButton(mainCanvasSize.scale(.5), vec2(200),
11
+ 'Back\nto\nMenu');
11
12
  buttonBack.textHeight = 60;
12
13
  buttonBack.onClick = ()=> uiMenu.visible = true;
13
14
 
@@ -16,7 +17,8 @@ function gameInit()
16
17
  canvasClearColor = hsl(0,0,.8);
17
18
 
18
19
  // example text
19
- uiMenu.addChild(new UIText(vec2(-80,-120), vec2(500, 80), 'LittleJS UI\nSystem Demo'));
20
+ uiMenu.addChild(new UIText(vec2(-80,-120), vec2(500, 80),
21
+ 'LittleJS UI\nSystem Demo'));
20
22
 
21
23
  // example image
22
24
  uiMenu.addChild(new UITile(vec2(200,-140), vec2(128), tile(3, 128)));
@@ -33,7 +35,8 @@ function gameInit()
33
35
  uiMenu.addChild(checkbox);
34
36
 
35
37
  // example scrollbar
36
- const scrollbar = new UIScrollbar(vec2(0,90), vec2(300, 50), soundVolume, 'Volume');
38
+ const scrollbar = new UIScrollbar(vec2(0,90), vec2(300, 50), soundVolume,
39
+ 'Volume');
37
40
  uiMenu.addChild(scrollbar);
38
41
  scrollbar.onChange = ()=> setSoundVolume(scrollbar.value);
39
42
 
@@ -65,16 +65,16 @@ function gameInit()
65
65
  // create particle emitter
66
66
  particleEmitter = new ParticleEmitter(
67
67
  vec2(16,9), 0, // emitPos, emitAngle
68
- 0, 0, 500, PI, // emitSize, emitTime, emitRate, emitCone
68
+ 0, 0, 500, PI, // emitSize, emitTime, rate, cone
69
69
  tile(0, 16), // tileIndex, tileSize
70
70
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
71
71
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
72
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
72
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
73
73
  .99, 1, 1, PI, // damping, angleDamping, gravityScale, cone
74
74
  .05, .5, true, true // fadeRate, randomness, collide, additive
75
75
  );
76
76
  particleEmitter.restitution = .3; // bounce when it collides
77
- particleEmitter.trailScale = 2; // stretch in direction of motion
77
+ particleEmitter.trailScale = 2; // stretch as it moves
78
78
  }
79
79
 
80
80
  ///////////////////////////////////////////////////////////////////////////////
@@ -86,7 +86,7 @@ function gameUpdate()
86
86
  sound_click.play(mousePos);
87
87
 
88
88
  // change particle color and set to fade out
89
- particleEmitter.colorStartA = hsl();
89
+ particleEmitter.colorStartA = randColor();
90
90
  particleEmitter.colorStartB = randColor();
91
91
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
92
92
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
@@ -7,7 +7,7 @@
7
7
  </head><body>
8
8
 
9
9
  <!-- LittleJS Engine -->
10
- <script src=../../dist/littlejs.js?1136></script>
10
+ <script src=../../dist/littlejs.js?11417></script>
11
11
 
12
12
  <!-- LittleJS Engine Source
13
13
  <script src=../../src/engineDebug.js></script>
@@ -31,4 +31,4 @@
31
31
  -->
32
32
 
33
33
  <!-- Add your game scripts here -->
34
- <script src=game.js?1136></script>
34
+ <script src=game.js?11417></script>
@@ -73,6 +73,7 @@ iframe
73
73
  margin: 5px;
74
74
  text-align: center;
75
75
  font-size: 40px;
76
+ font-weight: bold;
76
77
  }
77
78
  #exampleInfo
78
79
  {
@@ -52,16 +52,16 @@ function gameInit() {
52
52
  LJS.setGravity(vec2(0, -.01));
53
53
  // create particle emitter
54
54
  particleEmitter = new LJS.ParticleEmitter(vec2(16, 9), 0, // emitPos, emitAngle
55
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
55
+ 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
56
56
  tile(0, 16), // tileIndex, tileSize
57
57
  hsl(1, 1, 1), hsl(0, 0, 0), // colorStartA, colorStartB
58
58
  hsl(0, 0, 0, 0), hsl(0, 0, 0, 0), // colorEndA, colorEndB
59
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
59
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
60
60
  .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
61
61
  .05, .5, true, true // fadeRate, randomness, collide, additive
62
62
  );
63
63
  particleEmitter.restitution = .3; // bounce when it collides
64
- particleEmitter.trailScale = 2; // stretch in direction of motion
64
+ particleEmitter.trailScale = 2; // stretch as it moves
65
65
  }
66
66
  ///////////////////////////////////////////////////////////////////////////////
67
67
  function gameUpdate() {
@@ -69,7 +69,7 @@ function gameUpdate() {
69
69
  // play sound when mouse is pressed
70
70
  sound_click.play(LJS.mousePos);
71
71
  // change particle color and set to fade out
72
- particleEmitter.colorStartA = hsl();
72
+ particleEmitter.colorStartA = LJS.randColor();
73
73
  particleEmitter.colorStartB = LJS.randColor();
74
74
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1, 0);
75
75
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1, 0);
@@ -69,16 +69,16 @@ function gameInit()
69
69
  // create particle emitter
70
70
  particleEmitter = new LJS.ParticleEmitter(
71
71
  vec2(16,9), 0, // emitPos, emitAngle
72
- 1, 0, 500, Math.PI, // emitSize, emitTime, emitRate, emitCone
72
+ 1, 0, 500, Math.PI, // emitSize, emitTime, rate, cone
73
73
  tile(0, 16), // tileIndex, tileSize
74
74
  hsl(1,1,1), hsl(0,0,0), // colorStartA, colorStartB
75
75
  hsl(0,0,0,0), hsl(0,0,0,0), // colorEndA, colorEndB
76
- 2, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
76
+ 1, .2, .2, .1, .05, // time, sizeStart, sizeEnd, speed, angleSpeed
77
77
  .99, 1, 1, Math.PI, // damping, angleDamping, gravityScale, cone
78
78
  .05, .5, true, true // fadeRate, randomness, collide, additive
79
79
  );
80
80
  particleEmitter.restitution = .3; // bounce when it collides
81
- particleEmitter.trailScale = 2; // stretch in direction of motion
81
+ particleEmitter.trailScale = 2; // stretch stretch as it moves
82
82
  }
83
83
 
84
84
  ///////////////////////////////////////////////////////////////////////////////
@@ -90,7 +90,7 @@ function gameUpdate()
90
90
  sound_click.play(LJS.mousePos);
91
91
 
92
92
  // change particle color and set to fade out
93
- particleEmitter.colorStartA = hsl();
93
+ particleEmitter.colorStartA = LJS.randColor();
94
94
  particleEmitter.colorStartB = LJS.randColor();
95
95
  particleEmitter.colorEndA = particleEmitter.colorStartA.scale(1,0);
96
96
  particleEmitter.colorEndB = particleEmitter.colorStartB.scale(1,0);
@@ -21,9 +21,10 @@ LJS.setCanvasPixelated(false);
21
21
 
22
22
  function createUI()
23
23
  {
24
- LJS.uiSystem.defaultSoundPress = new LJS.Sound([1,0,220]);
25
- LJS.uiSystem.defaultSoundClick = new LJS.Sound([1,0,440]);
24
+ LJS.uiSystem.defaultSoundPress = new LJS.Sound([.5,0,220]);
25
+ LJS.uiSystem.defaultSoundClick = new LJS.Sound([.5,0,440]);
26
26
  LJS.uiSystem.defaultCornerRadius = 8;
27
+ LJS.uiSystem.defaultGradientColor = LJS.WHITE;
27
28
 
28
29
  // setup root to attach all ui elements to
29
30
  uiRoot = new LJS.UIObject;
@@ -63,7 +64,7 @@ function createUI()
63
64
  // example button
64
65
  const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
65
66
  uiMenu.addChild(button1);
66
- button1.onClick = ()=> LOG('Button 1 clicked');
67
+ button1.onClick = ()=> uiBackground.color = hsl(Math.random(),1,.7);
67
68
 
68
69
  // example checkbox
69
70
  const checkbox = new LJS.UICheckbox(vec2(-140,-20), vec2(40));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "littlejsengine",
3
- "version": "1.14.11",
3
+ "version": "1.14.19",
4
4
  "description": "LittleJS - Tiny and Fast HTML5 Game Engine",
5
5
  "main": "dist/littlejs.esm.js",
6
6
  "types": "dist/littlejs.d.ts",
@@ -37,6 +37,8 @@
37
37
  "google-closure-compiler": "~20230502.0.0",
38
38
  "roadroller": "~2.1.0",
39
39
  "typescript": "~5.1.6",
40
- "uglify-js": "~3.17.4"
40
+ "uglify-js": "~3.17.4",
41
+ "electron": "^38.2.0",
42
+ "electron-packager": "^17.1.2"
41
43
  }
42
44
  }
package/plugins/box2d.js CHANGED
@@ -39,6 +39,7 @@ function box2dSetDebug(enable) { box2dDebug = enable; }
39
39
  * - Each object has a Box2D body which can have multiple fixtures and joints
40
40
  * - Provides interface for Box2D body and fixture functions
41
41
  * @extends EngineObject
42
+ * @memberof Box2D
42
43
  */
43
44
  class Box2dObject extends EngineObject
44
45
  {
@@ -50,7 +51,7 @@ class Box2dObject extends EngineObject
50
51
  * @param {Color} [color]
51
52
  * @param {number} [bodyType]
52
53
  * @param {number} [renderOrder] */
53
- constructor(pos=vec2(), size, tileInfo, angle=0, color, bodyType=box2d.bodyTypeDynamic, renderOrder=0)
54
+ constructor(pos, size, tileInfo, angle=0, color, bodyType=box2d.bodyTypeDynamic, renderOrder=0)
54
55
  {
55
56
  super(pos, size, tileInfo, angle, color, renderOrder);
56
57
 
@@ -64,7 +65,7 @@ class Box2dObject extends EngineObject
64
65
  this.lineColor = BLACK;
65
66
  }
66
67
 
67
- /** Destroy this object and it's physics body */
68
+ /** Destroy this object and its physics body */
68
69
  destroy()
69
70
  {
70
71
  // destroy physics body, fixtures, and joints
@@ -548,6 +549,7 @@ class Box2dRaycastResult
548
549
  * Box2D Joint
549
550
  * - Base class for Box2D joints
550
551
  * - A joint is used to connect objects together
552
+ * @memberof Box2D
551
553
  */
552
554
  class Box2dJoint
553
555
  {
@@ -603,6 +605,7 @@ class Box2dJoint
603
605
  * - This a soft constraint with a max force
604
606
  * - This allows the constraint to stretch and without applying huge forces
605
607
  * @extends Box2dJoint
608
+ * @memberof Box2D
606
609
  */
607
610
  class Box2dTargetJoint extends Box2dJoint
608
611
  {
@@ -652,6 +655,7 @@ class Box2dTargetJoint extends Box2dJoint
652
655
  * - Constrains two points on two objects to remain at a fixed distance
653
656
  * - You can view this as a massless, rigid rod
654
657
  * @extends Box2dJoint
658
+ * @memberof Box2D
655
659
  */
656
660
  class Box2dDistanceJoint extends Box2dJoint
657
661
  {
@@ -715,6 +719,7 @@ class Box2dDistanceJoint extends Box2dJoint
715
719
  * Box2D Pin Joint
716
720
  * - Pins two objects together at a point
717
721
  * @extends Box2dDistanceJoint
722
+ * @memberof Box2D
718
723
  */
719
724
  class Box2dPinJoint extends Box2dDistanceJoint
720
725
  {
@@ -734,6 +739,7 @@ class Box2dPinJoint extends Box2dDistanceJoint
734
739
  * Box2D Rope Joint
735
740
  * - Enforces a maximum distance between two points on two objects
736
741
  * @extends Box2dJoint
742
+ * @memberof Box2D
737
743
  */
738
744
  class Box2dRopeJoint extends Box2dJoint
739
745
  {
@@ -786,6 +792,7 @@ class Box2dRopeJoint extends Box2dJoint
786
792
  * - You can use a motor to drive the relative rotation about the shared point
787
793
  * - A maximum motor torque is provided so that infinite forces are not generated
788
794
  * @extends Box2dJoint
795
+ * @memberof Box2D
789
796
  */
790
797
  class Box2dRevoluteJoint extends Box2dJoint
791
798
  {
@@ -887,6 +894,7 @@ class Box2dRevoluteJoint extends Box2dJoint
887
894
  * - Either joint can be a revolute or prismatic joint
888
895
  * - You specify a gear ratio to bind the motions together
889
896
  * @extends Box2dJoint
897
+ * @memberof Box2D
890
898
  */
891
899
  class Box2dGearJoint extends Box2dJoint
892
900
  {
@@ -935,6 +943,7 @@ class Box2dGearJoint extends Box2dJoint
935
943
  * - You can use a joint limit to restrict the range of motion
936
944
  * - You can use a joint motor to drive the motion or to model joint friction
937
945
  * @extends Box2dJoint
946
+ * @memberof Box2D
938
947
  */
939
948
  class Box2dPrismaticJoint extends Box2dJoint
940
949
  {
@@ -1044,6 +1053,7 @@ class Box2dPrismaticJoint extends Box2dJoint
1044
1053
  * - You can use a joint motor to drive the motion or to model joint friction
1045
1054
  * - This joint is designed for vehicle suspensions
1046
1055
  * @extends Box2dJoint
1056
+ * @memberof Box2D
1047
1057
  */
1048
1058
  class Box2dWheelJoint extends Box2dJoint
1049
1059
  {
@@ -1139,6 +1149,7 @@ class Box2dWheelJoint extends Box2dJoint
1139
1149
  * Box2D Weld Joint
1140
1150
  * - Glues two objects together
1141
1151
  * @extends Box2dJoint
1152
+ * @memberof Box2D
1142
1153
  */
1143
1154
  class Box2dWeldJoint extends Box2dJoint
1144
1155
  {
@@ -1197,6 +1208,7 @@ class Box2dWeldJoint extends Box2dJoint
1197
1208
  * - Used to apply top-down friction
1198
1209
  * - Provides 2D translational friction and angular friction
1199
1210
  * @extends Box2dJoint
1211
+ * @memberof Box2D
1200
1212
  */
1201
1213
  class Box2dFrictionJoint extends Box2dJoint
1202
1214
  {
@@ -1251,6 +1263,7 @@ class Box2dFrictionJoint extends Box2dJoint
1251
1263
  * - The pulley supports a ratio such that: length1 + ratio * length2 <= constant
1252
1264
  * - The force transmitted is scaled by the ratio
1253
1265
  * @extends Box2dJoint
1266
+ * @memberof Box2D
1254
1267
  */
1255
1268
  class Box2dPulleyJoint extends Box2dJoint
1256
1269
  {
@@ -1318,6 +1331,7 @@ class Box2dPulleyJoint extends Box2dJoint
1318
1331
  * - Controls the relative motion between two objects
1319
1332
  * - Typical usage is to control the movement of a object with respect to the ground
1320
1333
  * @extends Box2dJoint
1334
+ * @memberof Box2D
1321
1335
  */
1322
1336
  class Box2dMotorJoint extends Box2dJoint
1323
1337
  {
@@ -1381,6 +1395,7 @@ class Box2dMotorJoint extends Box2dJoint
1381
1395
  /**
1382
1396
  * Box2D Global Object
1383
1397
  * - Wraps Box2d world and provides global functions
1398
+ * @memberof Box2D
1384
1399
  */
1385
1400
  class Box2dPlugin
1386
1401
  {
@@ -1,24 +1,25 @@
1
1
  /**
2
- * LittleJS Newgrounds API
2
+ * LittleJS Newgrounds Plugin
3
3
  * - NewgroundsMedal extends Medal with Newgrounds API functionality
4
- * - Call new NewgroundsPlugin() to setup Newgrounds
4
+ * - Call new NewgroundsPlugin(app_id) to setup Newgrounds
5
5
  * - Uses CryptoJS for encryption if optional cipher is provided
6
+ * - provides functions to interact with medals scoreboards
6
7
  * - Keeps connection alive and logs views
7
- * - Functions to interact with scoreboards
8
- * - Functions to unlock medals
8
+ * @namespace Newgrounds
9
9
  */
10
10
 
11
11
  'use strict';
12
12
 
13
13
  /** Global Newgrounds object
14
14
  * @type {NewgroundsPlugin}
15
- * @memberof Medal */
15
+ * @memberof Newgrounds */
16
16
  let newgrounds;
17
17
 
18
18
  ///////////////////////////////////////////////////////////////////////////////
19
19
  /**
20
20
  * Newgrounds medal auto unlocks in newgrounds API
21
21
  * @extends Medal
22
+ * @memberof Newgrounds
22
23
  */
23
24
  class NewgroundsMedal extends Medal
24
25
  {
@@ -43,6 +44,7 @@ class NewgroundsMedal extends Medal
43
44
  ///////////////////////////////////////////////////////////////////////////////
44
45
  /**
45
46
  * Newgrounds API object
47
+ * @memberof Newgrounds
46
48
  */
47
49
  class NewgroundsPlugin
48
50
  {
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * LittleJS Post Processing Plugin
3
3
  * - Supports shadertoy style post processing shaders
4
- * - call new new PostProcessPlugin() to setup post processing
4
+ * - call new PostProcessPlugin() to setup post processing
5
5
  * - can be enabled to pass other canvases through a final shader
6
+ * @namespace PostProcess
6
7
  */
7
8
 
8
9
  'use strict';
@@ -10,92 +11,111 @@
10
11
  ///////////////////////////////////////////////////////////////////////////////
11
12
 
12
13
  /** Global Post Process plugin object
13
- * @type {PostProcessPlugin} */
14
+ * @type {PostProcessPlugin}
15
+ * @memberof PostProcess */
14
16
  let postProcess;
15
17
 
16
18
  /////////////////////////////////////////////////////////////////////////
17
19
  /**
18
20
  * UI System Global Object
21
+ * @memberof PostProcess
19
22
  */
20
23
  class PostProcessPlugin
21
24
  {
22
25
  /** Create global post processing shader
23
26
  * @param {string} shaderCode
24
27
  * @param {boolean} [includeOverlay]
28
+ * @param {boolean} [includeMainCanvas]
25
29
  * @example
26
30
  * // create the post process plugin object
27
31
  * new PostProcessPlugin(shaderCode);
28
32
  */
29
- constructor(shaderCode, includeOverlay=false)
33
+ constructor(shaderCode, includeOverlay=false, includeMainCanvas=true)
30
34
  {
31
35
  ASSERT(!postProcess, 'Post process already initialized');
32
36
  postProcess = this;
33
37
 
34
- if (headlessMode) return;
35
-
36
- if (!glEnable)
37
- {
38
- console.warn('PostProcessPlugin: WebGL not enabled!');
39
- return;
40
- }
41
-
42
38
  if (!shaderCode) // default shader pass through
43
39
  shaderCode = 'void mainImage(out vec4 c,vec2 p){c=texture(iChannel0,p/iResolution.xy);}';
44
40
 
45
41
  /** @property {WebGLProgram} - Shader for post processing */
46
- this.shader = glCreateProgram(
47
- '#version 300 es\n' + // specify GLSL ES version
48
- 'precision highp float;'+ // use highp for better accuracy
49
- 'in vec2 p;'+ // position
50
- 'void main(){'+ // shader entry point
51
- 'gl_Position=vec4(p+p-1.,1,1);'+ // set position
52
- '}' // end of shader
53
- ,
54
- '#version 300 es\n' + // specify GLSL ES version
55
- 'precision highp float;'+ // use highp for better accuracy
56
- 'uniform sampler2D iChannel0;'+ // input texture
57
- 'uniform vec3 iResolution;'+ // size of output texture
58
- 'uniform float iTime;'+ // time
59
- 'out vec4 c;'+ // out color
60
- '\n' + shaderCode + '\n'+ // insert custom shader code
61
- 'void main(){'+ // shader entry point
62
- 'mainImage(c,gl_FragCoord.xy);'+ // call post process function
63
- 'c.a=1.;'+ // always use full alpha
64
- '}' // end of shader
65
- );
42
+ this.shader = undefined;
66
43
 
67
44
  /** @property {WebGLTexture} - Texture for post processing */
68
- this.texture = glCreateTexture();
45
+ this.texture = undefined;
69
46
 
70
- /** @property {boolean} - Should overlay canvas be included in post processing */
71
- this.includeOverlay = includeOverlay;
47
+ // setup the post processing plugin
48
+ initPostProcess();
49
+ engineAddPlugin(undefined, postProcessRender, postProcessContextLost, postProcessContextRestored);
72
50
 
73
- // Render the post processing shader, called automatically by the engine
74
- engineAddPlugin(undefined, postProcessRender);
75
- function postProcessRender()
51
+ function initPostProcess()
76
52
  {
77
53
  if (headlessMode) return;
78
-
79
- // prepare to render post process shader
80
- if (glEnable)
81
- {
82
- glFlush(); // clear out the buffer
83
- mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
84
- }
85
- else
54
+
55
+ if (!glEnable)
86
56
  {
87
- // set the viewport
88
- glContext.viewport(0, 0, glCanvas.width = drawCanvas.width, glCanvas.height = drawCanvas.height);
57
+ console.warn('PostProcessPlugin: WebGL not enabled!');
58
+ return;
89
59
  }
90
60
 
91
- if (postProcess.includeOverlay)
61
+ // create resources
62
+ postProcess.texture = glCreateTexture();
63
+ postProcess.shader = glCreateProgram(
64
+ '#version 300 es\n' + // specify GLSL ES version
65
+ 'precision highp float;'+ // use highp for better accuracy
66
+ 'in vec2 p;'+ // position
67
+ 'void main(){'+ // shader entry point
68
+ 'gl_Position=vec4(p+p-1.,1,1);'+ // set position
69
+ '}' // end of shader
70
+ ,
71
+ '#version 300 es\n' + // specify GLSL ES version
72
+ 'precision highp float;'+ // use highp for better accuracy
73
+ 'uniform sampler2D iChannel0;'+ // input texture
74
+ 'uniform vec3 iResolution;'+ // size of output texture
75
+ 'uniform float iTime;'+ // time
76
+ 'out vec4 c;'+ // out color
77
+ '\n' + shaderCode + '\n'+ // insert custom shader code
78
+ 'void main(){'+ // shader entry point
79
+ 'mainImage(c,gl_FragCoord.xy);'+ // call post process function
80
+ 'c.a=1.;'+ // always use full alpha
81
+ '}' // end of shader
82
+ );
83
+ }
84
+ function postProcessContextLost()
85
+ {
86
+ postProcess.shader = undefined;
87
+ postProcess.texture = undefined;
88
+ LOG('PostProcessPlugin: WebGL context lost');
89
+ }
90
+ function postProcessContextRestored()
91
+ {
92
+ initPostProcess();
93
+ LOG('PostProcessPlugin: WebGL context restored');
94
+ }
95
+ function postProcessRender()
96
+ {
97
+ if (headlessMode) return;
98
+
99
+ if (!glEnable)
100
+ return;
101
+
102
+ // clear out the buffer
103
+ glFlush();
104
+
105
+ if (includeMainCanvas || includeOverlay)
92
106
  {
93
- // copy overlay canvas so it will be included in post processing
94
- mainContext.drawImage(overlayCanvas, 0, 0);
95
- overlayCanvas.width |= 0;
107
+ // copy WebGL to the main canvas
108
+ mainContext.drawImage(glCanvas, 0, 0);
109
+
110
+ if (includeOverlay)
111
+ {
112
+ // copy overlay canvas so it will be included in post processing
113
+ mainContext.drawImage(overlayCanvas, 0, 0);
114
+ overlayCanvas.width |= 0; // clear overlay canvas
115
+ }
96
116
  }
97
117
 
98
- // setup shader program to draw one triangle
118
+ // setup shader program to draw a quad
99
119
  glContext.useProgram(postProcess.shader);
100
120
  glContext.bindBuffer(glContext.ARRAY_BUFFER, glGeometryBuffer);
101
121
  glContext.pixelStorei(glContext.UNPACK_FLIP_Y_WEBGL, 1);
@@ -104,7 +124,10 @@ class PostProcessPlugin
104
124
  // set textures, pass in the 2d canvas and gl canvas in separate texture channels
105
125
  glContext.activeTexture(glContext.TEXTURE0);
106
126
  glContext.bindTexture(glContext.TEXTURE_2D, postProcess.texture);
107
- glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
127
+ if (includeMainCanvas || includeOverlay)
128
+ {
129
+ glContext.texImage2D(glContext.TEXTURE_2D, 0, glContext.RGBA, glContext.RGBA, glContext.UNSIGNED_BYTE, mainCanvas);
130
+ }
108
131
 
109
132
  // set vertex position attribute
110
133
  const vertexByteStride = 8;