Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Dec 12, 2024
1 parent 4336f47 commit 003b685
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docs/Audio.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Color.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Debug.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Engine.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Music.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Settings.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Sound.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/SoundWave.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/TileCollision.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/TileLayer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/TileLayerData.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Timer.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Utilities.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Vector2.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data/search.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions docs/engine.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.10.6';
const engineVersion = '1.10.8';

/** Frames per second to update
* @type {Number}
Expand Down Expand Up @@ -124,7 +124,7 @@
mainCanvasSize = vec2(mainCanvas.width, mainCanvas.height);

// disable smoothing for pixel art
mainContext.imageSmoothingEnabled = !canvasPixelated;
mainContext.imageSmoothingEnabled = !tilesPixelated;

// setup gl rendering if enabled
glPreRender();
Expand Down Expand Up @@ -277,6 +277,7 @@
'align-items:center;' + // horizontal center
'justify-content:center;' + // vertical center
'background:#000;' + // set background color
(canvasPixelated ? 'image-rendering:pixelated;' : '') + // pixel art
'user-select:none;' + // prevent hold to select
'-webkit-user-select:none;' + // compatibility for ios
(!touchInputEnable ? '' : // no touch css setttings
Expand Down
15 changes: 9 additions & 6 deletions docs/engineAudio.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@

/** @property {Number} - How much to randomize frequency each time sound plays */
this.randomness = 0;

/** @property {GainNode} - Gain node for this sound */
this.gainNode = audioContext.createGain();

if (zzfxSound)
{
Expand Down Expand Up @@ -114,13 +111,19 @@

// play the sound
const playbackRate = pitch + pitch * this.randomness*randomnessScale*rand(-1,1);
return this.source = playSamples(this.sampleChannels, volume, playbackRate, pan, loop, this.sampleRate, this.gainNode);
this.gainNode = audioContext.createGain();
this.source = playSamples(this.sampleChannels, volume, playbackRate, pan, loop, this.sampleRate, this.gainNode);
return this.source;
}

/** Set the sound volume
/** Set the sound volume of the most recently played instance of this sound
* @param {Number} [volume] - How much to scale volume by
*/
setVolume(volume=1) { this.gainNode.gain.value = volume; }
setVolume(volume=1)
{
if (this.gainNode)
this.gainNode.gain.value = volume;
}

/** Stop the last instance of this sound that was played */
stop()
Expand Down
2 changes: 1 addition & 1 deletion docs/engineDraw.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@
{
const context = this.context;
context.save();
context.imageSmoothingEnabled = !canvasPixelated;
context.imageSmoothingEnabled = !tilesPixelated;

const size = this.tileSize;
const drawSize = size.add(this.paddingSize).scale(scale);
Expand Down
15 changes: 13 additions & 2 deletions docs/engineSettings.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@
* @memberof Settings */
let canvasFixedSize = vec2();

/** Disables filtering for crisper pixel art if true
/** Use nearest neighbor scaling algorithm for canvas for more pixelated look
* @type {Boolean}
* @default
* @memberof Settings */
let canvasPixelated = true;

/** Disables texture filtering for crisper pixel art
* @type {Boolean}
* @default
* @memberof Settings */
let tilesPixelated = true;

/** Default font used for text rendering
* @type {String}
* @default
Expand Down Expand Up @@ -293,11 +299,16 @@
* @memberof Settings */
function setCanvasFixedSize(size) { canvasFixedSize = size; }

/** Disables anti aliasing for pixel art if true
/** Use nearest neighbor scaling algorithm for canvas for more pixelated look
* @param {Boolean} pixelated
* @memberof Settings */
function setCanvasPixelated(pixelated) { canvasPixelated = pixelated; }

/** Disables texture filtering for crisper pixel art
* @param {Boolean} pixelated
* @memberof Settings */
function setTilesPixelated(pixelated) { tilesPixelated = pixelated; }

/** Set default font used for text rendering
* @param {String} font
* @memberof Settings */
Expand Down
15 changes: 8 additions & 7 deletions docs/engineTileLayer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

'use strict';

/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
/** The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access
* @type {Array}
* @memberof TileCollision */
let tileCollision = [];

/** Size of the tile collision layer
/** Size of the tile collision layer 2d grid
* @type {Vector2}
* @memberof TileCollision */
let tileCollisionSize = vec2();

/** Clear and initialize tile collision
* @param {Vector2} size
* @param {Vector2} size - width and height of tile collision 2d grid
* @memberof TileCollision */
function initTileCollision(size)
{
Expand All @@ -35,7 +35,7 @@
tileCollision[i] = 0;
}

/** Set tile collision data
/** Set tile collision data for a given cell in the grid
* @param {Vector2} pos
* @param {Number} [data]
* @memberof TileCollision */
Expand All @@ -44,7 +44,7 @@
pos.arrayCheck(tileCollisionSize) && (tileCollision[(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
}

/** Get tile collision data
/** Get tile collision data for a given cell in the grid
* @param {Vector2} pos
* @return {Number}
* @memberof TileCollision */
Expand Down Expand Up @@ -75,7 +75,8 @@
return false;
}

/** Return the center of first tile hit (does not return the exact intersection)
/** Return the center of first tile hit, undefined if nothing was hit.
* This does not return the exact intersection, but the center of the tile hit.
* @param {Vector2} posStart
* @param {Vector2} posEnd
* @param {EngineObject} [object]
Expand Down Expand Up @@ -283,7 +284,7 @@
}

// disable smoothing for pixel art
this.context.imageSmoothingEnabled = !canvasPixelated;
this.context.imageSmoothingEnabled = !tilesPixelated;

// setup gl rendering if enabled
glPreRender();
Expand Down
66 changes: 57 additions & 9 deletions docs/engineUtilities.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,24 @@
* @param {Number} [y] - Y axis location */
constructor(x=0, y=0)
{
ASSERT(typeof x == 'number' && typeof y == 'number');
/** @property {Number} - X axis location */
this.x = x;
/** @property {Number} - Y axis location */
this.y = y;
ASSERT(this.isValid());
}

/** Sets values of this vector and returns self
* @param {Number} [x] - X axis location
* @param {Number} [y] - Y axis location
* @return {Vector2} */
set(x=0, y=0) { this.x=x; this.y=y; return this; }
set(x=0, y=0)
{
this.x = x;
this.y = y;
ASSERT(this.isValid());
return this;
}

/** Returns a new vector that is a copy of this
* @return {Vector2} */
Expand Down Expand Up @@ -536,6 +542,14 @@
if (debug)
return `(${(this.x<0?'':' ') + this.x.toFixed(digits)},${(this.y<0?'':' ') + this.y.toFixed(digits)} )`;
}

/** Checks if this is a valid vector
* @return {Boolean} */
isValid()
{
return typeof this.x == 'number' && !isNaN(this.x)
&& typeof this.y == 'number' && !isNaN(this.y);
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -596,6 +610,7 @@
this.b = b;
/** @property {Number} - Alpha */
this.a = a;
ASSERT(this.isValid());
}

/** Sets values of this color and returns self
Expand All @@ -605,7 +620,14 @@
* @param {Number} [a] - alpha
* @return {Color} */
set(r=1, g=1, b=1, a=1)
{ this.r=r; this.g=g; this.b=b; this.a=a; return this; }
{
this.r = r;
this.g = g;
this.b = b;
this.a = a;
ASSERT(this.isValid());
return this;
}

/** Returns a new color that is a copy of this
* @return {Color} */
Expand Down Expand Up @@ -688,6 +710,7 @@
this.g = f(p, q, h);
this.b = f(p, q, h - 1/3);
this.a = a;
ASSERT(this.isValid());
return this;
}

Expand Down Expand Up @@ -715,7 +738,6 @@
else if (b == max)
h = (r - g) / d + 4;
}

return [h / 6, s, l, a];
}

Expand Down Expand Up @@ -748,11 +770,27 @@
* @return {Color} */
setHex(hex)
{
const fromHex = (c)=> clamp(parseInt(hex.slice(c,c+2),16)/255);
this.r = fromHex(1);
this.g = fromHex(3),
this.b = fromHex(5);
this.a = hex.length > 7 ? fromHex(7) : 1;
ASSERT(typeof hex == 'string' && hex[0] == '#');
ASSERT([4,5,7,9].includes(hex.length), 'Invalid hex');

if (hex.length < 6)
{
const fromHex = (c)=> clamp(parseInt(hex[c],16)/15);
this.r = fromHex(1);
this.g = fromHex(2),
this.b = fromHex(3);
this.a = hex.length == 5 ? fromHex(4) : 1;
}
else
{
const fromHex = (c)=> clamp(parseInt(hex.slice(c,c+2),16)/255);
this.r = fromHex(1);
this.g = fromHex(3),
this.b = fromHex(5);
this.a = hex.length == 9 ? fromHex(7) : 1;
}

ASSERT(this.isValid());
return this;
}

Expand All @@ -766,6 +804,16 @@
const a = clamp(this.a)*255<<24;
return r + g + b + a;
}

/** Checks if this is a valid color
* @return {Boolean} */
isValid()
{
return typeof this.r == 'number' && !isNaN(this.r)
&& typeof this.g == 'number' && !isNaN(this.g)
&& typeof this.b == 'number' && !isNaN(this.b)
&& typeof this.a == 'number' && !isNaN(this.a);
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion docs/engineWebGL.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
}

// use point filtering for pixelated rendering
const filter = canvasPixelated ? gl_NEAREST : gl_LINEAR;
const filter = tilesPixelated ? gl_NEAREST : gl_LINEAR;
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, filter);
glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, filter);
return texture;
Expand Down

0 comments on commit 003b685

Please sign in to comment.