Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Aug 12, 2024
1 parent 387b343 commit 4b80394
Show file tree
Hide file tree
Showing 32 changed files with 163 additions and 140 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/Draw.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/EngineObject.html

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Input.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/Particle.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/TextureInfo.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/TileInfo.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/WebGL.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.

89 changes: 47 additions & 42 deletions docs/engine.js.html

Large diffs are not rendered by default.

29 changes: 19 additions & 10 deletions docs/engineAudio.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
'use strict';

/**
* Sound Object - Stores a zzfx sound for later use and can be played positionally
* Sound Object - Stores a sound for later use and can be played positionally
*
* <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
* @example
Expand All @@ -29,7 +29,7 @@
/** 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=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
* @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
*/
constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
{
Expand Down Expand Up @@ -180,7 +180,7 @@
* 1, 0, 9, 1 // channel notes
* ],
* [ // channel 1
* 0, 1, // instrument 1, right speaker
* 0, 1, // instrument 0, right speaker
* 0, 12, 17, -1 // channel notes
* ]
* ],
Expand Down Expand Up @@ -209,24 +209,24 @@

/** Play the music
* @param {Number} [volume=1] - How much to scale volume by
* @param {Boolean} [loop=1] - True if the music should loop
* @param {Boolean} [loop] - True if the music should loop
* @return {AudioBufferSourceNode} - The audio source node
*/
playMusic(volume, loop = false)
playMusic(volume, loop=false)
{ return super.play(undefined, volume, 1, 1, loop); }
}

/** Play an mp3, ogg, or wav audio from a local file or url
* @param {String} url - Location of sound file to play
* @param {String} filename - Location of sound file to play
* @param {Number} [volume] - How much to scale volume by
* @param {Boolean} [loop] - True if the music should loop
* @return {HTMLAudioElement} - The audio element for this sound
* @memberof Audio */
function playAudioFile(url, volume=1, loop=false)
function playAudioFile(filename, volume=1, loop=false)
{
if (!soundEnable) return;

const audio = new Audio(url);
const audio = new Audio(filename);
audio.volume = soundVolume * volume;
audio.loop = loop;
audio.play();
Expand Down Expand Up @@ -278,6 +278,11 @@
* @memberof Audio */
let audioContext = new AudioContext;

/** Keep track if audio was suspended when last sound was played
* @type {Boolean}
* @memberof Audio */
let audioSuspended = false;

/** Play cached audio samples with given settings
* @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
* @param {Number} [volume] - How much to scale volume by
Expand All @@ -292,11 +297,15 @@
if (!soundEnable) return;

// prevent sounds from building up if they can't be played
if (audioContext.state != 'running')
const audioWasSuspended = audioSuspended;
if (audioSuspended = audioContext.state != 'running')
{
// fix stalled audio
audioContext.resume();
return;

// prevent suspended sounds from building up
if (audioWasSuspended)
return;
}

// create buffer and source
Expand Down
6 changes: 5 additions & 1 deletion docs/engineDebug.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
///////////////////////////////////////////////////////////////////////////////
// Debug helper functions

/** Asserts if the experssion is false, does not do anything in release builds
/** Asserts if the expression is false, does not do anything in release builds
* @param {Boolean} assert
* @param {Object} [output]
* @memberof Debug */
Expand Down Expand Up @@ -262,6 +262,10 @@
{
const saveContext = mainContext;
mainContext = overlayContext;

// draw red rectangle around screen
const cameraSize = getCameraSize();
debugRect(cameraPos, cameraSize.subtract(vec2(.1)), '#f008');

// mouse pick
let bestDistance = Infinity, bestObject;
Expand Down
42 changes: 19 additions & 23 deletions docs/engineDraw.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@
if (typeof pos === 'number')
{
const textureInfo = textureInfos[textureIndex];
if (textureInfo)
{
const cols = textureInfo.size.x / size.x |0;
pos = vec2((pos%cols)*size.x, (pos/cols|0)*size.y);
}
else
pos = vec2();
ASSERT(textureInfo, 'Texture not loaded');
const cols = textureInfo.size.x / size.x |0;
pos = vec2((pos%cols)*size.x, (pos/cols|0)*size.y);
}

// return a tile info object
Expand All @@ -120,13 +116,23 @@
this.textureIndex = textureIndex;
}

/** Returns an offset copy of this tile, useful for animation
/** Returns a copy of this tile offset by a vector
* @param {Vector2} offset - Offset to apply in pixels
* @return {TileInfo}
*/
offset(offset)
{ return new TileInfo(this.pos.add(offset), this.size, this.textureIndex); }

/** Returns a copy of this tile offset by a number of animation frames
* @param {Number} frame - Offset to apply in animation frames
* @return {TileInfo}
*/
frame(frame)
{
ASSERT(typeof frame == 'number');
return this.offset(vec2(frame*this.size.x, 0));
}

/** Returns the texture info for this tile
* @return {TextureInfo}
*/
Expand Down Expand Up @@ -182,6 +188,11 @@
);
}

/** Get the camera's visible area in world space
* @return {Vector2}
* @memberof Draw */
function getCameraSize() { return mainCanvasSize.scale(1/cameraScale); }

/** Draw textured tile centered in world space, with color applied if using WebGL
* @param {Vector2} pos - Center of the tile in world space
* @param {Vector2} [size=(1,1)] - Size of the tile in world space
Expand Down Expand Up @@ -272,21 +283,6 @@
drawTile(pos, size, undefined, color, angle, false, undefined, useWebGL, screenSpace, context);
}

/** Draw colored polygon using passed in points
* @param {Array} points - Array of Vector2 points
* @param {Color} [color=(1,1,1,1)]
* @param {Boolean} [screenSpace=false]
* @param {CanvasRenderingContext2D} [context=mainContext]
* @memberof Draw */
function drawPoly(points, color=new Color, screenSpace, context=mainContext)
{
context.fillStyle = color.toString();
context.beginPath();
for (const point of screenSpace ? points : points.map(worldToScreen))
context.lineTo(point.x, point.y);
context.fill();
}

/** Draw colored line between two points
* @param {Vector2} posA
* @param {Vector2} posB
Expand Down
48 changes: 31 additions & 17 deletions docs/engineInput.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,21 @@
///////////////////////////////////////////////////////////////////////////////
// Gamepad input

// gamepad internal variables
const stickData = [];

// gamepads are updated by engine every frame automatically
function gamepadsUpdate()
{
const applyDeadZones = (v)=>
{
const min=.3, max=.8;
const deadZone = (v)=>
v > min ? percent( v, min, max) :
v < -min ? -percent(-v, min, max) : 0;
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
}

// update touch gamepad if enabled
if (touchGamepadEnable && isTouchDevice)
{
Expand All @@ -227,7 +239,16 @@
{
// read virtual analog stick
const sticks = stickData[0] || (stickData[0] = []);
sticks[0] = vec2(touchGamepadStick.x, -touchGamepadStick.y); // flip vertical
sticks[0] = vec2();
if (touchGamepadAnalog)
sticks[0] = applyDeadZones(touchGamepadStick);
else if (touchGamepadStick.lengthSquared() > .3)
{
// convert to 8 way dpad
sticks[0].x = Math.round(touchGamepadStick.x);
sticks[0].y = -Math.round(touchGamepadStick.y);
sticks[0] = sticks[0].clampLength();
}

// read virtual gamepad buttons
const data = inputData[1] || (inputData[1] = []);
Expand All @@ -239,7 +260,12 @@
}
}

if (!gamepadsEnable || !navigator || !navigator.getGamepads || !document.hasFocus() && !debug)
// return if gamepads are disabled or not supported
if (!gamepadsEnable || !navigator || !navigator.getGamepads)
return;

// only poll gamepads when focused or in debug mode
if (!debug && !document.hasFocus())
return;

// poll gamepads
Expand All @@ -253,14 +279,9 @@

if (gamepad)
{
// read clamp dead zone of analog sticks
const deadZone = .3, deadZoneMax = .8, applyDeadZone = (v)=>
v > deadZone ? percent( v, deadZone, deadZoneMax) :
v < -deadZone ? -percent(-v, deadZone, deadZoneMax) : 0;

// read analog sticks
for (let j = 0; j < gamepad.axes.length-1; j+=2)
sticks[j>>1] = vec2(applyDeadZone(gamepad.axes[j]), applyDeadZone(-gamepad.axes[j+1])).clampLength();
sticks[j>>1] = applyDeadZones(vec2(gamepad.axes[j],gamepad.axes[j+1]));

// read buttons
for (let j = gamepad.buttons.length; j--;)
Expand Down Expand Up @@ -359,7 +380,7 @@
touchGamepadStick = vec2();

const touchHandler = ontouchstart;
ontouchstart = ontouchmove = ontouchend = (e)=>
ontouchstart = ontouchmove = ontouchend = (e)=>
{
// clear touch gamepad input
touchGamepadStick = vec2();
Expand Down Expand Up @@ -389,14 +410,7 @@
if (touchPos.distance(stickCenter) < touchGamepadSize)
{
// virtual analog stick
if (touchGamepadAnalog)
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
else
{
// 8 way dpad
const angle = touchPos.subtract(stickCenter).angle();
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
}
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
}
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
{
Expand Down
2 changes: 1 addition & 1 deletion docs/engineMedals.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
}

// build the input object
const input =
const input =
{
'app_id': this.app_id,
'session_id': this.session_id,
Expand Down
4 changes: 2 additions & 2 deletions docs/engineObject.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* - Automatically adds self to object list
* - Will be updated and rendered each frame
* - Renders as a sprite from a tilesheet by default
* - Can have color and addtive color applied
* - Can have color and additive color applied
* - 2D Physics and collision system
* - Sorted by renderOrder
* - Objects can have children attached
Expand Down Expand Up @@ -291,7 +291,7 @@
}

/** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
destroy()
destroy()
{
if (this.destroyed)
return;
Expand Down
21 changes: 11 additions & 10 deletions docs/engineParticles.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,17 @@

// build particle
const particle = new Particle(pos, this.tileInfo, angle, colorStart, colorEnd, particleTime, sizeStart, sizeEnd, this.fadeRate, this.additive, this.trailScale, this.localSpace && this, this.particleDestroyCallback);
particle.velocity = vec2().setAngle(velocityAngle, speed);
particle.fadeRate = this.fadeRate;
particle.damping = this.damping;
particle.angleDamping = this.angleDamping;
particle.elasticity = this.elasticity;
particle.friction = this.friction;
particle.gravityScale = this.gravityScale;
particle.collideTiles = this.collideTiles;
particle.renderOrder = this.renderOrder;
particle.mirror = !!randInt(2);
particle.velocity = vec2().setAngle(velocityAngle, speed);
particle.angleVelocity = angleSpeed;
particle.fadeRate = this.fadeRate;
particle.damping = this.damping;
particle.angleDamping = this.angleDamping;
particle.elasticity = this.elasticity;
particle.friction = this.friction;
particle.gravityScale = this.gravityScale;
particle.collideTiles = this.collideTiles;
particle.renderOrder = this.renderOrder;
particle.mirror = !!randInt(2);

// call particle create callaback
this.particleCreateCallback && this.particleCreateCallback(particle);
Expand Down
6 changes: 3 additions & 3 deletions docs/engineSettings.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
* @type {Number}
* @default
* @memberof Settings */
let tileFixBleedScale = .3;
let tileFixBleedScale = .1;

///////////////////////////////////////////////////////////////////////////////
// Object settings
Expand All @@ -96,7 +96,7 @@
* @memberof Settings */
let enablePhysicsSolver = true;

/** Default object mass for collison calcuations (how heavy objects are)
/** Default object mass for collision calcuations (how heavy objects are)
* @type {Number}
* @default
* @memberof Settings */
Expand Down Expand Up @@ -179,7 +179,7 @@
* @memberof Settings */
let touchGamepadAnalog = true;

/** Size of virutal gamepad for touch devices in pixels
/** Size of virtual gamepad for touch devices in pixels
* @type {Number}
* @default
* @memberof Settings */
Expand Down
Loading

0 comments on commit 4b80394

Please sign in to comment.