Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Nov 2, 2021
1 parent 9e3049e commit 3dbb144
Show file tree
Hide file tree
Showing 59 changed files with 20,682 additions and 2,032 deletions.
28 changes: 16 additions & 12 deletions docs/Audio.html

Large diffs are not rendered by default.

510 changes: 491 additions & 19 deletions docs/Color.html

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions docs/Debug.html

Large diffs are not rendered by default.

433 changes: 316 additions & 117 deletions docs/Draw.html

Large diffs are not rendered by default.

2,338 changes: 2,120 additions & 218 deletions docs/EngineObject.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/Input.html

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/Medal.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/Medals.html

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions docs/Music.html

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions docs/Newgrounds.html

Large diffs are not rendered by default.

3,992 changes: 3,980 additions & 12 deletions docs/Particle.html

Large diffs are not rendered by default.

6,270 changes: 6,235 additions & 35 deletions docs/ParticleEmitter.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/Random.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/Settings.html

Large diffs are not rendered by default.

250 changes: 245 additions & 5 deletions docs/Sound.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/TileCollision.html

Large diffs are not rendered by default.

5,586 changes: 5,048 additions & 538 deletions docs/TileLayer.html

Large diffs are not rendered by default.

480 changes: 476 additions & 4 deletions docs/TileLayerData.html

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions docs/Timer.html

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions docs/Utilities.html

Large diffs are not rendered by default.

298 changes: 269 additions & 29 deletions docs/Vector2.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/WebGL.html

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions docs/engine.js.html

Large diffs are not rendered by default.

95 changes: 52 additions & 43 deletions docs/engineAudio.js.html

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions docs/engineDebug.js.html

Large diffs are not rendered by default.

49 changes: 29 additions & 20 deletions docs/engineDraw.js.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/engineInput.js.html

Large diffs are not rendered by default.

59 changes: 32 additions & 27 deletions docs/engineMedals.js.html

Large diffs are not rendered by default.

83 changes: 52 additions & 31 deletions docs/engineObject.js.html

Large diffs are not rendered by default.

123 changes: 77 additions & 46 deletions docs/engineParticles.js.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/engineSettings.js.html

Large diffs are not rendered by default.

89 changes: 53 additions & 36 deletions docs/engineTileLayer.js.html

Large diffs are not rendered by default.

96 changes: 58 additions & 38 deletions docs/engineUtilities.js.html

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions docs/engineWebGL.js.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions docs/global.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


.prettyprint.source,
.prettyprint code {
background-color: #f00;
}
10 changes: 7 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


.prettyprint.source,
.prettyprint code { background-color: #f00;}
552 changes: 318 additions & 234 deletions engine/engine.all.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine/engine.all.min.js

Large diffs are not rendered by default.

542 changes: 313 additions & 229 deletions engine/engine.all.release.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion engine/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const engineName = 'LittleJS';

/** Version of engine */
const engineVersion = '1.1.4';
const engineVersion = '1.1.5';

/** Frames per second to update objects
* @default */
Expand Down
87 changes: 46 additions & 41 deletions engine/engineAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@

'use strict';

/** Sound Object - Stores a zzfx sound for later use and can be played positionally */
/**
* Sound Object - Stores a zzfx sound for later use and can be played positionally
* @example
* // create a sound
* const sound_example = new Sound([.5,.5]);
*
* // play the sound
* sound_example.play();
*/
class Sound
{
/**
* Create a sound object and cache the zzfx samples for later use
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
* @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
* @example
* // create a sound
* const sound_example = new Sound([.5,.5]);
*
* // play the sound
* sound_example.play();
/** Create a sound object and cache the zzfx samples for later use
* @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
* @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
*/
constructor(zzfxSound, range=defaultSoundRange, taper=defaultSoundTaper)
{
if (!soundEnable) return;

/** @property {Number} - World space max range of sound, will not play if camera is farther away */
this.range = range;

/** @property {Number} - At what percentage of range should it start tapering off */
this.taper = taper;

// get randomness from sound parameters
Expand Down Expand Up @@ -89,37 +93,38 @@ class Sound
}
}

/** Music Object - Stores a zzfx music track for later use */
/**
* Music Object - Stores a zzfx music track for later use
* @example
* // create some music
* const music_example = new Music(
* [
* [ // instruments
* [,0,400] // simple note
* ],
* [ // patterns
* [ // pattern 1
* [ // channel 0
* 0, -1, // instrument 0, left speaker
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
* ],
* [0, 0, 0, 0], // sequence, play pattern 0 four times
* 90 // BPM
* ]);
*
* // play the music
* music_example.play();
*/
class Music
{
/**
* Create a music object and cache the zzfx music samples for later use
* @param {Array} zzfxMusic - Array of zzfx music parameters
* @example
* // create some music
* const music_example = new Music(
* [
* [ // instruments
* [,0,400] // simple note
* ],
* [ // patterns
* [ // pattern 1
* [ // channel 0
* 0, -1, // instrument 0, left speaker
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
* ],
* [0, 0, 0, 0], // sequence, play pattern 0 four times
* 90 // BPM
* ]);
*
* // play the music
* music_example.play();
/** Create a music object and cache the zzfx music samples for later use
* @param {Array} zzfxMusic - Array of zzfx music parameters
*/
constructor(zzfxMusic)
{
Expand Down
10 changes: 5 additions & 5 deletions engine/engineDebug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* LittleJS Medal System
* LittleJS Debug System
* <br> - Debug overlay with mouse pick
* <br> - Debug primitive rendering
* <br> - Save screenshots to disk
Expand Down Expand Up @@ -270,12 +270,12 @@ const debugRender = ()=>
const printVec2 = (v)=> '(' + (v.x>0?' ':'') + (v.x).toFixed(2) + ',' + (v.y>0?' ':'') + (v.y).toFixed(2) + ')';
const args = [.5, new Color, .05, undefined, undefined, 'monospace'];

drawText('pos = ' + printVec2(bestObject.pos)
drawOverlayText('pos = ' + printVec2(bestObject.pos)
+ (bestObject.angle>0?' ':' ') + (bestObject.angle*180/PI).toFixed(1) + '°',
pos = pos.add(height), ...args);
drawText('vel = ' + printVec2(bestObject.velocity), pos = pos.add(height), ...args);
drawText('size = ' + printVec2(bestObject.size), pos = pos.add(height), ...args);
drawText('collision = ' + getTileCollisionData(mousePos), pos = mousePos.subtract(height), ...args);
drawOverlayText('vel = ' + printVec2(bestObject.velocity), pos = pos.add(height), ...args);
drawOverlayText('size = ' + printVec2(bestObject.size), pos = pos.add(height), ...args);
drawOverlayText('collision = ' + getTileCollisionData(mousePos), pos = mousePos.subtract(height), ...args);
mainContext = saveContext;
}

Expand Down
41 changes: 23 additions & 18 deletions engine/engineDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ const screenToWorld = (screenPos)=>
const worldToScreen = (worldPos)=>
worldPos.subtract(cameraPos).multiply(vec2(cameraScale,-cameraScale)).add(mainCanvasSize.scale(.5)).subtract(vec2(.5));

/** Draw textured tile centered on pos
/** Draw textured tile centered on pos, with color applied if using WebGL
* @param {Vector2} pos - Center of the tile
* @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
* @param {Vector2} [tileSize=defaultTileSize] - Tile size in source pixels
* @param {Color} [color=new Color(1,1,1)]
* @param {Number} [angle=0]
* @param {Boolean} [mirror=0]
* @param {Color} [additiveColor=new Color(0,0,0,0)]
* @param {Color} [color=new Color(1,1,1)] - Color to modulate with
* @param {Number} [angle=0] - Angle to rotate by
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
* @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color applied
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering if enabled
* @memberof Draw */
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, color=new Color, angle=0, mirror,
additiveColor=new Color(0,0,0,0))
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
{
showWatermark && ++drawCount;
if (glEnable)
if (useWebGL && glEnable)
{
if (tileIndex < 0)
{
Expand Down Expand Up @@ -123,10 +124,11 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
* @param {Vector2} [size=new Vector2(1,1)]
* @param {Color} [color=new Color(1,1,1)]
* @param {Number} [angle=0]
* @param {Boolean} [useWebGL=glEnable]
* @memberof Draw */
function drawRect(pos, size, color, angle)
function drawRect(pos, size, color, angle, useWebGL)
{
drawTile(pos, size, -1, defaultTileSize, color, angle);
drawTile(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
}

/** Draw textured tile centered on pos in screen space
Expand All @@ -138,37 +140,40 @@ function drawRect(pos, size, color, angle)
* @param {Number} [angle=0]
* @param {Boolean} [mirror=0]
* @param {Color} [additiveColor=new Color(0,0,0,0)]
* @param {Boolean} [useWebGL=glEnable]
* @memberof Draw */
function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angle, mirror, additiveColor)
function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angle, mirror, additiveColor, useWebGL)
{
drawTile(screenToWorld(pos), size.scale(1/cameraScale), tileIndex, tileSize, color, angle, mirror, additiveColor);
drawTile(screenToWorld(pos), size.scale(1/cameraScale), tileIndex, tileSize, color, angle, mirror, additiveColor, useWebGL);
}

/** Draw colored untextured rectangle in screen space
* @param {Vector2} pos
* @param {Vector2} [size=new Vector2(1,1)]
* @param {Color} [color=new Color(1,1,1)]
* @param {Number} [angle=0]
* @param {Boolean} [useWebGL=glEnable]
* @memberof Draw */
function drawRectScreenSpace(pos, size, color, angle)
function drawRectScreenSpace(pos, size, color, angle, useWebGL)
{
drawTileScreenSpace(pos, size, -1, defaultTileSize, color, angle);
drawTileSrceenSpace(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
}

/** Draw colored line between two points
* @param {Vector2} posA
* @param {Vector2} posB
* @param {Number} [thickness=.1]
* @param {Color} [color=new Color(1,1,1)]
* @param {Boolean} [useWebGL=glEnable]
* @memberof Draw */
function drawLine(posA, posB, thickness=.1, color)
function drawLine(posA, posB, thickness=.1, color, useWebGL)
{
const halfDelta = vec2((posB.x - posA.x)/2, (posB.y - posA.y)/2);
const size = vec2(thickness, halfDelta.length()*2);
drawRect(posA.add(halfDelta), size, color, halfDelta.angle());
drawRect(posA.add(halfDelta), size, color, halfDelta.angle(), 0, 0, useWebGL);
}

/** Draw directly to a 2d canvas context in world space (bipass webgl)
/** Draw directly to a 2d canvas context in world space
* @param {Vector2} pos
* @param {Vector2} size
* @param {Number} angle
Expand Down Expand Up @@ -198,7 +203,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
* @param {Color} [lineColor=new Color(0,0,0)]
* @param {String} [textAlign='center']
* @memberof Draw */
function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=defaultFont)
function drawOverlayText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=defaultFont)
{
pos = worldToScreen(pos);
overlayContext.font = size*cameraScale + 'px '+ font;
Expand All @@ -214,7 +219,7 @@ function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new
overlayContext.fillText(text, pos.x, pos.y);
}

/** Enable additive or regular blend mode
/** Enable normal or additive blend mode
* @param {Boolean} [additive=0]
* @memberof Draw */
function setBlendMode(additive)
Expand Down
51 changes: 26 additions & 25 deletions engine/engineMedals.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ function medalsInit(saveName)
debugMedals || medals.forEach(medal=> medal.unlocked = localStorage[medal.storageKey()]);
}

/** Medal Object - Tracks an unlockable medal */
/**
* Medal Object - Tracks an unlockable medal
* @example
* // create a medal
* const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
*
* // unlock the medal
* medal_example.unlock();
*/
class Medal
{
/**
* Create an medal object and adds it to the list of medals
* @param {Number} id - The unique identifier of the medal
* @param {String} name - Name of the medal
* @param {String} [description] - Description of the medal
* @param {String} [icon='🏆'] - Icon for the medal
* @param {String} [src] - Image location for the medal
* @example
* // create a medal
* const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
*
* // unlock the medal
* medal_example.unlock();
/** Create an medal object and adds it to the list of medals
* @param {Number} id - The unique identifier of the medal
* @param {String} name - Name of the medal
* @param {String} [description] - Description of the medal
* @param {String} [icon='🏆'] - Icon for the medal
* @param {String} [src] - Image location for the medal
*/
constructor(id, name, description='', icon='🏆', src)
{
Expand Down Expand Up @@ -170,19 +171,19 @@ function medalsRender()

///////////////////////////////////////////////////////////////////////////////

/** Newgrounds API wrapper object */
/**
* Newgrounds API wrapper object
* @example
* // create a newgrounds object, replace the app id and cipher with your own
* const app_id = '53123:1ZuSTQ9l';
* const cipher = 'enF0vGH@Mj/FRASKL23Q==';
* newgrounds = new Newgrounds(app_id, cipher);
*/
class Newgrounds
{
/**
* Create a newgrounds object
* @param {Number} app_id - The newgrounds App ID
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
* @example
* // create a newgrounds object, replace the app id and cipher with your own
* const app_id = '53123:1ZuSTQ9l';
* const cipher = 'enF0vGH@Mj/FRASKL23Q==';
* newgrounds = new Newgrounds(app_id, cipher);
*/
/** Create a newgrounds object
* @param {Number} app_id - The newgrounds App ID
* @param {String} [cipher] - The encryption Key (AES-128/Base64) */
constructor(app_id, cipher)
{
ASSERT(!newgrounds && app_id);
Expand Down
Loading

0 comments on commit 3dbb144

Please sign in to comment.