From 003b685c0e3c30f935aeb62bc2650a54584f92ce Mon Sep 17 00:00:00 2001 From: Frank Force Date: Wed, 11 Dec 2024 23:40:25 -0600 Subject: [PATCH] docs --- docs/Audio.html | 2 +- docs/Color.html | 2 +- docs/Debug.html | 2 +- docs/Engine.html | 2 +- docs/Music.html | 2 +- docs/Settings.html | 2 +- docs/Sound.html | 2 +- docs/SoundWave.html | 2 +- docs/TileCollision.html | 2 +- docs/TileLayer.html | 2 +- docs/TileLayerData.html | 2 +- docs/Timer.html | 2 +- docs/Utilities.html | 2 +- docs/Vector2.html | 2 +- docs/data/search.json | 2 +- docs/engine.js.html | 5 +-- docs/engineAudio.js.html | 15 ++++---- docs/engineDraw.js.html | 2 +- docs/engineSettings.js.html | 15 ++++++-- docs/engineTileLayer.js.html | 15 ++++---- docs/engineUtilities.js.html | 66 +++++++++++++++++++++++++++++++----- docs/engineWebGL.js.html | 2 +- 22 files changed, 107 insertions(+), 43 deletions(-) diff --git a/docs/Audio.html b/docs/Audio.html index 716a5dd1..0714a010 100644 --- a/docs/Audio.html +++ b/docs/Audio.html @@ -1,3 +1,3 @@ Namespace: Audio
On this page

Audio

LittleJS Audio System

  • ZzFX Sound Effects - ZzFX Sound Effect Generator
  • ZzFXM Music - ZzFXM Music System
  • Caches sounds and music for fast playback
  • Can attenuate and apply stereo panning to sounds
  • Ability to play mp3, ogg, and wave files
  • Speech synthesis functions

Members

(static) audioContext :AudioContext

Audio context used by the engine

Type:
  • AudioContext

(static) audioGainNode :GainNode

Master gain node for all audio to pass through

Type:
  • GainNode

(static, constant) zzfxR

Sample rate used for all ZzFX sounds

Default Value
  • 44100

Methods

(static) getNoteFrequency(semitoneOffset, rootFrequencyopt) → {Number}

Get frequency of a note on a musical scale

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetNumber

How many semitones away from the root note

rootFrequencyNumber<optional>
220

Frequency at semitone offset 0

Returns:
  • The frequency of the note
Type: 
Number

(static) playAudioFile(filename, volumeopt, loopopt) → {SoundWave}

Play an mp3, ogg, or wav audio from a local file or url

Parameters:
NameTypeAttributesDefaultDescription
filenameString

Location of sound file to play

volumeNumber<optional>
1

How much to scale volume by

loopBoolean<optional>
false

True if the music should loop

Returns:
  • The sound object for this file
Type: 
SoundWave

(static) playSamples(sampleChannels, volumeopt, rateopt, panopt, loopopt, sampleRateopt, gainNodeopt) → {AudioBufferSourceNode}

Play cached audio samples with given settings

Parameters:
NameTypeAttributesDefaultDescription
sampleChannelsArray

Array of arrays of samples to play (for stereo playback)

volumeNumber<optional>
1

How much to scale volume by

rateNumber<optional>
1

The playback rate to use

panNumber<optional>
0

How much to apply stereo panning

loopBoolean<optional>
false

True if the sound should loop when it reaches the end

sampleRateNumber<optional>
44100

Sample rate for the sound

gainNodeGainNode<optional>

Optional gain node for volume control while playing

Returns:
  • The audio node of the sound played
Type: 
AudioBufferSourceNode

(static) speak(text, languageopt, volumeopt, rateopt, pitchopt) → {SpeechSynthesisUtterance}

Speak text with passed in settings

Parameters:
NameTypeAttributesDefaultDescription
textString

The text to speak

languageString<optional>

The language/accent to use (examples: en, it, ru, ja, zh)

volumeNumber<optional>
1

How much to scale volume by

rateNumber<optional>
1

How quickly to speak

pitchNumber<optional>
1

How much to change the pitch by

Returns:
  • The utterance that was spoken
Type: 
SpeechSynthesisUtterance

(static) speakStop()

Stop all queued speech

(static) zzfx(…zzfxSound) → {AudioBufferSourceNode}

Generate and play a ZzFX sound

Create sounds using the ZzFX Sound Designer.

Parameters:
NameTypeAttributesDescription
zzfxSoundArray<repeatable>

Array of ZzFX parameters, ex. [.5,.5]

Returns:
  • The audio node of the sound played
Type: 
AudioBufferSourceNode

(static) zzfxG(volumeopt, randomnessopt, frequencyopt, attackopt, sustainopt, releaseopt, shapeopt, shapeCurveopt, slideopt, deltaSlideopt, pitchJumpopt, pitchJumpTimeopt, repeatTimeopt, noiseopt, modulationopt, bitCrushopt, delayopt, sustainVolumeopt, decayopt, tremoloopt, filteropt) → {Array}

Generate samples for a ZzFX sound

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

Volume scale (percent)

randomnessNumber<optional>
0.05

How much to randomize frequency (percent Hz)

frequencyNumber<optional>
220

Frequency of sound (Hz)

attackNumber<optional>
0

Attack time, how fast sound starts (seconds)

sustainNumber<optional>
0

Sustain time, how long sound holds (seconds)

releaseNumber<optional>
0.1

Release time, how fast sound fades out (seconds)

shapeNumber<optional>
0

Shape of the sound wave

shapeCurveNumber<optional>
1

Squarenes of wave (0=square, 1=normal, 2=pointy)

slideNumber<optional>
0

How much to slide frequency (kHz/s)

deltaSlideNumber<optional>
0

How much to change slide (kHz/s/s)

pitchJumpNumber<optional>
0

Frequency of pitch jump (Hz)

pitchJumpTimeNumber<optional>
0

Time of pitch jump (seconds)

repeatTimeNumber<optional>
0

Resets some parameters periodically (seconds)

noiseNumber<optional>
0

How much random noise to add (percent)

modulationNumber<optional>
0

Frequency of modulation wave, negative flips phase (Hz)

bitCrushNumber<optional>
0

Resamples at a lower frequency in (samples*100)

delayNumber<optional>
0

Overlap sound with itself for reverb and flanger effects (seconds)

sustainVolumeNumber<optional>
1

Volume level for sustain (percent)

decayNumber<optional>
0

Decay time, how long to reach sustain after attack (seconds)

tremoloNumber<optional>
0

Trembling effect, rate controlled by repeat time (precent)

filterNumber<optional>
0

Filter cutoff frequency, positive for HPF, negative for LPF (Hz)

Returns:
  • Array of audio samples
Type: 
Array

(static) zzfxM(instruments, patterns, sequence, BPMopt) → {Array}

Generate samples for a ZzFM song with given parameters

Parameters:
NameTypeAttributesDefaultDescription
instrumentsArray

Array of ZzFX sound paramaters

patternsArray

Array of pattern data

sequenceArray

Array of pattern indexes

BPMNumber<optional>
125

Playback speed of the song in BPM

Returns:
  • Left and right channel sample data
Type: 
Array
\ No newline at end of file +
On this page

Audio

LittleJS Audio System

  • ZzFX Sound Effects - ZzFX Sound Effect Generator
  • ZzFXM Music - ZzFXM Music System
  • Caches sounds and music for fast playback
  • Can attenuate and apply stereo panning to sounds
  • Ability to play mp3, ogg, and wave files
  • Speech synthesis functions

Members

(static) audioContext :AudioContext

Audio context used by the engine

Type:
  • AudioContext

(static) audioGainNode :GainNode

Master gain node for all audio to pass through

Type:
  • GainNode

(static, constant) zzfxR

Sample rate used for all ZzFX sounds

Default Value
  • 44100

Methods

(static) getNoteFrequency(semitoneOffset, rootFrequencyopt) → {Number}

Get frequency of a note on a musical scale

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetNumber

How many semitones away from the root note

rootFrequencyNumber<optional>
220

Frequency at semitone offset 0

Returns:
  • The frequency of the note
Type: 
Number

(static) playAudioFile(filename, volumeopt, loopopt) → {SoundWave}

Play an mp3, ogg, or wav audio from a local file or url

Parameters:
NameTypeAttributesDefaultDescription
filenameString

Location of sound file to play

volumeNumber<optional>
1

How much to scale volume by

loopBoolean<optional>
false

True if the music should loop

Returns:
  • The sound object for this file
Type: 
SoundWave

(static) playSamples(sampleChannels, volumeopt, rateopt, panopt, loopopt, sampleRateopt, gainNodeopt) → {AudioBufferSourceNode}

Play cached audio samples with given settings

Parameters:
NameTypeAttributesDefaultDescription
sampleChannelsArray

Array of arrays of samples to play (for stereo playback)

volumeNumber<optional>
1

How much to scale volume by

rateNumber<optional>
1

The playback rate to use

panNumber<optional>
0

How much to apply stereo panning

loopBoolean<optional>
false

True if the sound should loop when it reaches the end

sampleRateNumber<optional>
44100

Sample rate for the sound

gainNodeGainNode<optional>

Optional gain node for volume control while playing

Returns:
  • The audio node of the sound played
Type: 
AudioBufferSourceNode

(static) speak(text, languageopt, volumeopt, rateopt, pitchopt) → {SpeechSynthesisUtterance}

Speak text with passed in settings

Parameters:
NameTypeAttributesDefaultDescription
textString

The text to speak

languageString<optional>

The language/accent to use (examples: en, it, ru, ja, zh)

volumeNumber<optional>
1

How much to scale volume by

rateNumber<optional>
1

How quickly to speak

pitchNumber<optional>
1

How much to change the pitch by

Returns:
  • The utterance that was spoken
Type: 
SpeechSynthesisUtterance

(static) speakStop()

Stop all queued speech

(static) zzfx(…zzfxSound) → {AudioBufferSourceNode}

Generate and play a ZzFX sound

Create sounds using the ZzFX Sound Designer.

Parameters:
NameTypeAttributesDescription
zzfxSoundArray<repeatable>

Array of ZzFX parameters, ex. [.5,.5]

Returns:
  • The audio node of the sound played
Type: 
AudioBufferSourceNode

(static) zzfxG(volumeopt, randomnessopt, frequencyopt, attackopt, sustainopt, releaseopt, shapeopt, shapeCurveopt, slideopt, deltaSlideopt, pitchJumpopt, pitchJumpTimeopt, repeatTimeopt, noiseopt, modulationopt, bitCrushopt, delayopt, sustainVolumeopt, decayopt, tremoloopt, filteropt) → {Array}

Generate samples for a ZzFX sound

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

Volume scale (percent)

randomnessNumber<optional>
0.05

How much to randomize frequency (percent Hz)

frequencyNumber<optional>
220

Frequency of sound (Hz)

attackNumber<optional>
0

Attack time, how fast sound starts (seconds)

sustainNumber<optional>
0

Sustain time, how long sound holds (seconds)

releaseNumber<optional>
0.1

Release time, how fast sound fades out (seconds)

shapeNumber<optional>
0

Shape of the sound wave

shapeCurveNumber<optional>
1

Squarenes of wave (0=square, 1=normal, 2=pointy)

slideNumber<optional>
0

How much to slide frequency (kHz/s)

deltaSlideNumber<optional>
0

How much to change slide (kHz/s/s)

pitchJumpNumber<optional>
0

Frequency of pitch jump (Hz)

pitchJumpTimeNumber<optional>
0

Time of pitch jump (seconds)

repeatTimeNumber<optional>
0

Resets some parameters periodically (seconds)

noiseNumber<optional>
0

How much random noise to add (percent)

modulationNumber<optional>
0

Frequency of modulation wave, negative flips phase (Hz)

bitCrushNumber<optional>
0

Resamples at a lower frequency in (samples*100)

delayNumber<optional>
0

Overlap sound with itself for reverb and flanger effects (seconds)

sustainVolumeNumber<optional>
1

Volume level for sustain (percent)

decayNumber<optional>
0

Decay time, how long to reach sustain after attack (seconds)

tremoloNumber<optional>
0

Trembling effect, rate controlled by repeat time (precent)

filterNumber<optional>
0

Filter cutoff frequency, positive for HPF, negative for LPF (Hz)

Returns:
  • Array of audio samples
Type: 
Array

(static) zzfxM(instruments, patterns, sequence, BPMopt) → {Array}

Generate samples for a ZzFM song with given parameters

Parameters:
NameTypeAttributesDefaultDescription
instrumentsArray

Array of ZzFX sound paramaters

patternsArray

Array of pattern data

sequenceArray

Array of pattern indexes

BPMNumber<optional>
125

Playback speed of the song in BPM

Returns:
  • Left and right channel sample data
Type: 
Array
\ No newline at end of file diff --git a/docs/Color.html b/docs/Color.html index df69b72b..08201241 100644 --- a/docs/Color.html +++ b/docs/Color.html @@ -1,3 +1,3 @@ Class: Color
On this page

Color

Color object (red, green, blue, alpha) with some helpful functions

Constructor

new Color(ropt, gopt, bopt, aopt)

Create a color with the rgba components passed in, white by default

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Example
let a = new Color;              // white
let b = new Color(1, 0, 0);     // red
let c = new Color(0, 0, 0, 0);  // transparent black
let d = rgb(0, 0, 1);           // blue using rgb color
let e = hsl(.3, 1, .5);         // green using hsl color

Members

a

Properties
TypeDescription
Number

Alpha

b

Properties
TypeDescription
Number

Blue

g

Properties
TypeDescription
Number

Green

r

Properties
TypeDescription
Number

Red

Methods

HSLA() → {Array}

Returns this color expressed in hsla format

Returns:
Type: 
Array

add(c) → {Color}

Returns a copy of this color plus the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

clamp() → {Color}

Returns a copy of this color clamped to the valid range between 0 and 1

Returns:
Type: 
Color

copy() → {Color}

Returns a new color that is a copy of this

Returns:
Type: 
Color

divide(c) → {Color}

Returns a copy of this color divided by the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

lerp(c, percent) → {Color}

Returns a new color that is p percent between this and the color passed in

Parameters:
NameTypeDescription
cColor

other color

percentNumber
Returns:
Type: 
Color

multiply(c) → {Color}

Returns a copy of this color times the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

mutate(amountopt, alphaAmountopt) → {Color}

Returns a new color that has each component randomly adjusted

Parameters:
NameTypeAttributesDefaultDescription
amountNumber<optional>
0.05
alphaAmountNumber<optional>
0
Returns:
Type: 
Color

rgbaInt() → {Number}

Returns this color expressed as 32 bit RGBA value

Returns:
Type: 
Number

scale(scale, alphaScaleopt) → {Color}

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately

Parameters:
NameTypeAttributesDefaultDescription
scaleNumber
alphaScaleNumber<optional>
scale
Returns:
Type: 
Color

set(ropt, gopt, bopt, aopt) → {Color}

Sets values of this color and returns self

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Returns:
Type: 
Color

setHSLA(hopt, sopt, lopt, aopt) → {Color}

Sets this color given a hue, saturation, lightness, and alpha

Parameters:
NameTypeAttributesDefaultDescription
hNumber<optional>
0

hue

sNumber<optional>
0

saturation

lNumber<optional>
1

lightness

aNumber<optional>
1

alpha

Returns:
Type: 
Color

setHex(hex) → {Color}

Set this color from a hex code

Parameters:
NameTypeDescription
hexString

html hex code

Returns:
Type: 
Color

subtract(c) → {Color}

Returns a copy of this color minus the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

toString(useAlphaopt) → {String}

Returns this color expressed as a hex color code

Parameters:
NameTypeAttributesDefaultDescription
useAlphaBoolean<optional>
true

if alpha should be included in result

Returns:
Type: 
String
\ No newline at end of file +
On this page

Color

Color object (red, green, blue, alpha) with some helpful functions

Constructor

new Color(ropt, gopt, bopt, aopt)

Create a color with the rgba components passed in, white by default

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Example
let a = new Color;              // white
let b = new Color(1, 0, 0);     // red
let c = new Color(0, 0, 0, 0);  // transparent black
let d = rgb(0, 0, 1);           // blue using rgb color
let e = hsl(.3, 1, .5);         // green using hsl color

Members

a

Properties
TypeDescription
Number

Alpha

b

Properties
TypeDescription
Number

Blue

g

Properties
TypeDescription
Number

Green

r

Properties
TypeDescription
Number

Red

Methods

HSLA() → {Array}

Returns this color expressed in hsla format

Returns:
Type: 
Array

add(c) → {Color}

Returns a copy of this color plus the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

clamp() → {Color}

Returns a copy of this color clamped to the valid range between 0 and 1

Returns:
Type: 
Color

copy() → {Color}

Returns a new color that is a copy of this

Returns:
Type: 
Color

divide(c) → {Color}

Returns a copy of this color divided by the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

isValid() → {Boolean}

Checks if this is a valid color

Returns:
Type: 
Boolean

lerp(c, percent) → {Color}

Returns a new color that is p percent between this and the color passed in

Parameters:
NameTypeDescription
cColor

other color

percentNumber
Returns:
Type: 
Color

multiply(c) → {Color}

Returns a copy of this color times the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

mutate(amountopt, alphaAmountopt) → {Color}

Returns a new color that has each component randomly adjusted

Parameters:
NameTypeAttributesDefaultDescription
amountNumber<optional>
0.05
alphaAmountNumber<optional>
0
Returns:
Type: 
Color

rgbaInt() → {Number}

Returns this color expressed as 32 bit RGBA value

Returns:
Type: 
Number

scale(scale, alphaScaleopt) → {Color}

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately

Parameters:
NameTypeAttributesDefaultDescription
scaleNumber
alphaScaleNumber<optional>
scale
Returns:
Type: 
Color

set(ropt, gopt, bopt, aopt) → {Color}

Sets values of this color and returns self

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Returns:
Type: 
Color

setHSLA(hopt, sopt, lopt, aopt) → {Color}

Sets this color given a hue, saturation, lightness, and alpha

Parameters:
NameTypeAttributesDefaultDescription
hNumber<optional>
0

hue

sNumber<optional>
0

saturation

lNumber<optional>
1

lightness

aNumber<optional>
1

alpha

Returns:
Type: 
Color

setHex(hex) → {Color}

Set this color from a hex code

Parameters:
NameTypeDescription
hexString

html hex code

Returns:
Type: 
Color

subtract(c) → {Color}

Returns a copy of this color minus the color passed in

Parameters:
NameTypeDescription
cColor

other color

Returns:
Type: 
Color

toString(useAlphaopt) → {String}

Returns this color expressed as a hex color code

Parameters:
NameTypeAttributesDefaultDescription
useAlphaBoolean<optional>
true

if alpha should be included in result

Returns:
Type: 
String
\ No newline at end of file diff --git a/docs/Debug.html b/docs/Debug.html index 6e1b85fc..f30c0ea8 100644 --- a/docs/Debug.html +++ b/docs/Debug.html @@ -1,3 +1,3 @@ Namespace: Debug
On this page

Debug

LittleJS Debug System

  • Press Esc to show debug overlay with mouse pick
  • Number keys toggle debug functions
  • +/- apply time scale
  • Debug primitive rendering
  • Save a 2d canvas as a png image

Members

(static, constant) debug :Boolean

True if debug is enabled

Type:
  • Boolean
Default Value
  • true

(static) debugKey :String

Key code used to toggle debug mode, Esc by default

Type:
  • String
Default Value
  • Escape

(static) debugOverlay :Boolean

True if the debug overlay is active, always false in release builds

Type:
  • Boolean

(static, constant) debugPointSize :Number

Size to render debug points by default

Type:
  • Number
Default Value
  • 0.5

(static, constant) enableAsserts :Boolean

True if asserts are enaled

Type:
  • Boolean
Default Value
  • true

(static) showWatermark :Boolean

True if watermark with FPS should be shown, false in release builds

Type:
  • Boolean
Default Value
  • true

Methods

(static) ASSERT(assert, outputopt)

Asserts if the expression is false, does not do anything in release builds

Parameters:
NameTypeAttributesDescription
assertBoolean
outputObject<optional>

(static) debugCircle(pos, radiusopt, coloropt, timeopt, fillopt)

Draw a debug circle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
radiusNumber<optional>
0
colorString<optional>
#fff
timeNumber<optional>
0
fillBoolean<optional>
false

(static) debugClear()

Clear all debug primitives in the list

(static) debugLine(posA, posB, coloropt, thicknessopt, timeopt)

Draw a debug line in world space

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
posBVector2
colorString<optional>
thicknessNumber<optional>
0.1
timeNumber<optional>

(static) debugOverlap(pA, sA, pB, sB, coloropt)

Draw a debug combined axis aligned bounding box in world space

Parameters:
NameTypeAttributesDescription
pAVector2

position A

sAVector2

size A

pBVector2

position B

sBVector2

size B

colorString<optional>

(static) debugPoint(pos, coloropt, timeopt, angleopt)

Draw a debug point in world space

Parameters:
NameTypeAttributesDescription
posVector2
colorString<optional>
timeNumber<optional>
angleNumber<optional>

(static) debugPoly(pos, points, coloropt, timeopt, angleopt, fillopt)

Draw a debug poly in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
pointsArray
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fillBoolean<optional>
false

(static) debugRect(pos, sizeopt, coloropt, timeopt, angleopt, fillopt)

Draw a debug rectangle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
Vector2()
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fillBoolean<optional>
false

(static) debugSaveCanvas(canvas, filenameopt, typeopt)

Save a canvas to disk

Parameters:
NameTypeAttributesDefaultDescription
canvasHTMLCanvasElement
filenameString<optional>
screenshot
typeString<optional>
image/png

(static) debugSaveDataURL(dataURL, filename)

Save a data url to disk

Parameters:
NameTypeDescription
dataURLString
filenameString

(static) debugSaveText(text, filenameopt, typeopt)

Save a text file to disk

Parameters:
NameTypeAttributesDefaultDescription
textString
filenameString<optional>
text
typeString<optional>
text/plain

(static) debugShowErrors()

Show error as full page of red text

(static) debugText(text, pos, sizeopt, coloropt, timeopt, angleopt, fontopt)

Draw a debug axis aligned bounding box in world space

Parameters:
NameTypeAttributesDefaultDescription
textString
posVector2
sizeNumber<optional>
1
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fontString<optional>
monospace

(static) setDebugKey(key)

Set key code used to toggle debug mode, Esc by default

Parameters:
NameTypeDescription
keyString

(static) setShowWatermark(show)

Set if watermark with FPS should be shown

Parameters:
NameTypeDescription
showBoolean
\ No newline at end of file +
On this page

Debug

LittleJS Debug System

  • Press Esc to show debug overlay with mouse pick
  • Number keys toggle debug functions
  • +/- apply time scale
  • Debug primitive rendering
  • Save a 2d canvas as a png image

Members

(static, constant) debug :Boolean

True if debug is enabled

Type:
  • Boolean
Default Value
  • true

(static) debugKey :String

Key code used to toggle debug mode, Esc by default

Type:
  • String
Default Value
  • Escape

(static) debugOverlay :Boolean

True if the debug overlay is active, always false in release builds

Type:
  • Boolean

(static, constant) debugPointSize :Number

Size to render debug points by default

Type:
  • Number
Default Value
  • 0.5

(static, constant) enableAsserts :Boolean

True if asserts are enaled

Type:
  • Boolean
Default Value
  • true

(static) showWatermark :Boolean

True if watermark with FPS should be shown, false in release builds

Type:
  • Boolean
Default Value
  • true

Methods

(static) ASSERT(assert, outputopt)

Asserts if the expression is false, does not do anything in release builds

Parameters:
NameTypeAttributesDescription
assertBoolean
outputObject<optional>

(static) debugCircle(pos, radiusopt, coloropt, timeopt, fillopt)

Draw a debug circle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
radiusNumber<optional>
0
colorString<optional>
#fff
timeNumber<optional>
0
fillBoolean<optional>
false

(static) debugClear()

Clear all debug primitives in the list

(static) debugLine(posA, posB, coloropt, thicknessopt, timeopt)

Draw a debug line in world space

Parameters:
NameTypeAttributesDefaultDescription
posAVector2
posBVector2
colorString<optional>
thicknessNumber<optional>
0.1
timeNumber<optional>

(static) debugOverlap(pA, sA, pB, sB, coloropt)

Draw a debug combined axis aligned bounding box in world space

Parameters:
NameTypeAttributesDescription
pAVector2

position A

sAVector2

size A

pBVector2

position B

sBVector2

size B

colorString<optional>

(static) debugPoint(pos, coloropt, timeopt, angleopt)

Draw a debug point in world space

Parameters:
NameTypeAttributesDescription
posVector2
colorString<optional>
timeNumber<optional>
angleNumber<optional>

(static) debugPoly(pos, points, coloropt, timeopt, angleopt, fillopt)

Draw a debug poly in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
pointsArray
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fillBoolean<optional>
false

(static) debugRect(pos, sizeopt, coloropt, timeopt, angleopt, fillopt)

Draw a debug rectangle in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
Vector2()
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fillBoolean<optional>
false

(static) debugSaveCanvas(canvas, filenameopt, typeopt)

Save a canvas to disk

Parameters:
NameTypeAttributesDefaultDescription
canvasHTMLCanvasElement
filenameString<optional>
screenshot
typeString<optional>
image/png

(static) debugSaveDataURL(dataURL, filename)

Save a data url to disk

Parameters:
NameTypeDescription
dataURLString
filenameString

(static) debugSaveText(text, filenameopt, typeopt)

Save a text file to disk

Parameters:
NameTypeAttributesDefaultDescription
textString
filenameString<optional>
text
typeString<optional>
text/plain

(static) debugShowErrors()

Show error as full page of red text

(static) debugText(text, pos, sizeopt, coloropt, timeopt, angleopt, fontopt)

Draw a debug axis aligned bounding box in world space

Parameters:
NameTypeAttributesDefaultDescription
textString
posVector2
sizeNumber<optional>
1
colorString<optional>
#fff
timeNumber<optional>
0
angleNumber<optional>
0
fontString<optional>
monospace

(static) setDebugKey(key)

Set key code used to toggle debug mode, Esc by default

Parameters:
NameTypeDescription
keyString

(static) setShowWatermark(show)

Set if watermark with FPS should be shown

Parameters:
NameTypeDescription
showBoolean
\ No newline at end of file diff --git a/docs/Engine.html b/docs/Engine.html index 83815394..abf07969 100644 --- a/docs/Engine.html +++ b/docs/Engine.html @@ -1,3 +1,3 @@ Namespace: Engine
On this page

Engine

LittleJS - The Tiny Fast JavaScript Game Engine MIT License - Copyright 2021 Frank Force

Engine Features

  • Object oriented system with base class engine object
  • Base class object handles update, physics, collision, rendering, etc
  • Engine helper classes and functions like Vector2, Color, and Timer
  • Super fast rendering system for tile sheets
  • Sound effects audio with zzfx and music with zzfxm
  • Input processing system with gamepad and touchscreen support
  • Tile layer rendering and collision system
  • Particle effect system
  • Medal system tracks and displays achievements
  • Debug tools and debug rendering system
  • Post processing effects
  • Call engineInit() to start it up!

Members

(static, constant) engineName :String

Name of engine

Type:
  • String
Default Value
  • LittleJS

(static) engineObjects :Array

Array containing all engine objects

Type:
  • Array

(static) engineObjectsCollide :Array

Array with only objects set to collide with other objects this frame (for optimization)

Type:
  • Array

(static, constant) engineVersion :String

Version of engine

Type:
  • String
Default Value
  • 1.10.6

(static) frame :Number

Current update frame, used to calculate time

Type:
  • Number

(static, constant) frameRate :Number

Frames per second to update

Type:
  • Number
Default Value
  • 60

(static) paused :Boolean

Is the game paused? Causes time and objects to not be updated

Type:
  • Boolean
Default Value
  • false

(static) time :Number

Current engine time since start in seconds

Type:
  • Number

(static, constant) timeDelta :Number

How many seconds each frame lasts, engine uses a fixed time step

Type:
  • Number
Default Value
  • 1/60

(static) timeReal :Number

Actual clock time since start in seconds (not affected by pause or frame rate clamping)

Type:
  • Number

Methods

(static) engineAddPlugin(updateFunctionopt, renderFunctionopt)

Add a new update function for a plugin

Parameters:
NameTypeAttributesDescription
updateFunctionfunction<optional>
renderFunctionfunction<optional>

(static) engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSourcesopt, rootElementopt)

Startup LittleJS engine with your callback functions

Parameters:
NameTypeAttributesDefaultDescription
gameInitfunction | function

Called once after the engine starts up

gameUpdatefunction

Called every frame before objects are updated

gameUpdatePostfunction

Called after physics and objects are updated, even when paused

gameRenderfunction

Called before objects are rendered, for drawing the background

gameRenderPostfunction

Called after objects are rendered, useful for drawing UI

imageSourcesArray<optional>
[]

List of images to load

rootElementHTMLElement<optional>

Root element to attach to, the document body by default

(static) engineObjectsCallback(posopt, sizeopt, callbackFunctionopt, objectsopt)

Triggers a callback for each object within a given area

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

Center of test area, or undefined for all objects

sizeNumber | Vector2<optional>

Radius of circle if float, rectangle size if Vector2

callbackFunctionfunction<optional>

Calls this function on every object that passes the test

objectsArray<optional>
engineObjects

List of objects to check

(static) engineObjectsCollect(posopt, sizeopt, objectsopt) → {Array}

Collects all object within a given area

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

Center of test area, or undefined for all objects

sizeNumber | Vector2<optional>

Radius of circle if float, rectangle size if Vector2

objectsArray<optional>
engineObjects

List of objects to check

Returns:
  • List of collected objects
Type: 
Array

(static) engineObjectsDestroy()

Destroy and remove all objects

(static) engineObjectsRaycast(start, end, objectsopt) → {Array}

Return a list of objects intersecting a ray

Parameters:
NameTypeAttributesDefaultDescription
startVector2
endVector2
objectsArray<optional>
engineObjects

List of objects to check

Returns:
  • List of objects hit
Type: 
Array

(static) engineObjectsUpdate()

Update each engine object, remove destroyed objects, and update time

(static) setPaused(isPaused)

Set if game is paused

Parameters:
NameTypeDescription
isPausedBoolean
\ No newline at end of file +
On this page

Engine

LittleJS - The Tiny Fast JavaScript Game Engine MIT License - Copyright 2021 Frank Force

Engine Features

  • Object oriented system with base class engine object
  • Base class object handles update, physics, collision, rendering, etc
  • Engine helper classes and functions like Vector2, Color, and Timer
  • Super fast rendering system for tile sheets
  • Sound effects audio with zzfx and music with zzfxm
  • Input processing system with gamepad and touchscreen support
  • Tile layer rendering and collision system
  • Particle effect system
  • Medal system tracks and displays achievements
  • Debug tools and debug rendering system
  • Post processing effects
  • Call engineInit() to start it up!

Members

(static, constant) engineName :String

Name of engine

Type:
  • String
Default Value
  • LittleJS

(static) engineObjects :Array

Array containing all engine objects

Type:
  • Array

(static) engineObjectsCollide :Array

Array with only objects set to collide with other objects this frame (for optimization)

Type:
  • Array

(static, constant) engineVersion :String

Version of engine

Type:
  • String
Default Value
  • 1.10.8

(static) frame :Number

Current update frame, used to calculate time

Type:
  • Number

(static, constant) frameRate :Number

Frames per second to update

Type:
  • Number
Default Value
  • 60

(static) paused :Boolean

Is the game paused? Causes time and objects to not be updated

Type:
  • Boolean
Default Value
  • false

(static) time :Number

Current engine time since start in seconds

Type:
  • Number

(static, constant) timeDelta :Number

How many seconds each frame lasts, engine uses a fixed time step

Type:
  • Number
Default Value
  • 1/60

(static) timeReal :Number

Actual clock time since start in seconds (not affected by pause or frame rate clamping)

Type:
  • Number

Methods

(static) engineAddPlugin(updateFunctionopt, renderFunctionopt)

Add a new update function for a plugin

Parameters:
NameTypeAttributesDescription
updateFunctionfunction<optional>
renderFunctionfunction<optional>

(static) engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, imageSourcesopt, rootElementopt)

Startup LittleJS engine with your callback functions

Parameters:
NameTypeAttributesDefaultDescription
gameInitfunction | function

Called once after the engine starts up

gameUpdatefunction

Called every frame before objects are updated

gameUpdatePostfunction

Called after physics and objects are updated, even when paused

gameRenderfunction

Called before objects are rendered, for drawing the background

gameRenderPostfunction

Called after objects are rendered, useful for drawing UI

imageSourcesArray<optional>
[]

List of images to load

rootElementHTMLElement<optional>

Root element to attach to, the document body by default

(static) engineObjectsCallback(posopt, sizeopt, callbackFunctionopt, objectsopt)

Triggers a callback for each object within a given area

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

Center of test area, or undefined for all objects

sizeNumber | Vector2<optional>

Radius of circle if float, rectangle size if Vector2

callbackFunctionfunction<optional>

Calls this function on every object that passes the test

objectsArray<optional>
engineObjects

List of objects to check

(static) engineObjectsCollect(posopt, sizeopt, objectsopt) → {Array}

Collects all object within a given area

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

Center of test area, or undefined for all objects

sizeNumber | Vector2<optional>

Radius of circle if float, rectangle size if Vector2

objectsArray<optional>
engineObjects

List of objects to check

Returns:
  • List of collected objects
Type: 
Array

(static) engineObjectsDestroy()

Destroy and remove all objects

(static) engineObjectsRaycast(start, end, objectsopt) → {Array}

Return a list of objects intersecting a ray

Parameters:
NameTypeAttributesDefaultDescription
startVector2
endVector2
objectsArray<optional>
engineObjects

List of objects to check

Returns:
  • List of objects hit
Type: 
Array

(static) engineObjectsUpdate()

Update each engine object, remove destroyed objects, and update time

(static) setPaused(isPaused)

Set if game is paused

Parameters:
NameTypeDescription
isPausedBoolean
\ No newline at end of file diff --git a/docs/Music.html b/docs/Music.html index 612f5bc3..07df8750 100644 --- a/docs/Music.html +++ b/docs/Music.html @@ -1,3 +1,3 @@ Class: Music
On this page

Music

Music Object - Stores a zzfx music track for later use

Create music with the ZzFXM tracker.

Constructor

new Music(zzfxMusic)

Create a music object and cache the zzfx music samples for later use

Parameters:
NameTypeDescription
zzfxMusic
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 0, 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();

Methods

playMusic(volumeopt, loopopt) → {AudioBufferSourceNode}

Play the music

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

How much to scale volume by

loopBoolean<optional>
false

True if the music should loop

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode
\ No newline at end of file +
On this page

Music

Music Object - Stores a zzfx music track for later use

Create music with the ZzFXM tracker.

Constructor

new Music(zzfxMusic)

Create a music object and cache the zzfx music samples for later use

Parameters:
NameTypeDescription
zzfxMusic
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 0, 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();

Methods

playMusic(volumeopt, loopopt) → {AudioBufferSourceNode}

Play the music

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

How much to scale volume by

loopBoolean<optional>
false

True if the music should loop

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode
\ No newline at end of file diff --git a/docs/Settings.html b/docs/Settings.html index 9f0503c1..ffaaf58b 100644 --- a/docs/Settings.html +++ b/docs/Settings.html @@ -1,3 +1,3 @@ Namespace: Settings
On this page

Settings

LittleJS Engine Settings

  • All settings for the engine are here

Members

(static) cameraPos :Vector2

Position of camera in world space

Type:
Default Value
  • Vector2()

(static) cameraScale :Number

Scale of camera in world space

Type:
  • Number
Default Value
  • 32

(static) canvasFixedSize :Vector2

Fixed size of the canvas, if enabled canvas size never changes

  • you may also need to set mainCanvasSize if using screen space coords in startup
Type:
Default Value
  • Vector2()

(static) canvasMaxSize :Vector2

The max size of the canvas, centered if window is larger

Type:
Default Value
  • Vector2(1920,1080)

(static) canvasPixelated :Boolean

Disables filtering for crisper pixel art if true

Type:
  • Boolean
Default Value
  • true

(static) enablePhysicsSolver :Boolean

Enable physics solver for collisions between objects

Type:
  • Boolean
Default Value
  • true

(static) fontDefault :String

Default font used for text rendering

Type:
  • String
Default Value
  • arial

(static) gamepadDirectionEmulateStick :Boolean

If true, the dpad input is also routed to the left analog stick (for better accessability)

Type:
  • Boolean
Default Value
  • true

(static) gamepadsEnable :Boolean

Should gamepads be allowed

Type:
  • Boolean
Default Value
  • true

(static) glEnable :Boolean

Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)

Type:
  • Boolean
Default Value
  • true

(static) glOverlay :Boolean

Fixes slow rendering in some browsers by not compositing the WebGL canvas

Type:
  • Boolean
Default Value
  • true

(static) gravity :Number

How much gravity to apply to objects along the Y axis, negative is down

Type:
  • Number

(static) headlessMode :Boolean

Disables all rendering, audio, and input for servers

Type:
  • Boolean

(static) inputWASDEmulateDirection :Boolean

If true the WASD keys are also routed to the direction keys (for better accessability)

Type:
  • Boolean
Default Value
  • true

(static) medalDisplayIconSize :Number

Size of icon in medal display

Type:
  • Number
Default Value
  • 50

(static) medalDisplaySize :Vector2

Size of medal display

Type:
Default Value
  • Vector2(640,80)

(static) medalDisplaySlideTime :Number

How quickly to slide on/off medals in seconds

Type:
  • Number
Default Value
  • 0.5

(static) medalDisplayTime :Number

How long to show medals for in seconds

Type:
  • Number
Default Value
  • 5

(static) medalsPreventUnlock :Boolean

Set to stop medals from being unlockable (like if cheats are enabled)

Type:
  • Boolean

(static) objectDefaultAngleDamping :Number

How much to slow angular velocity each frame (0-1)

Type:
  • Number
Default Value
  • 1

(static) objectDefaultDamping :Number

How much to slow velocity by each frame (0-1)

Type:
  • Number
Default Value
  • 1

(static) objectDefaultElasticity :Number

How much to bounce when a collision occurs (0-1)

Type:
  • Number

(static) objectDefaultFriction :Number

How much to slow when touching (0-1)

Type:
  • Number
Default Value
  • 0.8

(static) objectDefaultMass :Number

Default object mass for collision calcuations (how heavy objects are)

Type:
  • Number
Default Value
  • 1

(static) objectMaxSpeed :Number

Clamp max speed to avoid fast objects missing collisions

Type:
  • Number
Default Value
  • 1

(static) particleEmitRateScale :Number

Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)

Type:
  • Number
Default Value
  • 1

(static) showSplashScreen :Boolean

Enable to show the LittleJS splash screen be shown on startup

Type:
  • Boolean

(static) soundDefaultRange :Number

Default range where sound no longer plays

Type:
  • Number
Default Value
  • 40

(static) soundDefaultTaper :Number

Default range percent to start tapering off sound (0-1)

Type:
  • Number
Default Value
  • 0.7

(static) soundEnable :Boolean

All audio code can be disabled and removed from build

Type:
  • Boolean
Default Value
  • true

(static) soundVolume :Number

Volume scale to apply to all sound, music and speech

Type:
  • Number
Default Value
  • 0.3

(static) tileFixBleedScale :Number

How many pixels smaller to draw tiles to prevent bleeding from neighbors

Type:
  • Number

(static) tileSizeDefault :Vector2

Default size of tiles in pixels

Type:
Default Value
  • Vector2(16,16)

(static) touchGamepadAlpha :Number

Transparency of touch gamepad overlay

Type:
  • Number
Default Value
  • 0.3

(static) touchGamepadAnalog :Boolean

True if touch gamepad should be analog stick or false to use if 8 way dpad

Type:
  • Boolean
Default Value
  • true

(static) touchGamepadEnable :Boolean

True if touch gamepad should appear on mobile devices

  • Supports left analog stick, 4 face buttons and start button (button 9)
  • Must be set by end of gameInit to be activated
Type:
  • Boolean

(static) touchGamepadSize :Number

Size of virtual gamepad for touch devices in pixels

Type:
  • Number
Default Value
  • 99

(static) touchInputEnable :Boolean

True if touch input is enabled for mobile devices

  • Touch events will be routed to mouse events
Type:
  • Boolean
Default Value
  • true

(static) vibrateEnable :Boolean

Allow vibration hardware if it exists

Type:
  • Boolean
Default Value
  • true

Methods

(static) setCameraPos(pos)

Set position of camera in world space

Parameters:
NameTypeDescription
posVector2

(static) setCameraScale(scale)

Set scale of camera in world space

Parameters:
NameTypeDescription
scaleNumber

(static) setCanvasFixedSize(size)

Set fixed size of the canvas

Parameters:
NameTypeDescription
sizeVector2

(static) setCanvasMaxSize(size)

Set max size of the canvas

Parameters:
NameTypeDescription
sizeVector2

(static) setCanvasPixelated(pixelated)

Disables anti aliasing for pixel art if true

Parameters:
NameTypeDescription
pixelatedBoolean

(static) setEnablePhysicsSolver(enable)

Set if collisions between objects are enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setFontDefault(font)

Set default font used for text rendering

Parameters:
NameTypeDescription
fontString

(static) setGamepadDirectionEmulateStick(enable)

Set if the dpad input is also routed to the left analog stick

Parameters:
NameTypeDescription
enableBoolean

(static) setGamepadsEnable(enable)

Set if gamepads are enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setGlEnable(enable)

Set if webgl rendering is enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setGlOverlay(overlay)

Set to not composite the WebGL canvas

Parameters:
NameTypeDescription
overlayBoolean

(static) setGravity(newGravity)

Set how much gravity to apply to objects along the Y axis

Parameters:
NameTypeDescription
newGravityNumber

(static) setHeadlessMode(headless)

Set to disalbe rendering, audio, and input for servers

Parameters:
NameTypeDescription
headlessBoolean

(static) setInputWASDEmulateDirection(enable)

Set if true the WASD keys are also routed to the direction keys

Parameters:
NameTypeDescription
enableBoolean

(static) setMedalDisplayIconSize(size)

Set size of icon in medal display

Parameters:
NameTypeDescription
sizeNumber

(static) setMedalDisplaySize(size)

Set size of medal display

Parameters:
NameTypeDescription
sizeVector2

(static) setMedalDisplaySlideTime(time)

Set how quickly to slide on/off medals in seconds

Parameters:
NameTypeDescription
timeNumber

(static) setMedalDisplayTime(time)

Set how long to show medals for in seconds

Parameters:
NameTypeDescription
timeNumber

(static) setMedalsPreventUnlock(preventUnlock)

Set to stop medals from being unlockable

Parameters:
NameTypeDescription
preventUnlockBoolean

(static) setObjectDefaultAngleDamping(damp)

Set how much to slow angular velocity each frame

Parameters:
NameTypeDescription
dampNumber

(static) setObjectDefaultDamping(damp)

Set how much to slow velocity by each frame

Parameters:
NameTypeDescription
dampNumber

(static) setObjectDefaultElasticity(elasticity)

Set how much to bounce when a collision occur

Parameters:
NameTypeDescription
elasticityNumber

(static) setObjectDefaultFriction(friction)

Set how much to slow when touching

Parameters:
NameTypeDescription
frictionNumber

(static) setObjectDefaultMass(mass)

Set default object mass for collison calcuations

Parameters:
NameTypeDescription
massNumber

(static) setObjectMaxSpeed(speed)

Set max speed to avoid fast objects missing collisions

Parameters:
NameTypeDescription
speedNumber

(static) setParticleEmitRateScale(scale)

Set to scales emit rate of particles

Parameters:
NameTypeDescription
scaleNumber

(static) setShowSplashScreen(show)

Set if the LittleJS splash screen be shown on startup

Parameters:
NameTypeDescription
showBoolean

(static) setSoundDefaultRange(range)

Set default range where sound no longer plays

Parameters:
NameTypeDescription
rangeNumber

(static) setSoundDefaultTaper(taper)

Set default range percent to start tapering off sound

Parameters:
NameTypeDescription
taperNumber

(static) setSoundEnable(enable)

Set to disable all audio code

Parameters:
NameTypeDescription
enableBoolean

(static) setSoundVolume(volume)

Set volume scale to apply to all sound, music and speech

Parameters:
NameTypeDescription
volumeNumber

(static) setTileFixBleedScale(scale)

Set to prevent tile bleeding from neighbors in pixels

Parameters:
NameTypeDescription
scaleNumber

(static) setTileSizeDefault(size)

Set default size of tiles in pixels

Parameters:
NameTypeDescription
sizeVector2

(static) setTouchGamepadAlpha(alpha)

Set transparency of touch gamepad overlay

Parameters:
NameTypeDescription
alphaNumber

(static) setTouchGamepadAnalog(analog)

Set if touch gamepad should be analog stick or 8 way dpad

Parameters:
NameTypeDescription
analogBoolean

(static) setTouchGamepadEnable(enable)

Set if touch gamepad should appear on mobile devices

Parameters:
NameTypeDescription
enableBoolean

(static) setTouchGamepadSize(size)

Set size of virutal gamepad for touch devices in pixels

Parameters:
NameTypeDescription
sizeNumber

(static) setTouchInputEnable(enable)

Set if touch input is allowed

Parameters:
NameTypeDescription
enableBoolean

(static) setVibrateEnable(enable)

Set to allow vibration hardware if it exists

Parameters:
NameTypeDescription
enableBoolean
\ No newline at end of file +
On this page

Settings

LittleJS Engine Settings

  • All settings for the engine are here

Members

(static) cameraPos :Vector2

Position of camera in world space

Type:
Default Value
  • Vector2()

(static) cameraScale :Number

Scale of camera in world space

Type:
  • Number
Default Value
  • 32

(static) canvasFixedSize :Vector2

Fixed size of the canvas, if enabled canvas size never changes

  • you may also need to set mainCanvasSize if using screen space coords in startup
Type:
Default Value
  • Vector2()

(static) canvasMaxSize :Vector2

The max size of the canvas, centered if window is larger

Type:
Default Value
  • Vector2(1920,1080)

(static) canvasPixelated :Boolean

Use nearest neighbor scaling algorithm for canvas for more pixelated look

Type:
  • Boolean
Default Value
  • true

(static) enablePhysicsSolver :Boolean

Enable physics solver for collisions between objects

Type:
  • Boolean
Default Value
  • true

(static) fontDefault :String

Default font used for text rendering

Type:
  • String
Default Value
  • arial

(static) gamepadDirectionEmulateStick :Boolean

If true, the dpad input is also routed to the left analog stick (for better accessability)

Type:
  • Boolean
Default Value
  • true

(static) gamepadsEnable :Boolean

Should gamepads be allowed

Type:
  • Boolean
Default Value
  • true

(static) glEnable :Boolean

Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)

Type:
  • Boolean
Default Value
  • true

(static) glOverlay :Boolean

Fixes slow rendering in some browsers by not compositing the WebGL canvas

Type:
  • Boolean
Default Value
  • true

(static) gravity :Number

How much gravity to apply to objects along the Y axis, negative is down

Type:
  • Number

(static) headlessMode :Boolean

Disables all rendering, audio, and input for servers

Type:
  • Boolean

(static) inputWASDEmulateDirection :Boolean

If true the WASD keys are also routed to the direction keys (for better accessability)

Type:
  • Boolean
Default Value
  • true

(static) medalDisplayIconSize :Number

Size of icon in medal display

Type:
  • Number
Default Value
  • 50

(static) medalDisplaySize :Vector2

Size of medal display

Type:
Default Value
  • Vector2(640,80)

(static) medalDisplaySlideTime :Number

How quickly to slide on/off medals in seconds

Type:
  • Number
Default Value
  • 0.5

(static) medalDisplayTime :Number

How long to show medals for in seconds

Type:
  • Number
Default Value
  • 5

(static) medalsPreventUnlock :Boolean

Set to stop medals from being unlockable (like if cheats are enabled)

Type:
  • Boolean

(static) objectDefaultAngleDamping :Number

How much to slow angular velocity each frame (0-1)

Type:
  • Number
Default Value
  • 1

(static) objectDefaultDamping :Number

How much to slow velocity by each frame (0-1)

Type:
  • Number
Default Value
  • 1

(static) objectDefaultElasticity :Number

How much to bounce when a collision occurs (0-1)

Type:
  • Number

(static) objectDefaultFriction :Number

How much to slow when touching (0-1)

Type:
  • Number
Default Value
  • 0.8

(static) objectDefaultMass :Number

Default object mass for collision calcuations (how heavy objects are)

Type:
  • Number
Default Value
  • 1

(static) objectMaxSpeed :Number

Clamp max speed to avoid fast objects missing collisions

Type:
  • Number
Default Value
  • 1

(static) particleEmitRateScale :Number

Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)

Type:
  • Number
Default Value
  • 1

(static) showSplashScreen :Boolean

Enable to show the LittleJS splash screen be shown on startup

Type:
  • Boolean

(static) soundDefaultRange :Number

Default range where sound no longer plays

Type:
  • Number
Default Value
  • 40

(static) soundDefaultTaper :Number

Default range percent to start tapering off sound (0-1)

Type:
  • Number
Default Value
  • 0.7

(static) soundEnable :Boolean

All audio code can be disabled and removed from build

Type:
  • Boolean
Default Value
  • true

(static) soundVolume :Number

Volume scale to apply to all sound, music and speech

Type:
  • Number
Default Value
  • 0.3

(static) tileFixBleedScale :Number

How many pixels smaller to draw tiles to prevent bleeding from neighbors

Type:
  • Number

(static) tileSizeDefault :Vector2

Default size of tiles in pixels

Type:
Default Value
  • Vector2(16,16)

(static) tilesPixelated :Boolean

Disables texture filtering for crisper pixel art

Type:
  • Boolean
Default Value
  • true

(static) touchGamepadAlpha :Number

Transparency of touch gamepad overlay

Type:
  • Number
Default Value
  • 0.3

(static) touchGamepadAnalog :Boolean

True if touch gamepad should be analog stick or false to use if 8 way dpad

Type:
  • Boolean
Default Value
  • true

(static) touchGamepadEnable :Boolean

True if touch gamepad should appear on mobile devices

  • Supports left analog stick, 4 face buttons and start button (button 9)
  • Must be set by end of gameInit to be activated
Type:
  • Boolean

(static) touchGamepadSize :Number

Size of virtual gamepad for touch devices in pixels

Type:
  • Number
Default Value
  • 99

(static) touchInputEnable :Boolean

True if touch input is enabled for mobile devices

  • Touch events will be routed to mouse events
Type:
  • Boolean
Default Value
  • true

(static) vibrateEnable :Boolean

Allow vibration hardware if it exists

Type:
  • Boolean
Default Value
  • true

Methods

(static) setCameraPos(pos)

Set position of camera in world space

Parameters:
NameTypeDescription
posVector2

(static) setCameraScale(scale)

Set scale of camera in world space

Parameters:
NameTypeDescription
scaleNumber

(static) setCanvasFixedSize(size)

Set fixed size of the canvas

Parameters:
NameTypeDescription
sizeVector2

(static) setCanvasMaxSize(size)

Set max size of the canvas

Parameters:
NameTypeDescription
sizeVector2

(static) setCanvasPixelated(pixelated)

Use nearest neighbor scaling algorithm for canvas for more pixelated look

Parameters:
NameTypeDescription
pixelatedBoolean

(static) setEnablePhysicsSolver(enable)

Set if collisions between objects are enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setFontDefault(font)

Set default font used for text rendering

Parameters:
NameTypeDescription
fontString

(static) setGamepadDirectionEmulateStick(enable)

Set if the dpad input is also routed to the left analog stick

Parameters:
NameTypeDescription
enableBoolean

(static) setGamepadsEnable(enable)

Set if gamepads are enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setGlEnable(enable)

Set if webgl rendering is enabled

Parameters:
NameTypeDescription
enableBoolean

(static) setGlOverlay(overlay)

Set to not composite the WebGL canvas

Parameters:
NameTypeDescription
overlayBoolean

(static) setGravity(newGravity)

Set how much gravity to apply to objects along the Y axis

Parameters:
NameTypeDescription
newGravityNumber

(static) setHeadlessMode(headless)

Set to disalbe rendering, audio, and input for servers

Parameters:
NameTypeDescription
headlessBoolean

(static) setInputWASDEmulateDirection(enable)

Set if true the WASD keys are also routed to the direction keys

Parameters:
NameTypeDescription
enableBoolean

(static) setMedalDisplayIconSize(size)

Set size of icon in medal display

Parameters:
NameTypeDescription
sizeNumber

(static) setMedalDisplaySize(size)

Set size of medal display

Parameters:
NameTypeDescription
sizeVector2

(static) setMedalDisplaySlideTime(time)

Set how quickly to slide on/off medals in seconds

Parameters:
NameTypeDescription
timeNumber

(static) setMedalDisplayTime(time)

Set how long to show medals for in seconds

Parameters:
NameTypeDescription
timeNumber

(static) setMedalsPreventUnlock(preventUnlock)

Set to stop medals from being unlockable

Parameters:
NameTypeDescription
preventUnlockBoolean

(static) setObjectDefaultAngleDamping(damp)

Set how much to slow angular velocity each frame

Parameters:
NameTypeDescription
dampNumber

(static) setObjectDefaultDamping(damp)

Set how much to slow velocity by each frame

Parameters:
NameTypeDescription
dampNumber

(static) setObjectDefaultElasticity(elasticity)

Set how much to bounce when a collision occur

Parameters:
NameTypeDescription
elasticityNumber

(static) setObjectDefaultFriction(friction)

Set how much to slow when touching

Parameters:
NameTypeDescription
frictionNumber

(static) setObjectDefaultMass(mass)

Set default object mass for collison calcuations

Parameters:
NameTypeDescription
massNumber

(static) setObjectMaxSpeed(speed)

Set max speed to avoid fast objects missing collisions

Parameters:
NameTypeDescription
speedNumber

(static) setParticleEmitRateScale(scale)

Set to scales emit rate of particles

Parameters:
NameTypeDescription
scaleNumber

(static) setShowSplashScreen(show)

Set if the LittleJS splash screen be shown on startup

Parameters:
NameTypeDescription
showBoolean

(static) setSoundDefaultRange(range)

Set default range where sound no longer plays

Parameters:
NameTypeDescription
rangeNumber

(static) setSoundDefaultTaper(taper)

Set default range percent to start tapering off sound

Parameters:
NameTypeDescription
taperNumber

(static) setSoundEnable(enable)

Set to disable all audio code

Parameters:
NameTypeDescription
enableBoolean

(static) setSoundVolume(volume)

Set volume scale to apply to all sound, music and speech

Parameters:
NameTypeDescription
volumeNumber

(static) setTileFixBleedScale(scale)

Set to prevent tile bleeding from neighbors in pixels

Parameters:
NameTypeDescription
scaleNumber

(static) setTileSizeDefault(size)

Set default size of tiles in pixels

Parameters:
NameTypeDescription
sizeVector2

(static) setTilesPixelated(pixelated)

Disables texture filtering for crisper pixel art

Parameters:
NameTypeDescription
pixelatedBoolean

(static) setTouchGamepadAlpha(alpha)

Set transparency of touch gamepad overlay

Parameters:
NameTypeDescription
alphaNumber

(static) setTouchGamepadAnalog(analog)

Set if touch gamepad should be analog stick or 8 way dpad

Parameters:
NameTypeDescription
analogBoolean

(static) setTouchGamepadEnable(enable)

Set if touch gamepad should appear on mobile devices

Parameters:
NameTypeDescription
enableBoolean

(static) setTouchGamepadSize(size)

Set size of virutal gamepad for touch devices in pixels

Parameters:
NameTypeDescription
sizeNumber

(static) setTouchInputEnable(enable)

Set if touch input is allowed

Parameters:
NameTypeDescription
enableBoolean

(static) setVibrateEnable(enable)

Set to allow vibration hardware if it exists

Parameters:
NameTypeDescription
enableBoolean
\ No newline at end of file diff --git a/docs/Sound.html b/docs/Sound.html index 3c8de9f1..cfa472c4 100644 --- a/docs/Sound.html +++ b/docs/Sound.html @@ -1,3 +1,3 @@ Class: Sound
On this page

Sound

Sound Object - Stores a sound for later use and can be played positionally

Create sounds using the ZzFX Sound Designer.

Constructor

new Sound(zzfxSound, rangeopt, taperopt)

Create a sound object and cache the zzfx samples for later use

Parameters:
NameTypeAttributesDefaultDescription
zzfxSoundArray

Array of zzfx parameters, ex. [.5,.5]

rangeNumber<optional>
soundDefaultRange

World space max range of sound, will not play if camera is farther away

taperNumber<optional>
soundDefaultTaper

At what percentage of range should it start tapering

Example
// create a sound
const sound_example = new Sound([.5,.5]);

// play the sound
sound_example.play();

Members

gainNode

Properties
TypeDescription
GainNode

Gain node for this sound

randomness

Properties
TypeDescription
Number

How much to randomize frequency each time sound plays

range

Properties
TypeDescription
Number

World space max range of sound, will not play if camera is farther away

taper

Properties
TypeDescription
Number

At what percentage of range should it start tapering off

Methods

getDuration() → {Number}

Get how long this sound is in seconds

Returns:
  • How long the sound is in seconds (undefined if loading)
Type: 
Number

getSource() → {AudioBufferSourceNode}

Get source of most recent instance of this sound that was played

Returns:
Type: 
AudioBufferSourceNode

isLoading() → {Boolean}

Check if sound is loading, for sounds fetched from a url

Returns:
  • True if sound is loading and not ready to play
Type: 
Boolean

play(posopt, volumeopt, pitchopt, randomnessScaleopt, loopopt) → {AudioBufferSourceNode}

Play the sound

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

pitchNumber<optional>
1

How much to scale pitch by (also adjusted by this.randomness)

randomnessScaleNumber<optional>
1

How much to scale randomness

loopBoolean<optional>
false

Should the sound loop

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

playNote(semitoneOffset, posopt, volumeopt) → {AudioBufferSourceNode}

Play the sound as a note with a semitone offset

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetNumber

How many semitones to offset pitch

posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

setVolume(volumeopt)

Set the sound volume

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

How much to scale volume by

stop()

Stop the last instance of this sound that was played

\ No newline at end of file +
On this page

Sound

Sound Object - Stores a sound for later use and can be played positionally

Create sounds using the ZzFX Sound Designer.

Constructor

new Sound(zzfxSound, rangeopt, taperopt)

Create a sound object and cache the zzfx samples for later use

Parameters:
NameTypeAttributesDefaultDescription
zzfxSoundArray

Array of zzfx parameters, ex. [.5,.5]

rangeNumber<optional>
soundDefaultRange

World space max range of sound, will not play if camera is farther away

taperNumber<optional>
soundDefaultTaper

At what percentage of range should it start tapering

Example
// create a sound
const sound_example = new Sound([.5,.5]);

// play the sound
sound_example.play();

Members

randomness

Properties
TypeDescription
Number

How much to randomize frequency each time sound plays

range

Properties
TypeDescription
Number

World space max range of sound, will not play if camera is farther away

taper

Properties
TypeDescription
Number

At what percentage of range should it start tapering off

Methods

getDuration() → {Number}

Get how long this sound is in seconds

Returns:
  • How long the sound is in seconds (undefined if loading)
Type: 
Number

getSource() → {AudioBufferSourceNode}

Get source of most recent instance of this sound that was played

Returns:
Type: 
AudioBufferSourceNode

isLoading() → {Boolean}

Check if sound is loading, for sounds fetched from a url

Returns:
  • True if sound is loading and not ready to play
Type: 
Boolean

play(posopt, volumeopt, pitchopt, randomnessScaleopt, loopopt) → {AudioBufferSourceNode}

Play the sound

Parameters:
NameTypeAttributesDefaultDescription
posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

pitchNumber<optional>
1

How much to scale pitch by (also adjusted by this.randomness)

randomnessScaleNumber<optional>
1

How much to scale randomness

loopBoolean<optional>
false

Should the sound loop

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

playNote(semitoneOffset, posopt, volumeopt) → {AudioBufferSourceNode}

Play the sound as a note with a semitone offset

Parameters:
NameTypeAttributesDefaultDescription
semitoneOffsetNumber

How many semitones to offset pitch

posVector2<optional>

World space position to play the sound, sound is not attenuated if null

volumeNumber<optional>
1

How much to scale volume by (in addition to range fade)

Returns:
  • The audio source node
Type: 
AudioBufferSourceNode

setVolume(volumeopt)

Set the sound volume of the most recently played instance of this sound

Parameters:
NameTypeAttributesDefaultDescription
volumeNumber<optional>
1

How much to scale volume by

stop()

Stop the last instance of this sound that was played

\ No newline at end of file diff --git a/docs/SoundWave.html b/docs/SoundWave.html index d3a441f0..e8ab85b9 100644 --- a/docs/SoundWave.html +++ b/docs/SoundWave.html @@ -1,3 +1,3 @@ Class: SoundWave
On this page

SoundWave

Sound Wave Object - Stores a wave sound for later use and can be played positionally

  • this can be used to play wave, mp3, and ogg files

Constructor

new SoundWave(filename, randomnessopt, rangeopt, taperopt, onloadCallbackopt)

Create a sound object and cache the wave file for later use

Parameters:
NameTypeAttributesDefaultDescription
filenameString

Filename of audio file to load

randomnessNumber<optional>
0

How much to randomize frequency each time sound plays

rangeNumber<optional>
soundDefaultRange

World space max range of sound, will not play if camera is farther away

taperNumber<optional>
soundDefaultTaper

At what percentage of range should it start tapering off

onloadCallbackfunction<optional>

callback function to call when sound is loaded

Example
// create a sound
const sound_example = new SoundWave('sound.mp3');

// play the sound
sound_example.play();
\ No newline at end of file +
On this page

SoundWave

Sound Wave Object - Stores a wave sound for later use and can be played positionally

  • this can be used to play wave, mp3, and ogg files

Constructor

new SoundWave(filename, randomnessopt, rangeopt, taperopt, onloadCallbackopt)

Create a sound object and cache the wave file for later use

Parameters:
NameTypeAttributesDefaultDescription
filenameString

Filename of audio file to load

randomnessNumber<optional>
0

How much to randomize frequency each time sound plays

rangeNumber<optional>
soundDefaultRange

World space max range of sound, will not play if camera is farther away

taperNumber<optional>
soundDefaultTaper

At what percentage of range should it start tapering off

onloadCallbackfunction<optional>

callback function to call when sound is loaded

Example
// create a sound
const sound_example = new SoundWave('sound.mp3');

// play the sound
sound_example.play();
\ No newline at end of file diff --git a/docs/TileCollision.html b/docs/TileCollision.html index ea472f31..44417a43 100644 --- a/docs/TileCollision.html +++ b/docs/TileCollision.html @@ -1,3 +1,3 @@ Namespace: TileCollision
On this page

TileCollision

LittleJS Tile Layer System

  • Caches arrays of tiles to off screen canvas for fast rendering
  • Unlimited numbers of layers, allocates canvases as needed
  • Interfaces with EngineObject for collision
  • Collision layer is separate from visible layers
  • It is recommended to have a visible layer that matches the collision
  • Tile layers can be drawn to using their context with canvas2d
  • Drawn directly to the main canvas without using WebGL

Members

(static) tileCollision :Array

The tile collision layer array, use setTileCollisionData and getTileCollisionData to access

Type:
  • Array

(static) tileCollisionSize :Vector2

Size of the tile collision layer

Type:

Methods

(static) getTileCollisionData(pos) → {Number}

Get tile collision data

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
Number

(static) initTileCollision(size)

Clear and initialize tile collision

Parameters:
NameTypeDescription
sizeVector2

(static) setTileCollisionData(pos, dataopt)

Set tile collision data

Parameters:
NameTypeAttributesDefaultDescription
posVector2
dataNumber<optional>
0

(static) tileCollisionRaycast(posStart, posEnd, objectopt) → {Vector2}

Return the center of first tile hit (does not return the exact intersection)

Parameters:
NameTypeAttributesDescription
posStartVector2
posEndVector2
objectEngineObject<optional>
Returns:
Type: 
Vector2

(static) tileCollisionTest(pos, sizeopt, objectopt) → {Boolean}

Check if collision with another object should occur

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(0,0)
objectEngineObject<optional>
Returns:
Type: 
Boolean
\ No newline at end of file +
On this page

TileCollision

LittleJS Tile Layer System

  • Caches arrays of tiles to off screen canvas for fast rendering
  • Unlimited numbers of layers, allocates canvases as needed
  • Interfaces with EngineObject for collision
  • Collision layer is separate from visible layers
  • It is recommended to have a visible layer that matches the collision
  • Tile layers can be drawn to using their context with canvas2d
  • Drawn directly to the main canvas without using WebGL

Members

(static) tileCollision :Array

The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access

Type:
  • Array

(static) tileCollisionSize :Vector2

Size of the tile collision layer 2d grid

Type:

Methods

(static) getTileCollisionData(pos) → {Number}

Get tile collision data for a given cell in the grid

Parameters:
NameTypeDescription
posVector2
Returns:
Type: 
Number

(static) initTileCollision(size)

Clear and initialize tile collision

Parameters:
NameTypeDescription
sizeVector2

width and height of tile collision 2d grid

(static) setTileCollisionData(pos, dataopt)

Set tile collision data for a given cell in the grid

Parameters:
NameTypeAttributesDefaultDescription
posVector2
dataNumber<optional>
0

(static) tileCollisionRaycast(posStart, posEnd, objectopt) → {Vector2}

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.

Parameters:
NameTypeAttributesDescription
posStartVector2
posEndVector2
objectEngineObject<optional>
Returns:
Type: 
Vector2

(static) tileCollisionTest(pos, sizeopt, objectopt) → {Boolean}

Check if collision with another object should occur

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(0,0)
objectEngineObject<optional>
Returns:
Type: 
Boolean
\ No newline at end of file diff --git a/docs/TileLayer.html b/docs/TileLayer.html index 562afe21..75c4b21d 100644 --- a/docs/TileLayer.html +++ b/docs/TileLayer.html @@ -1,3 +1,3 @@ Class: TileLayer
On this page

TileLayer

Tile Layer - cached rendering system for tile layers

  • Each Tile layer is rendered to an off screen canvas
  • To allow dynamic modifications, layers are rendered using canvas 2d
  • Some devices like mobile phones are limited to 4k texture resolution
  • So with 16x16 tiles this limits layers to 256x256 on mobile devices

Constructor

new TileLayer(positionopt, sizeopt, tileInfoopt, scaleopt, renderOrderopt)

Create a tile layer object

Parameters:
NameTypeAttributesDefaultDescription
positionVector2<optional>
(0,0)

World space position

sizeVector2<optional>
tileCollisionSize

World space size

tileInfoTileInfo<optional>

Tile info for layer

scaleVector2<optional>
(1,1)

How much to scale this layer when rendered

renderOrderNumber<optional>
0

Objects are sorted by renderOrder

Example
// create tile collision and visible tile layer
initTileCollision(vec2(200,100));
const tileLayer = new TileLayer();

Extends

Members

additiveColor

Properties
TypeDescription
Color

Additive color to apply when rendered

angle

Properties
TypeDescription
Number

Angle to rotate the object

angleDamping

Properties
NameTypeAttributesDefaultDescription
angleDampingNumber<optional>
objectDefaultAngleDamping

How much to slow down rotation each frame (0-1)

angleVelocity

Properties
TypeDescription
Number

Angular velocity of the object

canvas

Properties
TypeDescription
HTMLCanvasElement

The canvas used by this tile layer

children

Properties
TypeDescription
Array

List of children of this object

clampSpeedLinear

Properties
TypeDescription
Boolean

Limit object speed using linear or circular math

collideRaycast

Properties
TypeDescription
Boolean

Object collides with raycasts

collideSolidObjects

Properties
TypeDescription
Boolean

Object collides with solid objects

collideTiles

Properties
TypeDescription
Boolean

Object collides with the tile collision

color

Properties
TypeDescription
Color

Color to apply when rendered

context

Properties
TypeDescription
CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

The 2D canvas context used by this tile layer

damping

Properties
NameTypeAttributesDefaultDescription
dampingNumber<optional>
objectDefaultDamping

How much to slow down velocity each frame (0-1)

drawSize

Properties
TypeDescription
Vector2

Size of object used for drawing, uses size if not set

elasticity

Properties
NameTypeAttributesDefaultDescription
elasticityNumber<optional>
objectDefaultElasticity

How bouncy the object is when colliding (0-1)

friction

Properties
NameTypeAttributesDefaultDescription
frictionNumber<optional>
objectDefaultFriction

How much friction to apply when sliding (0-1)

gravityScale

Properties
TypeDescription
Number

How much to scale gravity by for this object

isOverlay

Properties
TypeDescription
Boolean

If true this layer will render to overlay canvas and appear above all objects

isSolid

Properties
TypeDescription
Boolean

Object collides with and blocks other objects

localAngle

Properties
TypeDescription
Number

Local angle if child

localPos

Properties
TypeDescription
Vector2

Local position if child

mass

Properties
NameTypeAttributesDefaultDescription
massNumber<optional>
objectDefaultMass

How heavy the object is, static if 0

mirror

Properties
TypeDescription
Boolean

Should it flip along y axis when rendered

parent

Properties
TypeDescription
EngineObject

Parent of object if in local space

pos

Properties
TypeDescription
Vector2

World space position of the object

renderOrder

Properties
TypeDescription
Number

Objects are sorted by render order

savedRenderSettings

scale

Properties
TypeDescription
Vector2

How much to scale this layer when rendered

size

Properties
TypeDescription
Vector2

World space width and height of the object

spawnTime

Properties
TypeDescription
Number

Track when object was created

tileInfo

Properties
TypeDescription
TileInfo

Tile info to render object (undefined is untextured)

velocity

Properties
TypeDescription
Vector2

Velocity of the object

Methods

addChild(child, localPosopt, localAngleopt)

Attaches a child to this with a given local transform

Parameters:
NameTypeAttributesDefaultDescription
childEngineObject
localPosVector2<optional>
(0,0)
localAngleNumber<optional>
0

applyAcceleration(acceleration)

Apply acceleration to this object (adjust velocity, not affected by mass)

Parameters:
NameTypeDescription
accelerationVector2

applyForce(force)

Apply force to this object (adjust velocity, affected by mass)

Parameters:
NameTypeDescription
forceVector2

collideWithObject(object) → {Boolean}

Called to check if a object collision should be resolved

Parameters:
NameTypeDescription
objectEngineObject

the object to test against

Returns:
  • true if the collision should be resolved
Type: 
Boolean

collideWithTile(tileData, pos) → {Boolean}

Called to check if a tile collision should be resolved

Parameters:
NameTypeDescription
tileDataNumber

the value of the tile at the position

posVector2

tile where the collision occured

Returns:
  • true if the collision should be resolved
Type: 
Boolean

destroy()

Destroy this object, destroy it's children, detach it's parent, and mark it for removal

drawCanvas2D(pos, size, angle, mirror, drawFunction)

Draw directly to the 2D canvas in world space (bipass webgl)

Parameters:
NameTypeDescription
posVector2
sizeVector2
angleNumber
mirrorBoolean
drawFunctionfunction

drawRect(pos, sizeopt, coloropt, angleopt)

Draw a rectangle directly onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(1,1)
colorColor<optional>
(1,1,1,1)
angleNumber<optional>
0

drawTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt)

Draw a tile directly onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(1,1)
tileInfoTileInfo<optional>
colorColor<optional>
(1,1,1,1)
angleNumber<optional>
0
mirrorBoolean<optional>
0

drawTileData(layerPos, clearopt)

Draw the tile at a given position in the tile grid This can be used to clear out tiles when they are destroyed Tiles can also be redrawn if isinde a redrawStart/End block

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2
clearBoolean<optional>
true

should the old tile be cleared out

getAliveTime() → {Number}

How long since the object was created

Returns:
Type: 
Number

getData(layerPos) → {TileLayerData}

Get data at a given position in the array

Parameters:
NameTypeDescription
layerPosVector2

Local position in array

Returns:
Type: 
TileLayerData

getMirrorSign() → {Number}

Get the direction of the mirror

Returns:

-1 if this.mirror is true, or 1 if not mirrored

Type: 
Number

localToWorld(pos)

Convert from local space to world space

Parameters:
NameTypeDescription
posVector2

local space point

localToWorldVector(vec)

Convert from local space to world space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

local space vector

redraw()

Draw all the tile data to an offscreen canvas

  • This may be slow in some browsers but only needs to be done once

redrawEnd()

Call to end the redraw process

redrawStart(clearopt)

Call to start the redraw process

  • This can be used to manually update small parts of the level
Parameters:
NameTypeAttributesDefaultDescription
clearBoolean<optional>
false

Should it clear the canvas before drawing

removeChild(child)

Removes a child from this one

Parameters:
NameTypeDescription
childEngineObject

render()

Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder

renderDebugInfo()

Render debug info for this object

setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, collideRaycastopt)

Set how this object collides

Parameters:
NameTypeAttributesDefaultDescription
collideSolidObjectsBoolean<optional>
true

Does it collide with solid objects?

isSolidBoolean<optional>
true

Does it collide with and block other objects? (expensive in large numbers)

collideTilesBoolean<optional>
true

Does it collide with the tile collision?

collideRaycastBoolean<optional>
true

Does it collide with raycasts?

setData(layerPos, data, redrawopt)

Set data at a given position in the array

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2

Local position in array

dataTileLayerData

Data to set

redrawBoolean<optional>
false

Force the tile to redraw if true

toString() → {String}

Returns string containg info about this object for debugging

Returns:
Type: 
String

update()

Update the object physics, called automatically by engine once each frame

updateTransforms()

Update the object transform, called automatically by engine even when paused

worldToLocal(pos)

Convert from world space to local space

Parameters:
NameTypeDescription
posVector2

world space point

worldToLocalVector(vec)

Convert from world space to local space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

world space vector

\ No newline at end of file +
On this page

TileLayer

Tile Layer - cached rendering system for tile layers

  • Each Tile layer is rendered to an off screen canvas
  • To allow dynamic modifications, layers are rendered using canvas 2d
  • Some devices like mobile phones are limited to 4k texture resolution
  • So with 16x16 tiles this limits layers to 256x256 on mobile devices

Constructor

new TileLayer(positionopt, sizeopt, tileInfoopt, scaleopt, renderOrderopt)

Create a tile layer object

Parameters:
NameTypeAttributesDefaultDescription
positionVector2<optional>
(0,0)

World space position

sizeVector2<optional>
tileCollisionSize

World space size

tileInfoTileInfo<optional>

Tile info for layer

scaleVector2<optional>
(1,1)

How much to scale this layer when rendered

renderOrderNumber<optional>
0

Objects are sorted by renderOrder

Example
// create tile collision and visible tile layer
initTileCollision(vec2(200,100));
const tileLayer = new TileLayer();

Extends

Members

additiveColor

Properties
TypeDescription
Color

Additive color to apply when rendered

angle

Properties
TypeDescription
Number

Angle to rotate the object

angleDamping

Properties
NameTypeAttributesDefaultDescription
angleDampingNumber<optional>
objectDefaultAngleDamping

How much to slow down rotation each frame (0-1)

angleVelocity

Properties
TypeDescription
Number

Angular velocity of the object

canvas

Properties
TypeDescription
HTMLCanvasElement

The canvas used by this tile layer

children

Properties
TypeDescription
Array

List of children of this object

clampSpeedLinear

Properties
TypeDescription
Boolean

Limit object speed using linear or circular math

collideRaycast

Properties
TypeDescription
Boolean

Object collides with raycasts

collideSolidObjects

Properties
TypeDescription
Boolean

Object collides with solid objects

collideTiles

Properties
TypeDescription
Boolean

Object collides with the tile collision

color

Properties
TypeDescription
Color

Color to apply when rendered

context

Properties
TypeDescription
CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D

The 2D canvas context used by this tile layer

damping

Properties
NameTypeAttributesDefaultDescription
dampingNumber<optional>
objectDefaultDamping

How much to slow down velocity each frame (0-1)

drawSize

Properties
TypeDescription
Vector2

Size of object used for drawing, uses size if not set

elasticity

Properties
NameTypeAttributesDefaultDescription
elasticityNumber<optional>
objectDefaultElasticity

How bouncy the object is when colliding (0-1)

friction

Properties
NameTypeAttributesDefaultDescription
frictionNumber<optional>
objectDefaultFriction

How much friction to apply when sliding (0-1)

gravityScale

Properties
TypeDescription
Number

How much to scale gravity by for this object

isOverlay

Properties
TypeDescription
Boolean

If true this layer will render to overlay canvas and appear above all objects

isSolid

Properties
TypeDescription
Boolean

Object collides with and blocks other objects

localAngle

Properties
TypeDescription
Number

Local angle if child

localPos

Properties
TypeDescription
Vector2

Local position if child

mass

Properties
NameTypeAttributesDefaultDescription
massNumber<optional>
objectDefaultMass

How heavy the object is, static if 0

mirror

Properties
TypeDescription
Boolean

Should it flip along y axis when rendered

parent

Properties
TypeDescription
EngineObject

Parent of object if in local space

pos

Properties
TypeDescription
Vector2

World space position of the object

renderOrder

Properties
TypeDescription
Number

Objects are sorted by render order

savedRenderSettings

scale

Properties
TypeDescription
Vector2

How much to scale this layer when rendered

size

Properties
TypeDescription
Vector2

World space width and height of the object

spawnTime

Properties
TypeDescription
Number

Track when object was created

tileInfo

Properties
TypeDescription
TileInfo

Tile info to render object (undefined is untextured)

velocity

Properties
TypeDescription
Vector2

Velocity of the object

Methods

addChild(child, localPosopt, localAngleopt)

Attaches a child to this with a given local transform

Parameters:
NameTypeAttributesDefaultDescription
childEngineObject
localPosVector2<optional>
(0,0)
localAngleNumber<optional>
0

applyAcceleration(acceleration)

Apply acceleration to this object (adjust velocity, not affected by mass)

Parameters:
NameTypeDescription
accelerationVector2

applyForce(force)

Apply force to this object (adjust velocity, affected by mass)

Parameters:
NameTypeDescription
forceVector2

collideWithObject(object) → {Boolean}

Called to check if a object collision should be resolved

Parameters:
NameTypeDescription
objectEngineObject

the object to test against

Returns:
  • true if the collision should be resolved
Type: 
Boolean

collideWithTile(tileData, pos) → {Boolean}

Called to check if a tile collision should be resolved

Parameters:
NameTypeDescription
tileDataNumber

the value of the tile at the position

posVector2

tile where the collision occured

Returns:
  • true if the collision should be resolved
Type: 
Boolean

destroy()

Destroy this object, destroy it's children, detach it's parent, and mark it for removal

drawCanvas2D(pos, size, angle, mirror, drawFunction)

Draw directly to the 2D canvas in world space (bipass webgl)

Parameters:
NameTypeDescription
posVector2
sizeVector2
angleNumber
mirrorBoolean
drawFunctionfunction

drawRect(pos, sizeopt, coloropt, angleopt)

Draw a rectangle directly onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(1,1)
colorColor<optional>
(1,1,1,1)
angleNumber<optional>
0

drawTile(pos, sizeopt, tileInfoopt, coloropt, angleopt, mirroropt)

Draw a tile directly onto the layer canvas in world space

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2<optional>
(1,1)
tileInfoTileInfo<optional>
colorColor<optional>
(1,1,1,1)
angleNumber<optional>
0
mirrorBoolean<optional>
0

drawTileData(layerPos, clearopt)

Draw the tile at a given position in the tile grid This can be used to clear out tiles when they are destroyed Tiles can also be redrawn if isinde a redrawStart/End block

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2
clearBoolean<optional>
true

should the old tile be cleared out

getAliveTime() → {Number}

How long since the object was created

Returns:
Type: 
Number

getData(layerPos) → {TileLayerData}

Get data at a given position in the array

Parameters:
NameTypeDescription
layerPosVector2

Local position in array

Returns:
Type: 
TileLayerData

getMirrorSign() → {Number}

Get the direction of the mirror

Returns:

-1 if this.mirror is true, or 1 if not mirrored

Type: 
Number

localToWorld(pos)

Convert from local space to world space

Parameters:
NameTypeDescription
posVector2

local space point

localToWorldVector(vec)

Convert from local space to world space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

local space vector

redraw()

Draw all the tile data to an offscreen canvas

  • This may be slow in some browsers but only needs to be done once

redrawEnd()

Call to end the redraw process

redrawStart(clearopt)

Call to start the redraw process

  • This can be used to manually update small parts of the level
Parameters:
NameTypeAttributesDefaultDescription
clearBoolean<optional>
false

Should it clear the canvas before drawing

removeChild(child)

Removes a child from this one

Parameters:
NameTypeDescription
childEngineObject

render()

Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder

renderDebugInfo()

Render debug info for this object

setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, collideRaycastopt)

Set how this object collides

Parameters:
NameTypeAttributesDefaultDescription
collideSolidObjectsBoolean<optional>
true

Does it collide with solid objects?

isSolidBoolean<optional>
true

Does it collide with and block other objects? (expensive in large numbers)

collideTilesBoolean<optional>
true

Does it collide with the tile collision?

collideRaycastBoolean<optional>
true

Does it collide with raycasts?

setData(layerPos, data, redrawopt)

Set data at a given position in the array

Parameters:
NameTypeAttributesDefaultDescription
layerPosVector2

Local position in array

dataTileLayerData

Data to set

redrawBoolean<optional>
false

Force the tile to redraw if true

toString() → {String}

Returns string containg info about this object for debugging

Returns:
Type: 
String

update()

Update the object physics, called automatically by engine once each frame

updateTransforms()

Update the object transform, called automatically by engine even when paused

worldToLocal(pos)

Convert from world space to local space

Parameters:
NameTypeDescription
posVector2

world space point

worldToLocalVector(vec)

Convert from world space to local space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

world space vector

\ No newline at end of file diff --git a/docs/TileLayerData.html b/docs/TileLayerData.html index 41a76578..c36324b7 100644 --- a/docs/TileLayerData.html +++ b/docs/TileLayerData.html @@ -1,3 +1,3 @@ Class: TileLayerData
On this page

TileLayerData

Tile layer data object stores info about how to render a tile

Constructor

new TileLayerData(tileopt, directionopt, mirroropt, coloropt)

Create a tile layer data object, one for each tile in a TileLayer

Parameters:
NameTypeAttributesDefaultDescription
tileNumber<optional>

The tile to use, untextured if undefined

directionNumber<optional>
0

Integer direction of tile, in 90 degree increments

mirrorBoolean<optional>
false

If the tile should be mirrored along the x axis

colorColor<optional>

Color of the tile

Example
// create tile layer data with tile index 0 and random orientation and color
const tileIndex = 0;
const direction = randInt(4)
const mirror = randInt(2);
const color = randColor();
const data = new TileLayerData(tileIndex, direction, mirror, color);

Members

color

Properties
TypeDescription
Color

Color of the tile

direction

Properties
TypeDescription
Number

Integer direction of tile, in 90 degree increments

mirror

Properties
TypeDescription
Boolean

If the tile should be mirrored along the x axis

tile

Properties
TypeDescription
Number

The tile to use, untextured if undefined

Methods

clear()

Set this tile to clear, it will not be rendered

\ No newline at end of file +
On this page

TileLayerData

Tile layer data object stores info about how to render a tile

Constructor

new TileLayerData(tileopt, directionopt, mirroropt, coloropt)

Create a tile layer data object, one for each tile in a TileLayer

Parameters:
NameTypeAttributesDefaultDescription
tileNumber<optional>

The tile to use, untextured if undefined

directionNumber<optional>
0

Integer direction of tile, in 90 degree increments

mirrorBoolean<optional>
false

If the tile should be mirrored along the x axis

colorColor<optional>

Color of the tile

Example
// create tile layer data with tile index 0 and random orientation and color
const tileIndex = 0;
const direction = randInt(4)
const mirror = randInt(2);
const color = randColor();
const data = new TileLayerData(tileIndex, direction, mirror, color);

Members

color

Properties
TypeDescription
Color

Color of the tile

direction

Properties
TypeDescription
Number

Integer direction of tile, in 90 degree increments

mirror

Properties
TypeDescription
Boolean

If the tile should be mirrored along the x axis

tile

Properties
TypeDescription
Number

The tile to use, untextured if undefined

Methods

clear()

Set this tile to clear, it will not be rendered

\ No newline at end of file diff --git a/docs/Timer.html b/docs/Timer.html index dd9c0827..181404ed 100644 --- a/docs/Timer.html +++ b/docs/Timer.html @@ -1,3 +1,3 @@ Class: Timer
On this page

Timer

Timer object tracks how long has passed since it was set

Constructor

new Timer(timeLeftopt)

Create a timer object set time passed in

Parameters:
NameTypeAttributesDescription
timeLeftNumber<optional>

How much time left before the timer elapses in seconds

Example
let a = new Timer;    // creates a timer that is not set
a.set(3);             // sets the timer to 3 seconds

let b = new Timer(1); // creates a timer with 1 second left
b.unset();            // unsets the timer

Methods

active() → {Boolean}

Returns true if set and has not elapsed

Returns:
Type: 
Boolean

elapsed() → {Boolean}

Returns true if set and elapsed

Returns:
Type: 
Boolean

get() → {Number}

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

Returns:
Type: 
Number

getPercent() → {Number}

Get percentage elapsed based on time it was set to, returns 0 if not set

Returns:
Type: 
Number

isSet() → {Boolean}

Returns true if set

Returns:
Type: 
Boolean

set(timeLeftopt)

Set the timer with seconds passed in

Parameters:
NameTypeAttributesDefaultDescription
timeLeftNumber<optional>
0

How much time left before the timer is elapsed in seconds

toString() → {String}

Returns this timer expressed as a string

Returns:
Type: 
String

unset()

Unset the timer

valueOf() → {Number}

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

Returns:
Type: 
Number
\ No newline at end of file +
On this page

Timer

Timer object tracks how long has passed since it was set

Constructor

new Timer(timeLeftopt)

Create a timer object set time passed in

Parameters:
NameTypeAttributesDescription
timeLeftNumber<optional>

How much time left before the timer elapses in seconds

Example
let a = new Timer;    // creates a timer that is not set
a.set(3);             // sets the timer to 3 seconds

let b = new Timer(1); // creates a timer with 1 second left
b.unset();            // unsets the timer

Methods

active() → {Boolean}

Returns true if set and has not elapsed

Returns:
Type: 
Boolean

elapsed() → {Boolean}

Returns true if set and elapsed

Returns:
Type: 
Boolean

get() → {Number}

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

Returns:
Type: 
Number

getPercent() → {Number}

Get percentage elapsed based on time it was set to, returns 0 if not set

Returns:
Type: 
Number

isSet() → {Boolean}

Returns true if set

Returns:
Type: 
Boolean

set(timeLeftopt)

Set the timer with seconds passed in

Parameters:
NameTypeAttributesDefaultDescription
timeLeftNumber<optional>
0

How much time left before the timer is elapsed in seconds

toString() → {String}

Returns this timer expressed as a string

Returns:
Type: 
String

unset()

Unset the timer

valueOf() → {Number}

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

Returns:
Type: 
Number
\ No newline at end of file diff --git a/docs/Utilities.html b/docs/Utilities.html index 0238a804..326b1baf 100644 --- a/docs/Utilities.html +++ b/docs/Utilities.html @@ -1,3 +1,3 @@ Namespace: Utilities
On this page

Utilities

LittleJS Utility Classes and Functions

  • General purpose math library
  • Vector2 - fast, simple, easy 2D vector class
  • Color - holds a rgba color with some math functions
  • Timer - tracks time automatically
  • RandomGenerator - seeded random number generator

Members

(static, constant) BLACK :Color

Color - Black

Type:

(static, constant) BLUE :Color

Color - Blue

Type:

(static, constant) CYAN :Color

Color - Cyan

Type:

(static, constant) GRAY :Color

Color - Gray

Type:

(static, constant) GREEN :Color

Color - Green

Type:

(static, constant) MAGENTA :Color

Color - Magenta

Type:

(static, constant) ORANGE :Color

Color - Orange

Type:

(static, constant) PI :Number

A shortcut to get Math.PI

Type:
  • Number
Default Value
  • Math.PI

(static, constant) PURPLE :Color

Color - Purple

Type:

(static, constant) RED :Color

Color - Red

Type:

(static, constant) WHITE :Color

Color - White

Type:

(static, constant) YELLOW :Color

Color - Yellow

Type:

Methods

(static) abs(value) → {Number}

Returns absoulte value of value passed in

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) clamp(value, minopt, maxopt) → {Number}

Clamps the value beween max and min

Parameters:
NameTypeAttributesDefaultDescription
valueNumber
minNumber<optional>
0
maxNumber<optional>
1
Returns:
Type: 
Number

(static) distanceAngle(angleA, angleB) → {Number}

Returns signed wrapped distance between the two angles passed in

Parameters:
NameTypeDescription
angleANumber
angleBNumber
Returns:
Type: 
Number

(static) distanceWrap(valueA, valueB, wrapSizeopt) → {Number}

Returns signed wrapped distance between the two values passed in

Parameters:
NameTypeAttributesDefaultDescription
valueANumber
valueBNumber
wrapSizeNumber<optional>
1
Returns:
Type: 
Number

(static) formatTime(t) → {String}

Formats seconds to mm:ss style for display purposes

Parameters:
NameTypeDescription
tNumber

time in seconds

Returns:
Type: 
String

(static) hsl(hopt, sopt, lopt, aopt) → {Color}

Create a color object with HSLA values, white by default

Parameters:
NameTypeAttributesDefaultDescription
hNumber<optional>
0

hue

sNumber<optional>
0

saturation

lNumber<optional>
1

lightness

aNumber<optional>
1

alpha

Returns:
Type: 
Color

(static) isColor(c) → {Boolean}

Check if object is a valid Color

Parameters:
NameTypeDescription
cany
Returns:
Type: 
Boolean

(static) isIntersecting(start, end, pos, size) → {Boolean}

Returns true if a line segment is intersecting an axis aligned box

Parameters:
NameTypeDescription
startVector2

Start of raycast

endVector2

End of raycast

posVector2

Center of box

sizeVector2

Size of box

Returns:
  • True if intersecting
Type: 
Boolean

(static) isOverlapping(posA, sizeA, posB, sizeBopt) → {Boolean}

Returns true if two axis aligned bounding boxes are overlapping

Parameters:
NameTypeAttributesDefaultDescription
posAVector2

Center of box A

sizeAVector2

Size of box A

posBVector2

Center of box B

sizeBVector2<optional>
(0,0)

Size of box B, a point if undefined

Returns:
  • True if overlapping
Type: 
Boolean

(static) isVector2(v) → {Boolean}

Check if object is a valid Vector2

Parameters:
NameTypeDescription
vany
Returns:
Type: 
Boolean

(static) lerp(percent, valueA, valueB) → {Number}

Linearly interpolates between values passed in using percent

Parameters:
NameTypeDescription
percentNumber
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) lerpAngle(percent, angleA, angleB) → {Number}

Linearly interpolates between the angles passed in with wrapping

Parameters:
NameTypeDescription
percentNumber
angleANumber
angleBNumber
Returns:
Type: 
Number

(static) lerpWrap(percent, valueA, valueB, wrapSizeopt) → {Number}

Linearly interpolates between values passed in with wrapping

Parameters:
NameTypeAttributesDefaultDescription
percentNumber
valueANumber
valueBNumber
wrapSizeNumber<optional>
1
Returns:
Type: 
Number

(static) max(valueA, valueB) → {Number}

Returns highest of two values passed in

Parameters:
NameTypeDescription
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) min(valueA, valueB) → {Number}

Returns lowest of two values passed in

Parameters:
NameTypeDescription
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) mod(dividend, divisoropt) → {Number}

Returns first parm modulo the second param, but adjusted so negative numbers work as expected

Parameters:
NameTypeAttributesDefaultDescription
dividendNumber
divisorNumber<optional>
1
Returns:
Type: 
Number

(static) nearestPowerOfTwo(value) → {Number}

Returns the nearest power of two not less then the value

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) percent(value, valueA, valueB) → {Number}

Returns what percentage the value is between valueA and valueB

Parameters:
NameTypeDescription
valueNumber
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) rgb(ropt, gopt, bopt, aopt) → {Color}

Create a color object with RGBA values, white by default

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Returns:
Type: 
Color

(static) sign(value) → {Number}

Returns the sign of value passed in

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) smoothStep(percent) → {Number}

Applies smoothstep function to the percentage value

Parameters:
NameTypeDescription
percentNumber
Returns:
Type: 
Number

(static) vec2(xopt, yopt) → {Vector2}

Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar

Parameters:
NameTypeAttributesDefaultDescription
xNumber | Vector2<optional>
0
yNumber<optional>
Returns:
Type: 
Vector2
Example
let a = vec2(0, 1); // vector with coordinates (0, 1)
let b = vec2(a);    // copy a into b
a = vec2(5);        // set a to (5, 5)
b = vec2();         // set b to (0, 0)

(static) wave(frequencyopt, amplitudeopt, topt) → {Number}

Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default

Parameters:
NameTypeAttributesDefaultDescription
frequencyNumber<optional>
1

Frequency of the wave in Hz

amplitudeNumber<optional>
1

Amplitude (max height) of the wave

tNumber<optional>
time

Value to use for time of the wave

Returns:
  • Value waving between 0 and amplitude
Type: 
Number
\ No newline at end of file +
On this page

Utilities

LittleJS Utility Classes and Functions

  • General purpose math library
  • Vector2 - fast, simple, easy 2D vector class
  • Color - holds a rgba color with some math functions
  • Timer - tracks time automatically
  • RandomGenerator - seeded random number generator

Members

(static, constant) BLACK :Color

Color - Black

Type:

(static, constant) BLUE :Color

Color - Blue

Type:

(static, constant) CYAN :Color

Color - Cyan

Type:

(static, constant) GRAY :Color

Color - Gray

Type:

(static, constant) GREEN :Color

Color - Green

Type:

(static, constant) MAGENTA :Color

Color - Magenta

Type:

(static, constant) ORANGE :Color

Color - Orange

Type:

(static, constant) PI :Number

A shortcut to get Math.PI

Type:
  • Number
Default Value
  • Math.PI

(static, constant) PURPLE :Color

Color - Purple

Type:

(static, constant) RED :Color

Color - Red

Type:

(static, constant) WHITE :Color

Color - White

Type:

(static, constant) YELLOW :Color

Color - Yellow

Type:

Methods

(static) abs(value) → {Number}

Returns absoulte value of value passed in

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) clamp(value, minopt, maxopt) → {Number}

Clamps the value beween max and min

Parameters:
NameTypeAttributesDefaultDescription
valueNumber
minNumber<optional>
0
maxNumber<optional>
1
Returns:
Type: 
Number

(static) distanceAngle(angleA, angleB) → {Number}

Returns signed wrapped distance between the two angles passed in

Parameters:
NameTypeDescription
angleANumber
angleBNumber
Returns:
Type: 
Number

(static) distanceWrap(valueA, valueB, wrapSizeopt) → {Number}

Returns signed wrapped distance between the two values passed in

Parameters:
NameTypeAttributesDefaultDescription
valueANumber
valueBNumber
wrapSizeNumber<optional>
1
Returns:
Type: 
Number

(static) formatTime(t) → {String}

Formats seconds to mm:ss style for display purposes

Parameters:
NameTypeDescription
tNumber

time in seconds

Returns:
Type: 
String

(static) hsl(hopt, sopt, lopt, aopt) → {Color}

Create a color object with HSLA values, white by default

Parameters:
NameTypeAttributesDefaultDescription
hNumber<optional>
0

hue

sNumber<optional>
0

saturation

lNumber<optional>
1

lightness

aNumber<optional>
1

alpha

Returns:
Type: 
Color

(static) isColor(c) → {Boolean}

Check if object is a valid Color

Parameters:
NameTypeDescription
cany
Returns:
Type: 
Boolean

(static) isIntersecting(start, end, pos, size) → {Boolean}

Returns true if a line segment is intersecting an axis aligned box

Parameters:
NameTypeDescription
startVector2

Start of raycast

endVector2

End of raycast

posVector2

Center of box

sizeVector2

Size of box

Returns:
  • True if intersecting
Type: 
Boolean

(static) isOverlapping(posA, sizeA, posB, sizeBopt) → {Boolean}

Returns true if two axis aligned bounding boxes are overlapping

Parameters:
NameTypeAttributesDefaultDescription
posAVector2

Center of box A

sizeAVector2

Size of box A

posBVector2

Center of box B

sizeBVector2<optional>
(0,0)

Size of box B, a point if undefined

Returns:
  • True if overlapping
Type: 
Boolean

(static) isVector2(v) → {Boolean}

Check if object is a valid Vector2

Parameters:
NameTypeDescription
vany
Returns:
Type: 
Boolean

(static) lerp(percent, valueA, valueB) → {Number}

Linearly interpolates between values passed in using percent

Parameters:
NameTypeDescription
percentNumber
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) lerpAngle(percent, angleA, angleB) → {Number}

Linearly interpolates between the angles passed in with wrapping

Parameters:
NameTypeDescription
percentNumber
angleANumber
angleBNumber
Returns:
Type: 
Number

(static) lerpWrap(percent, valueA, valueB, wrapSizeopt) → {Number}

Linearly interpolates between values passed in with wrapping

Parameters:
NameTypeAttributesDefaultDescription
percentNumber
valueANumber
valueBNumber
wrapSizeNumber<optional>
1
Returns:
Type: 
Number

(static) max(valueA, valueB) → {Number}

Returns highest of two values passed in

Parameters:
NameTypeDescription
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) min(valueA, valueB) → {Number}

Returns lowest of two values passed in

Parameters:
NameTypeDescription
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) mod(dividend, divisoropt) → {Number}

Returns first parm modulo the second param, but adjusted so negative numbers work as expected

Parameters:
NameTypeAttributesDefaultDescription
dividendNumber
divisorNumber<optional>
1
Returns:
Type: 
Number

(static) nearestPowerOfTwo(value) → {Number}

Returns the nearest power of two not less then the value

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) percent(value, valueA, valueB) → {Number}

Returns what percentage the value is between valueA and valueB

Parameters:
NameTypeDescription
valueNumber
valueANumber
valueBNumber
Returns:
Type: 
Number

(static) rgb(ropt, gopt, bopt, aopt) → {Color}

Create a color object with RGBA values, white by default

Parameters:
NameTypeAttributesDefaultDescription
rNumber<optional>
1

red

gNumber<optional>
1

green

bNumber<optional>
1

blue

aNumber<optional>
1

alpha

Returns:
Type: 
Color

(static) sign(value) → {Number}

Returns the sign of value passed in

Parameters:
NameTypeDescription
valueNumber
Returns:
Type: 
Number

(static) smoothStep(percent) → {Number}

Applies smoothstep function to the percentage value

Parameters:
NameTypeDescription
percentNumber
Returns:
Type: 
Number

(static) vec2(xopt, yopt) → {Vector2}

Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar

Parameters:
NameTypeAttributesDefaultDescription
xNumber | Vector2<optional>
0
yNumber<optional>
Returns:
Type: 
Vector2
Example
let a = vec2(0, 1); // vector with coordinates (0, 1)
let b = vec2(a);    // copy a into b
a = vec2(5);        // set a to (5, 5)
b = vec2();         // set b to (0, 0)

(static) wave(frequencyopt, amplitudeopt, topt) → {Number}

Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default

Parameters:
NameTypeAttributesDefaultDescription
frequencyNumber<optional>
1

Frequency of the wave in Hz

amplitudeNumber<optional>
1

Amplitude (max height) of the wave

tNumber<optional>
time

Value to use for time of the wave

Returns:
  • Value waving between 0 and amplitude
Type: 
Number
\ No newline at end of file diff --git a/docs/Vector2.html b/docs/Vector2.html index c2540f99..5515a95a 100644 --- a/docs/Vector2.html +++ b/docs/Vector2.html @@ -1,3 +1,3 @@ Class: Vector2
On this page

Vector2

2D Vector object with vector math library

  • Functions do not change this so they can be chained together

Constructor

new Vector2(xopt, yopt)

Create a 2D vector with the x and y passed in, can also be created with vec2()

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0

X axis location

yNumber<optional>
0

Y axis location

Example
let a = new Vector2(2, 3); // vector with coordinates (2, 3)
let b = new Vector2;       // vector with coordinates (0, 0)
let c = vec2(4, 2);        // use the vec2 function to make a Vector2
let d = a.add(b).scale(5); // operators can be chained

Members

x

Properties
TypeDescription
Number

X axis location

y

Properties
TypeDescription
Number

Y axis location

Methods

add(v) → {Vector2}

Returns a copy of this vector plus the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

angle() → {Number}

Returns the angle of this vector, up is angle 0

Returns:
Type: 
Number

area() → {Number}

Returns the area this vector covers as a rectangle

Returns:
Type: 
Number

arrayCheck(arraySize) → {Boolean}

Returns true if this vector is within the bounds of an array size passed in

Parameters:
NameTypeDescription
arraySizeVector2
Returns:
Type: 
Boolean

clampLength(lengthopt) → {Vector2}

Returns a new vector clamped to length passed in

Parameters:
NameTypeAttributesDefaultDescription
lengthNumber<optional>
1
Returns:
Type: 
Vector2

copy() → {Vector2}

Returns a new vector that is a copy of this

Returns:
Type: 
Vector2

cross(v) → {Number}

Returns the cross product of this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

direction() → {Number}

Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

Returns:
Type: 
Number

distance(v) → {Number}

Returns the distance from this vector to vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

distanceSquared(v) → {Number}

Returns the distance squared from this vector to vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

divide(v) → {Vector2}

Returns a copy of this vector divided by the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

dot(v) → {Number}

Returns the dot product of this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

floor() → {Vector2}

Returns a copy of this vector with each axis floored

Returns:
Type: 
Vector2

invert() → {Vector2}

Returns a copy of this vector that has been inverted

Returns:
Type: 
Vector2

length() → {Number}

Returns the length of this vector

Returns:
Type: 
Number

lengthSquared() → {Number}

Returns the length of this vector squared

Returns:
Type: 
Number

lerp(v, percent) → {Vector2}

Returns a new vector that is p percent between this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

percentNumber
Returns:
Type: 
Vector2

multiply(v) → {Vector2}

Returns a copy of this vector times the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

normalize(lengthopt) → {Vector2}

Returns a new vector in same direction as this one with the length passed in

Parameters:
NameTypeAttributesDefaultDescription
lengthNumber<optional>
1
Returns:
Type: 
Vector2

rotate(angle) → {Vector2}

Returns copy of this vector rotated by the angle passed in

Parameters:
NameTypeDescription
angleNumber
Returns:
Type: 
Vector2

scale(s) → {Vector2}

Returns a copy of this vector scaled by the vector passed in

Parameters:
NameTypeDescription
sNumber

scale

Returns:
Type: 
Vector2

set(xopt, yopt) → {Vector2}

Sets values of this vector and returns self

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0

X axis location

yNumber<optional>
0

Y axis location

Returns:
Type: 
Vector2

setAngle(angleopt, lengthopt) → {Vector2}

Sets this vector with angle and length passed in

Parameters:
NameTypeAttributesDefaultDescription
angleNumber<optional>
0
lengthNumber<optional>
1
Returns:
Type: 
Vector2

setDirection(directionopt, lengthopt)

Set the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

Parameters:
NameTypeAttributesDefaultDescription
directionNumber<optional>
lengthNumber<optional>
1

subtract(v) → {Vector2}

Returns a copy of this vector minus the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

toString(digits) → {String}

Returns this vector expressed as a string

Parameters:
NameTypeDefaultDescription
digitsNumber3

precision to display

Returns:
Type: 
String
\ No newline at end of file +
On this page

Vector2

2D Vector object with vector math library

  • Functions do not change this so they can be chained together

Constructor

new Vector2(xopt, yopt)

Create a 2D vector with the x and y passed in, can also be created with vec2()

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0

X axis location

yNumber<optional>
0

Y axis location

Example
let a = new Vector2(2, 3); // vector with coordinates (2, 3)
let b = new Vector2;       // vector with coordinates (0, 0)
let c = vec2(4, 2);        // use the vec2 function to make a Vector2
let d = a.add(b).scale(5); // operators can be chained

Members

x

Properties
TypeDescription
Number

X axis location

y

Properties
TypeDescription
Number

Y axis location

Methods

add(v) → {Vector2}

Returns a copy of this vector plus the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

angle() → {Number}

Returns the angle of this vector, up is angle 0

Returns:
Type: 
Number

area() → {Number}

Returns the area this vector covers as a rectangle

Returns:
Type: 
Number

arrayCheck(arraySize) → {Boolean}

Returns true if this vector is within the bounds of an array size passed in

Parameters:
NameTypeDescription
arraySizeVector2
Returns:
Type: 
Boolean

clampLength(lengthopt) → {Vector2}

Returns a new vector clamped to length passed in

Parameters:
NameTypeAttributesDefaultDescription
lengthNumber<optional>
1
Returns:
Type: 
Vector2

copy() → {Vector2}

Returns a new vector that is a copy of this

Returns:
Type: 
Vector2

cross(v) → {Number}

Returns the cross product of this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

direction() → {Number}

Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

Returns:
Type: 
Number

distance(v) → {Number}

Returns the distance from this vector to vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

distanceSquared(v) → {Number}

Returns the distance squared from this vector to vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

divide(v) → {Vector2}

Returns a copy of this vector divided by the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

dot(v) → {Number}

Returns the dot product of this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Number

floor() → {Vector2}

Returns a copy of this vector with each axis floored

Returns:
Type: 
Vector2

invert() → {Vector2}

Returns a copy of this vector that has been inverted

Returns:
Type: 
Vector2

isValid() → {Boolean}

Checks if this is a valid vector

Returns:
Type: 
Boolean

length() → {Number}

Returns the length of this vector

Returns:
Type: 
Number

lengthSquared() → {Number}

Returns the length of this vector squared

Returns:
Type: 
Number

lerp(v, percent) → {Vector2}

Returns a new vector that is p percent between this and the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

percentNumber
Returns:
Type: 
Vector2

multiply(v) → {Vector2}

Returns a copy of this vector times the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

normalize(lengthopt) → {Vector2}

Returns a new vector in same direction as this one with the length passed in

Parameters:
NameTypeAttributesDefaultDescription
lengthNumber<optional>
1
Returns:
Type: 
Vector2

rotate(angle) → {Vector2}

Returns copy of this vector rotated by the angle passed in

Parameters:
NameTypeDescription
angleNumber
Returns:
Type: 
Vector2

scale(s) → {Vector2}

Returns a copy of this vector scaled by the vector passed in

Parameters:
NameTypeDescription
sNumber

scale

Returns:
Type: 
Vector2

set(xopt, yopt) → {Vector2}

Sets values of this vector and returns self

Parameters:
NameTypeAttributesDefaultDescription
xNumber<optional>
0

X axis location

yNumber<optional>
0

Y axis location

Returns:
Type: 
Vector2

setAngle(angleopt, lengthopt) → {Vector2}

Sets this vector with angle and length passed in

Parameters:
NameTypeAttributesDefaultDescription
angleNumber<optional>
0
lengthNumber<optional>
1
Returns:
Type: 
Vector2

setDirection(directionopt, lengthopt)

Set the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

Parameters:
NameTypeAttributesDefaultDescription
directionNumber<optional>
lengthNumber<optional>
1

subtract(v) → {Vector2}

Returns a copy of this vector minus the vector passed in

Parameters:
NameTypeDescription
vVector2

other vector

Returns:
Type: 
Vector2

toString(digits) → {String}

Returns this vector expressed as a string

Parameters:
NameTypeDefaultDescription
digitsNumber3

precision to display

Returns:
Type: 
String
\ No newline at end of file diff --git a/docs/data/search.json b/docs/data/search.json index 96cece68..c2f083fc 100644 --- a/docs/data/search.json +++ b/docs/data/search.json @@ -1 +1 @@ -{"list":[{"title":"Audio","link":"Audio","description":"

LittleJS Audio System

\n"},{"title":"Audio.audioContext","link":"audioContext","description":"

Audio context used by the engine

"},{"title":"Audio.audioGainNode","link":"audioGainNode","description":"

Master gain node for all audio to pass through

"},{"title":"Audio.getNoteFrequency","link":"getNoteFrequency","description":"

Get frequency of a note on a musical scale

"},{"title":"Audio.playAudioFile","link":"playAudioFile","description":"

Play an mp3, ogg, or wav audio from a local file or url

"},{"title":"Audio.playSamples","link":"playSamples","description":"

Play cached audio samples with given settings

"},{"title":"Audio.speak","link":"speak","description":"

Speak text with passed in settings

"},{"title":"Audio.speakStop","link":"speakStop","description":"

Stop all queued speech

"},{"title":"Audio.zzfx","link":"zzfx","description":"

Generate and play a ZzFX sound

\n

Create sounds using the ZzFX Sound Designer.

"},{"title":"Audio.zzfxG","link":"zzfxG","description":"

Generate samples for a ZzFX sound

"},{"title":"Audio.zzfxM","link":"zzfxM","description":"

Generate samples for a ZzFM song with given parameters

"},{"title":"Audio.zzfxR","link":"zzfxR","description":"

Sample rate used for all ZzFX sounds

"},{"title":"Color","link":"Color","description":"

Create a color with the rgba components passed in, white by default

"},{"title":"Color#HSLA","link":"HSLA","description":"

Returns this color expressed in hsla format

"},{"title":"Color#a","link":"a"},{"title":"Color#add","link":"add","description":"

Returns a copy of this color plus the color passed in

"},{"title":"Color#b","link":"b"},{"title":"Color#clamp","link":"clamp","description":"

Returns a copy of this color clamped to the valid range between 0 and 1

"},{"title":"Color#copy","link":"copy","description":"

Returns a new color that is a copy of this

"},{"title":"Color#divide","link":"divide","description":"

Returns a copy of this color divided by the color passed in

"},{"title":"Color#g","link":"g"},{"title":"Color#lerp","link":"lerp","description":"

Returns a new color that is p percent between this and the color passed in

"},{"title":"Color#multiply","link":"multiply","description":"

Returns a copy of this color times the color passed in

"},{"title":"Color#mutate","link":"mutate","description":"

Returns a new color that has each component randomly adjusted

"},{"title":"Color#r","link":"r"},{"title":"Color#rgbaInt","link":"rgbaInt","description":"

Returns this color expressed as 32 bit RGBA value

"},{"title":"Color#scale","link":"scale","description":"

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately

"},{"title":"Color#set","link":"set","description":"

Sets values of this color and returns self

"},{"title":"Color#setHSLA","link":"setHSLA","description":"

Sets this color given a hue, saturation, lightness, and alpha

"},{"title":"Color#setHex","link":"setHex","description":"

Set this color from a hex code

"},{"title":"Color#subtract","link":"subtract","description":"

Returns a copy of this color minus the color passed in

"},{"title":"Color#toString","link":"toString","description":"

Returns this color expressed as a hex color code

"},{"title":"Debug","link":"Debug","description":"

LittleJS Debug System

\n"},{"title":"Debug.ASSERT","link":"ASSERT","description":"

Asserts if the expression is false, does not do anything in release builds

"},{"title":"Debug.debug","link":"debug","description":"

True if debug is enabled

"},{"title":"Debug.debugCircle","link":"debugCircle","description":"

Draw a debug circle in world space

"},{"title":"Debug.debugClear","link":"debugClear","description":"

Clear all debug primitives in the list

"},{"title":"Debug.debugKey","link":"debugKey","description":"

Key code used to toggle debug mode, Esc by default

"},{"title":"Debug.debugLine","link":"debugLine","description":"

Draw a debug line in world space

"},{"title":"Debug.debugOverlap","link":"debugOverlap","description":"

Draw a debug combined axis aligned bounding box in world space

"},{"title":"Debug.debugOverlay","link":"debugOverlay","description":"

True if the debug overlay is active, always false in release builds

"},{"title":"Debug.debugPoint","link":"debugPoint","description":"

Draw a debug point in world space

"},{"title":"Debug.debugPointSize","link":"debugPointSize","description":"

Size to render debug points by default

"},{"title":"Debug.debugPoly","link":"debugPoly","description":"

Draw a debug poly in world space

"},{"title":"Debug.debugRect","link":"debugRect","description":"

Draw a debug rectangle in world space

"},{"title":"Debug.debugSaveCanvas","link":"debugSaveCanvas","description":"

Save a canvas to disk

"},{"title":"Debug.debugSaveDataURL","link":"debugSaveDataURL","description":"

Save a data url to disk

"},{"title":"Debug.debugSaveText","link":"debugSaveText","description":"

Save a text file to disk

"},{"title":"Debug.debugShowErrors","link":"debugShowErrors","description":"

Show error as full page of red text

"},{"title":"Debug.debugText","link":"debugText","description":"

Draw a debug axis aligned bounding box in world space

"},{"title":"Debug.enableAsserts","link":"enableAsserts","description":"

True if asserts are enaled

"},{"title":"Debug.setDebugKey","link":"setDebugKey","description":"

Set key code used to toggle debug mode, Esc by default

"},{"title":"Debug.setShowWatermark","link":"setShowWatermark","description":"

Set if watermark with FPS should be shown

"},{"title":"Debug.showWatermark","link":"showWatermark","description":"

True if watermark with FPS should be shown, false in release builds

"},{"title":"Draw","link":"Draw","description":"

LittleJS Drawing System

\n\n

LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.\nThere are 3 canvas/contexts available to draw to...\nmainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.\nglCanvas - Used by the accelerated WebGL batch rendering system.\noverlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.

\n

The WebGL rendering system is very fast with some caveats...

\n\n

The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!

"},{"title":"Draw.drawCanvas2D","link":"drawCanvas2D","description":"

Draw directly to a 2d canvas context in world space

"},{"title":"Draw.drawCircle","link":"drawCircle","description":"

Draw colored circle using passed in point

"},{"title":"Draw.drawEllipse","link":"drawEllipse","description":"

Draw colored ellipse using passed in point

"},{"title":"Draw.drawLine","link":"drawLine","description":"

Draw colored line between two points

"},{"title":"Draw.drawPoly","link":"drawPoly","description":"

Draw colored polygon using passed in points

"},{"title":"Draw.drawRect","link":"drawRect","description":"

Draw colored rect centered on pos

"},{"title":"Draw.drawText","link":"drawText","description":"

Draw text on overlay canvas in world space\nAutomatically splits new lines into rows

"},{"title":"Draw.drawTextScreen","link":"drawTextScreen","description":"

Draw text on overlay canvas in screen space\nAutomatically splits new lines into rows

"},{"title":"Draw.drawTile","link":"drawTile","description":"

Draw textured tile centered in world space, with color applied if using WebGL

"},{"title":"Draw.getCameraSize","link":"getCameraSize","description":"

Get the camera's visible area in world space

"},{"title":"Draw.isFullscreen","link":"isFullscreen","description":"

Returns true if fullscreen mode is active

"},{"title":"Draw.mainCanvas","link":"mainCanvas","description":"

The primary 2D canvas visible to the user

"},{"title":"Draw.mainCanvasSize","link":"mainCanvasSize","description":"

The size of the main canvas (and other secondary canvases)

"},{"title":"Draw.mainContext","link":"mainContext","description":"

2d context for mainCanvas

"},{"title":"Draw.overlayCanvas","link":"overlayCanvas","description":"

A canvas that appears on top of everything the same size as mainCanvas

"},{"title":"Draw.overlayContext","link":"overlayContext","description":"

2d context for overlayCanvas

"},{"title":"Draw.screenToWorld","link":"screenToWorld","description":"

Convert from screen to world space coordinates

"},{"title":"Draw.setBlendMode","link":"setBlendMode","description":"

Enable normal or additive blend mode

"},{"title":"Draw.textureInfos","link":"textureInfos","description":"

Array containing texture info for batch rendering system

"},{"title":"Draw.tile","link":"tile","description":"

Create a tile info object using a grid based system

\n"},{"title":"Draw.toggleFullscreen","link":"toggleFullscreen","description":"

Toggle fullsceen mode

"},{"title":"Draw.worldToScreen","link":"worldToScreen","description":"

Convert from world to screen space coordinates

"},{"title":"Engine","link":"Engine","description":"

LittleJS - The Tiny Fast JavaScript Game Engine\nMIT License - Copyright 2021 Frank Force

\n

Engine Features

\n"},{"title":"Engine.engineAddPlugin","link":"engineAddPlugin","description":"

Add a new update function for a plugin

"},{"title":"Engine.engineInit","link":"engineInit","description":"

Startup LittleJS engine with your callback functions

"},{"title":"Engine.engineName","link":"engineName","description":"

Name of engine

"},{"title":"Engine.engineObjects","link":"engineObjects","description":"

Array containing all engine objects

"},{"title":"Engine.engineObjectsCallback","link":"engineObjectsCallback","description":"

Triggers a callback for each object within a given area

"},{"title":"Engine.engineObjectsCollect","link":"engineObjectsCollect","description":"

Collects all object within a given area

"},{"title":"Engine.engineObjectsCollide","link":"engineObjectsCollide","description":"

Array with only objects set to collide with other objects this frame (for optimization)

"},{"title":"Engine.engineObjectsDestroy","link":"engineObjectsDestroy","description":"

Destroy and remove all objects

"},{"title":"Engine.engineObjectsRaycast","link":"engineObjectsRaycast","description":"

Return a list of objects intersecting a ray

"},{"title":"Engine.engineObjectsUpdate","link":"engineObjectsUpdate","description":"

Update each engine object, remove destroyed objects, and update time

"},{"title":"Engine.engineVersion","link":"engineVersion","description":"

Version of engine

"},{"title":"Engine.frame","link":"frame","description":"

Current update frame, used to calculate time

"},{"title":"Engine.frameRate","link":"frameRate","description":"

Frames per second to update

"},{"title":"Engine.paused","link":"paused","description":"

Is the game paused? Causes time and objects to not be updated

"},{"title":"Engine.setPaused","link":"setPaused","description":"

Set if game is paused

"},{"title":"Engine.time","link":"time","description":"

Current engine time since start in seconds

"},{"title":"Engine.timeDelta","link":"timeDelta","description":"

How many seconds each frame lasts, engine uses a fixed time step

"},{"title":"Engine.timeReal","link":"timeReal","description":"

Actual clock time since start in seconds (not affected by pause or frame rate clamping)

"},{"title":"EngineObject","link":"EngineObject","description":"

Create an engine object and adds it to the list of objects

"},{"title":"EngineObject#addChild","link":"addChild","description":"

Attaches a child to this with a given local transform

"},{"title":"EngineObject#additiveColor","link":"additiveColor"},{"title":"EngineObject#angle","link":"angle"},{"title":"EngineObject#angleDamping","link":"angleDamping"},{"title":"EngineObject#angleVelocity","link":"angleVelocity"},{"title":"EngineObject#applyAcceleration","link":"applyAcceleration","description":"

Apply acceleration to this object (adjust velocity, not affected by mass)

"},{"title":"EngineObject#applyForce","link":"applyForce","description":"

Apply force to this object (adjust velocity, affected by mass)

"},{"title":"EngineObject#children","link":"children"},{"title":"EngineObject#clampSpeedLinear","link":"clampSpeedLinear"},{"title":"EngineObject#collideRaycast","link":"collideRaycast"},{"title":"EngineObject#collideSolidObjects","link":"collideSolidObjects"},{"title":"EngineObject#collideTiles","link":"collideTiles"},{"title":"EngineObject#collideWithObject","link":"collideWithObject","description":"

Called to check if a object collision should be resolved

"},{"title":"EngineObject#collideWithTile","link":"collideWithTile","description":"

Called to check if a tile collision should be resolved

"},{"title":"EngineObject#color","link":"color"},{"title":"EngineObject#damping","link":"damping"},{"title":"EngineObject#destroy","link":"destroy","description":"

Destroy this object, destroy it's children, detach it's parent, and mark it for removal

"},{"title":"EngineObject#drawSize","link":"drawSize"},{"title":"EngineObject#elasticity","link":"elasticity"},{"title":"EngineObject#friction","link":"friction"},{"title":"EngineObject#getAliveTime","link":"getAliveTime","description":"

How long since the object was created

"},{"title":"EngineObject#getMirrorSign","link":"getMirrorSign","description":"

Get the direction of the mirror

"},{"title":"EngineObject#gravityScale","link":"gravityScale"},{"title":"EngineObject#isSolid","link":"isSolid"},{"title":"EngineObject#localAngle","link":"localAngle"},{"title":"EngineObject#localPos","link":"localPos"},{"title":"EngineObject#localToWorld","link":"localToWorld","description":"

Convert from local space to world space

"},{"title":"EngineObject#localToWorldVector","link":"localToWorldVector","description":"

Convert from local space to world space for a vector (rotation only)

"},{"title":"EngineObject#mass","link":"mass"},{"title":"EngineObject#mirror","link":"mirror"},{"title":"EngineObject#parent","link":"parent"},{"title":"EngineObject#pos","link":"pos"},{"title":"EngineObject#removeChild","link":"removeChild","description":"

Removes a child from this one

"},{"title":"EngineObject#render","link":"render","description":"

Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder

"},{"title":"EngineObject#renderDebugInfo","link":"renderDebugInfo","description":"

Render debug info for this object

"},{"title":"EngineObject#renderOrder","link":"renderOrder"},{"title":"EngineObject#setCollision","link":"setCollision","description":"

Set how this object collides

"},{"title":"EngineObject#size","link":"size"},{"title":"EngineObject#spawnTime","link":"spawnTime"},{"title":"EngineObject#tileInfo","link":"tileInfo"},{"title":"EngineObject#toString","link":"toString","description":"

Returns string containg info about this object for debugging

"},{"title":"EngineObject#update","link":"update","description":"

Update the object physics, called automatically by engine once each frame

"},{"title":"EngineObject#updateTransforms","link":"updateTransforms","description":"

Update the object transform, called automatically by engine even when paused

"},{"title":"EngineObject#velocity","link":"velocity"},{"title":"EngineObject#worldToLocal","link":"worldToLocal","description":"

Convert from world space to local space

"},{"title":"EngineObject#worldToLocalVector","link":"worldToLocalVector","description":"

Convert from world space to local space for a vector (rotation only)

"},{"title":"FontImage","link":"FontImage","description":"

Create an image font

"},{"title":"FontImage#drawText","link":"drawText","description":"

Draw text in world space using the image font

"},{"title":"FontImage#drawTextScreen","link":"drawTextScreen","description":"

Draw text in screen space using the image font

"},{"title":"Input","link":"Input","description":"

LittleJS Input System

\n"},{"title":"Input.clearInput","link":"clearInput","description":"

Clears all input

"},{"title":"Input.gamepadIsDown","link":"gamepadIsDown","description":"

Returns true if gamepad button is down

"},{"title":"Input.gamepadStick","link":"gamepadStick","description":"

Returns gamepad stick value

"},{"title":"Input.gamepadWasPressed","link":"gamepadWasPressed","description":"

Returns true if gamepad button was pressed

"},{"title":"Input.gamepadWasReleased","link":"gamepadWasReleased","description":"

Returns true if gamepad button was released

"},{"title":"Input.isTouchDevice","link":"isTouchDevice","description":"

True if a touch device has been detected

"},{"title":"Input.isUsingGamepad","link":"isUsingGamepad","description":"

Returns true if user is using gamepad (has more recently pressed a gamepad button)

"},{"title":"Input.keyIsDown","link":"keyIsDown","description":"

Returns true if device key is down

"},{"title":"Input.keyWasPressed","link":"keyWasPressed","description":"

Returns true if device key was pressed this frame

"},{"title":"Input.keyWasReleased","link":"keyWasReleased","description":"

Returns true if device key was released this frame

"},{"title":"Input.mouseIsDown","link":"mouseIsDown","description":"

Returns true if mouse button is down

"},{"title":"Input.mousePos","link":"mousePos","description":"

Mouse pos in world space

"},{"title":"Input.mousePosScreen","link":"mousePosScreen","description":"

Mouse pos in screen space

"},{"title":"Input.mouseWasPressed","link":"mouseWasPressed","description":"

Returns true if mouse button was pressed

"},{"title":"Input.mouseWasReleased","link":"mouseWasReleased","description":"

Returns true if mouse button was released

"},{"title":"Input.mouseWheel","link":"mouseWheel","description":"

Mouse wheel delta this frame

"},{"title":"Input.preventDefaultInput","link":"preventDefaultInput","description":"

Prevents input continuing to the default browser handling (false by default)

"},{"title":"Input.vibrate","link":"vibrate","description":"

Pulse the vibration hardware if it exists

"},{"title":"Input.vibrateStop","link":"vibrateStop","description":"

Cancel any ongoing vibration

"},{"title":"Medal","link":"Medal","description":"

Create a medal object and adds it to the list of medals

"},{"title":"Medal#description","link":"description"},{"title":"Medal#icon","link":"icon"},{"title":"Medal#id","link":"id"},{"title":"Medal#name","link":"name"},{"title":"Medal#render","link":"render","description":"

Render a medal

"},{"title":"Medal#renderIcon","link":"renderIcon","description":"

Render the icon for a medal

"},{"title":"Medal#unlock","link":"unlock","description":"

Unlocks a medal if not already unlocked

"},{"title":"Medal#unlocked","link":"unlocked"},{"title":"Medals","link":"Medals","description":"

LittleJS Medal System

\n"},{"title":"Medals.medals","link":"medals","description":"

List of all medals

"},{"title":"Medals.medalsForEach","link":"medalsForEach","description":"

Calls a function for each medal

"},{"title":"Medals.medalsInit","link":"medalsInit","description":"

Initialize medals with a save name used for storage

\n"},{"title":"Music","link":"Music","description":"

Create a music object and cache the zzfx music samples for later use

"},{"title":"Music#playMusic","link":"playMusic","description":"

Play the music

"},{"title":"Particle","link":"Particle","description":"

Create a particle with the passed in settings\nTypically this is created automatically by a ParticleEmitter

"},{"title":"Particle#additive","link":"additive"},{"title":"Particle#colorEndDelta","link":"colorEndDelta"},{"title":"Particle#colorStart","link":"colorStart"},{"title":"Particle#destroyCallback","link":"destroyCallback"},{"title":"Particle#fadeRate","link":"fadeRate"},{"title":"Particle#lifeTime","link":"lifeTime"},{"title":"Particle#localSpaceEmitter","link":"localSpaceEmitter"},{"title":"Particle#render","link":"render","description":"

Render the particle, automatically called each frame, sorted by renderOrder

"},{"title":"Particle#sizeEndDelta","link":"sizeEndDelta"},{"title":"Particle#sizeStart","link":"sizeStart"},{"title":"Particle#trailScale","link":"trailScale"},{"title":"ParticleEmitter","link":"ParticleEmitter","description":"

Create a particle system with the given settings

"},{"title":"ParticleEmitter#additive","link":"additive"},{"title":"ParticleEmitter#angleDamping","link":"angleDamping"},{"title":"ParticleEmitter#angleSpeed","link":"angleSpeed"},{"title":"ParticleEmitter#collideTiles","link":"collideTiles"},{"title":"ParticleEmitter#colorEndA","link":"colorEndA"},{"title":"ParticleEmitter#colorEndB","link":"colorEndB"},{"title":"ParticleEmitter#colorStartA","link":"colorStartA"},{"title":"ParticleEmitter#colorStartB","link":"colorStartB"},{"title":"ParticleEmitter#damping","link":"damping"},{"title":"ParticleEmitter#emitConeAngle","link":"emitConeAngle"},{"title":"ParticleEmitter#emitParticle","link":"emitParticle","description":"

Spawn one particle

"},{"title":"ParticleEmitter#emitRate","link":"emitRate"},{"title":"ParticleEmitter#emitSize","link":"emitSize"},{"title":"ParticleEmitter#emitTime","link":"emitTime"},{"title":"ParticleEmitter#emitTimeBuffer","link":"emitTimeBuffer"},{"title":"ParticleEmitter#fadeRate","link":"fadeRate"},{"title":"ParticleEmitter#gravityScale","link":"gravityScale"},{"title":"ParticleEmitter#localSpace","link":"localSpace"},{"title":"ParticleEmitter#particleConeAngle","link":"particleConeAngle"},{"title":"ParticleEmitter#particleCreateCallback","link":"particleCreateCallback"},{"title":"ParticleEmitter#particleDestroyCallback","link":"particleDestroyCallback"},{"title":"ParticleEmitter#particleTime","link":"particleTime"},{"title":"ParticleEmitter#randomColorLinear","link":"randomColorLinear"},{"title":"ParticleEmitter#randomness","link":"randomness"},{"title":"ParticleEmitter#sizeEnd","link":"sizeEnd"},{"title":"ParticleEmitter#sizeStart","link":"sizeStart"},{"title":"ParticleEmitter#speed","link":"speed"},{"title":"ParticleEmitter#trailScale","link":"trailScale"},{"title":"ParticleEmitter#update","link":"update","description":"

Update the emitter to spawn particles, called automatically by engine once each frame

"},{"title":"Random","link":"Random","description":"

Random global functions

"},{"title":"Random.rand","link":"rand","description":"

Returns a random value between the two values passed in

"},{"title":"Random.randColor","link":"randColor","description":"

Returns a random color between the two passed in colors, combine components if linear

"},{"title":"Random.randInCircle","link":"randInCircle","description":"

Returns a random Vector2 within a circular shape

"},{"title":"Random.randInt","link":"randInt","description":"

Returns a floored random value between the two values passed in\nThe upper bound is exclusive. (If 2 is passed in, result will be 0 or 1)

"},{"title":"Random.randSign","link":"randSign","description":"

Randomly returns either -1 or 1

"},{"title":"Random.randVector","link":"randVector","description":"

Returns a random Vector2 with the passed in length

"},{"title":"RandomGenerator","link":"RandomGenerator","description":"

Create a random number generator with the seed passed in

"},{"title":"RandomGenerator#float","link":"float","description":"

Returns a seeded random value between the two values passed in

"},{"title":"RandomGenerator#int","link":"int","description":"

Returns a floored seeded random value the two values passed in

"},{"title":"RandomGenerator#seed","link":"seed"},{"title":"RandomGenerator#sign","link":"sign","description":"

Randomly returns either -1 or 1 deterministically

"},{"title":"Settings","link":"Settings","description":"

LittleJS Engine Settings

\n"},{"title":"Settings.cameraPos","link":"cameraPos","description":"

Position of camera in world space

"},{"title":"Settings.cameraScale","link":"cameraScale","description":"

Scale of camera in world space

"},{"title":"Settings.canvasFixedSize","link":"canvasFixedSize","description":"

Fixed size of the canvas, if enabled canvas size never changes

\n"},{"title":"Settings.canvasMaxSize","link":"canvasMaxSize","description":"

The max size of the canvas, centered if window is larger

"},{"title":"Settings.canvasPixelated","link":"canvasPixelated","description":"

Disables filtering for crisper pixel art if true

"},{"title":"Settings.enablePhysicsSolver","link":"enablePhysicsSolver","description":"

Enable physics solver for collisions between objects

"},{"title":"Settings.fontDefault","link":"fontDefault","description":"

Default font used for text rendering

"},{"title":"Settings.gamepadDirectionEmulateStick","link":"gamepadDirectionEmulateStick","description":"

If true, the dpad input is also routed to the left analog stick (for better accessability)

"},{"title":"Settings.gamepadsEnable","link":"gamepadsEnable","description":"

Should gamepads be allowed

"},{"title":"Settings.glEnable","link":"glEnable","description":"

Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)

"},{"title":"Settings.glOverlay","link":"glOverlay","description":"

Fixes slow rendering in some browsers by not compositing the WebGL canvas

"},{"title":"Settings.gravity","link":"gravity","description":"

How much gravity to apply to objects along the Y axis, negative is down

"},{"title":"Settings.headlessMode","link":"headlessMode","description":"

Disables all rendering, audio, and input for servers

"},{"title":"Settings.inputWASDEmulateDirection","link":"inputWASDEmulateDirection","description":"

If true the WASD keys are also routed to the direction keys (for better accessability)

"},{"title":"Settings.medalDisplayIconSize","link":"medalDisplayIconSize","description":"

Size of icon in medal display

"},{"title":"Settings.medalDisplaySize","link":"medalDisplaySize","description":"

Size of medal display

"},{"title":"Settings.medalDisplaySlideTime","link":"medalDisplaySlideTime","description":"

How quickly to slide on/off medals in seconds

"},{"title":"Settings.medalDisplayTime","link":"medalDisplayTime","description":"

How long to show medals for in seconds

"},{"title":"Settings.medalsPreventUnlock","link":"medalsPreventUnlock","description":"

Set to stop medals from being unlockable (like if cheats are enabled)

"},{"title":"Settings.objectDefaultAngleDamping","link":"objectDefaultAngleDamping","description":"

How much to slow angular velocity each frame (0-1)

"},{"title":"Settings.objectDefaultDamping","link":"objectDefaultDamping","description":"

How much to slow velocity by each frame (0-1)

"},{"title":"Settings.objectDefaultElasticity","link":"objectDefaultElasticity","description":"

How much to bounce when a collision occurs (0-1)

"},{"title":"Settings.objectDefaultFriction","link":"objectDefaultFriction","description":"

How much to slow when touching (0-1)

"},{"title":"Settings.objectDefaultMass","link":"objectDefaultMass","description":"

Default object mass for collision calcuations (how heavy objects are)

"},{"title":"Settings.objectMaxSpeed","link":"objectMaxSpeed","description":"

Clamp max speed to avoid fast objects missing collisions

"},{"title":"Settings.particleEmitRateScale","link":"particleEmitRateScale","description":"

Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)

"},{"title":"Settings.setCameraPos","link":"setCameraPos","description":"

Set position of camera in world space

"},{"title":"Settings.setCameraScale","link":"setCameraScale","description":"

Set scale of camera in world space

"},{"title":"Settings.setCanvasFixedSize","link":"setCanvasFixedSize","description":"

Set fixed size of the canvas

"},{"title":"Settings.setCanvasMaxSize","link":"setCanvasMaxSize","description":"

Set max size of the canvas

"},{"title":"Settings.setCanvasPixelated","link":"setCanvasPixelated","description":"

Disables anti aliasing for pixel art if true

"},{"title":"Settings.setEnablePhysicsSolver","link":"setEnablePhysicsSolver","description":"

Set if collisions between objects are enabled

"},{"title":"Settings.setFontDefault","link":"setFontDefault","description":"

Set default font used for text rendering

"},{"title":"Settings.setGamepadDirectionEmulateStick","link":"setGamepadDirectionEmulateStick","description":"

Set if the dpad input is also routed to the left analog stick

"},{"title":"Settings.setGamepadsEnable","link":"setGamepadsEnable","description":"

Set if gamepads are enabled

"},{"title":"Settings.setGlEnable","link":"setGlEnable","description":"

Set if webgl rendering is enabled

"},{"title":"Settings.setGlOverlay","link":"setGlOverlay","description":"

Set to not composite the WebGL canvas

"},{"title":"Settings.setGravity","link":"setGravity","description":"

Set how much gravity to apply to objects along the Y axis

"},{"title":"Settings.setHeadlessMode","link":"setHeadlessMode","description":"

Set to disalbe rendering, audio, and input for servers

"},{"title":"Settings.setInputWASDEmulateDirection","link":"setInputWASDEmulateDirection","description":"

Set if true the WASD keys are also routed to the direction keys

"},{"title":"Settings.setMedalDisplayIconSize","link":"setMedalDisplayIconSize","description":"

Set size of icon in medal display

"},{"title":"Settings.setMedalDisplaySize","link":"setMedalDisplaySize","description":"

Set size of medal display

"},{"title":"Settings.setMedalDisplaySlideTime","link":"setMedalDisplaySlideTime","description":"

Set how quickly to slide on/off medals in seconds

"},{"title":"Settings.setMedalDisplayTime","link":"setMedalDisplayTime","description":"

Set how long to show medals for in seconds

"},{"title":"Settings.setMedalsPreventUnlock","link":"setMedalsPreventUnlock","description":"

Set to stop medals from being unlockable

"},{"title":"Settings.setObjectDefaultAngleDamping","link":"setObjectDefaultAngleDamping","description":"

Set how much to slow angular velocity each frame

"},{"title":"Settings.setObjectDefaultDamping","link":"setObjectDefaultDamping","description":"

Set how much to slow velocity by each frame

"},{"title":"Settings.setObjectDefaultElasticity","link":"setObjectDefaultElasticity","description":"

Set how much to bounce when a collision occur

"},{"title":"Settings.setObjectDefaultFriction","link":"setObjectDefaultFriction","description":"

Set how much to slow when touching

"},{"title":"Settings.setObjectDefaultMass","link":"setObjectDefaultMass","description":"

Set default object mass for collison calcuations

"},{"title":"Settings.setObjectMaxSpeed","link":"setObjectMaxSpeed","description":"

Set max speed to avoid fast objects missing collisions

"},{"title":"Settings.setParticleEmitRateScale","link":"setParticleEmitRateScale","description":"

Set to scales emit rate of particles

"},{"title":"Settings.setShowSplashScreen","link":"setShowSplashScreen","description":"

Set if the LittleJS splash screen be shown on startup

"},{"title":"Settings.setSoundDefaultRange","link":"setSoundDefaultRange","description":"

Set default range where sound no longer plays

"},{"title":"Settings.setSoundDefaultTaper","link":"setSoundDefaultTaper","description":"

Set default range percent to start tapering off sound

"},{"title":"Settings.setSoundEnable","link":"setSoundEnable","description":"

Set to disable all audio code

"},{"title":"Settings.setSoundVolume","link":"setSoundVolume","description":"

Set volume scale to apply to all sound, music and speech

"},{"title":"Settings.setTileFixBleedScale","link":"setTileFixBleedScale","description":"

Set to prevent tile bleeding from neighbors in pixels

"},{"title":"Settings.setTileSizeDefault","link":"setTileSizeDefault","description":"

Set default size of tiles in pixels

"},{"title":"Settings.setTouchGamepadAlpha","link":"setTouchGamepadAlpha","description":"

Set transparency of touch gamepad overlay

"},{"title":"Settings.setTouchGamepadAnalog","link":"setTouchGamepadAnalog","description":"

Set if touch gamepad should be analog stick or 8 way dpad

"},{"title":"Settings.setTouchGamepadEnable","link":"setTouchGamepadEnable","description":"

Set if touch gamepad should appear on mobile devices

"},{"title":"Settings.setTouchGamepadSize","link":"setTouchGamepadSize","description":"

Set size of virutal gamepad for touch devices in pixels

"},{"title":"Settings.setTouchInputEnable","link":"setTouchInputEnable","description":"

Set if touch input is allowed

"},{"title":"Settings.setVibrateEnable","link":"setVibrateEnable","description":"

Set to allow vibration hardware if it exists

"},{"title":"Settings.showSplashScreen","link":"showSplashScreen","description":"

Enable to show the LittleJS splash screen be shown on startup

"},{"title":"Settings.soundDefaultRange","link":"soundDefaultRange","description":"

Default range where sound no longer plays

"},{"title":"Settings.soundDefaultTaper","link":"soundDefaultTaper","description":"

Default range percent to start tapering off sound (0-1)

"},{"title":"Settings.soundEnable","link":"soundEnable","description":"

All audio code can be disabled and removed from build

"},{"title":"Settings.soundVolume","link":"soundVolume","description":"

Volume scale to apply to all sound, music and speech

"},{"title":"Settings.tileFixBleedScale","link":"tileFixBleedScale","description":"

How many pixels smaller to draw tiles to prevent bleeding from neighbors

"},{"title":"Settings.tileSizeDefault","link":"tileSizeDefault","description":"

Default size of tiles in pixels

"},{"title":"Settings.touchGamepadAlpha","link":"touchGamepadAlpha","description":"

Transparency of touch gamepad overlay

"},{"title":"Settings.touchGamepadAnalog","link":"touchGamepadAnalog","description":"

True if touch gamepad should be analog stick or false to use if 8 way dpad

"},{"title":"Settings.touchGamepadEnable","link":"touchGamepadEnable","description":"

True if touch gamepad should appear on mobile devices

\n"},{"title":"Settings.touchGamepadSize","link":"touchGamepadSize","description":"

Size of virtual gamepad for touch devices in pixels

"},{"title":"Settings.touchInputEnable","link":"touchInputEnable","description":"

True if touch input is enabled for mobile devices

\n"},{"title":"Settings.vibrateEnable","link":"vibrateEnable","description":"

Allow vibration hardware if it exists

"},{"title":"Sound","link":"Sound","description":"

Create a sound object and cache the zzfx samples for later use

"},{"title":"Sound#gainNode","link":"gainNode"},{"title":"Sound#getDuration","link":"getDuration","description":"

Get how long this sound is in seconds

"},{"title":"Sound#getSource","link":"getSource","description":"

Get source of most recent instance of this sound that was played

"},{"title":"Sound#isLoading","link":"isLoading","description":"

Check if sound is loading, for sounds fetched from a url

"},{"title":"Sound#play","link":"play","description":"

Play the sound

"},{"title":"Sound#playNote","link":"playNote","description":"

Play the sound as a note with a semitone offset

"},{"title":"Sound#randomness","link":"randomness"},{"title":"Sound#range","link":"range"},{"title":"Sound#setVolume","link":"setVolume","description":"

Set the sound volume

"},{"title":"Sound#stop","link":"stop","description":"

Stop the last instance of this sound that was played

"},{"title":"Sound#taper","link":"taper"},{"title":"SoundWave","link":"SoundWave","description":"

Create a sound object and cache the wave file for later use

"},{"title":"TextureInfo","link":"TextureInfo","description":"

Create a TextureInfo, called automatically by the engine

"},{"title":"TextureInfo#glTexture","link":"glTexture"},{"title":"TextureInfo#image","link":"image"},{"title":"TextureInfo#size","link":"size"},{"title":"TileCollision","link":"TileCollision","description":"

LittleJS Tile Layer System

\n"},{"title":"TileCollision.getTileCollisionData","link":"getTileCollisionData","description":"

Get tile collision data

"},{"title":"TileCollision.initTileCollision","link":"initTileCollision","description":"

Clear and initialize tile collision

"},{"title":"TileCollision.setTileCollisionData","link":"setTileCollisionData","description":"

Set tile collision data

"},{"title":"TileCollision.tileCollision","link":"tileCollision","description":"

The tile collision layer array, use setTileCollisionData and getTileCollisionData to access

"},{"title":"TileCollision.tileCollisionRaycast","link":"tileCollisionRaycast","description":"

Return the center of first tile hit (does not return the exact intersection)

"},{"title":"TileCollision.tileCollisionSize","link":"tileCollisionSize","description":"

Size of the tile collision layer

"},{"title":"TileCollision.tileCollisionTest","link":"tileCollisionTest","description":"

Check if collision with another object should occur

"},{"title":"TileInfo","link":"TileInfo","description":"

Create a tile info object

"},{"title":"TileInfo#frame","link":"frame","description":"

Returns a copy of this tile offset by a number of animation frames

"},{"title":"TileInfo#getTextureInfo","link":"getTextureInfo","description":"

Returns the texture info for this tile

"},{"title":"TileInfo#offset","link":"offset","description":"

Returns a copy of this tile offset by a vector

"},{"title":"TileInfo#padding","link":"padding"},{"title":"TileInfo#pos","link":"pos"},{"title":"TileInfo#size","link":"size"},{"title":"TileInfo#textureIndex","link":"textureIndex"},{"title":"TileLayer","link":"TileLayer","description":"

Create a tile layer object

"},{"title":"TileLayer#canvas","link":"canvas"},{"title":"TileLayer#context","link":"context"},{"title":"TileLayer#drawCanvas2D","link":"drawCanvas2D","description":"

Draw directly to the 2D canvas in world space (bipass webgl)

"},{"title":"TileLayer#drawRect","link":"drawRect","description":"

Draw a rectangle directly onto the layer canvas in world space

"},{"title":"TileLayer#drawTile","link":"drawTile","description":"

Draw a tile directly onto the layer canvas in world space

"},{"title":"TileLayer#drawTileData","link":"drawTileData","description":"

Draw the tile at a given position in the tile grid\nThis can be used to clear out tiles when they are destroyed\nTiles can also be redrawn if isinde a redrawStart/End block

"},{"title":"TileLayer#getData","link":"getData","description":"

Get data at a given position in the array

"},{"title":"TileLayer#isOverlay","link":"isOverlay"},{"title":"TileLayer#redraw","link":"redraw","description":"

Draw all the tile data to an offscreen canvas

\n"},{"title":"TileLayer#redrawEnd","link":"redrawEnd","description":"

Call to end the redraw process

"},{"title":"TileLayer#redrawStart","link":"redrawStart","description":"

Call to start the redraw process

\n"},{"title":"TileLayer#savedRenderSettings","link":"savedRenderSettings"},{"title":"TileLayer#scale","link":"scale"},{"title":"TileLayer#setData","link":"setData","description":"

Set data at a given position in the array

"},{"title":"TileLayerData","link":"TileLayerData","description":"

Create a tile layer data object, one for each tile in a TileLayer

"},{"title":"TileLayerData#clear","link":"clear","description":"

Set this tile to clear, it will not be rendered

"},{"title":"TileLayerData#color","link":"color"},{"title":"TileLayerData#direction","link":"direction"},{"title":"TileLayerData#mirror","link":"mirror"},{"title":"TileLayerData#tile","link":"tile"},{"title":"Timer","link":"Timer","description":"

Create a timer object set time passed in

"},{"title":"Timer#active","link":"active","description":"

Returns true if set and has not elapsed

"},{"title":"Timer#elapsed","link":"elapsed","description":"

Returns true if set and elapsed

"},{"title":"Timer#get","link":"get","description":"

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

"},{"title":"Timer#getPercent","link":"getPercent","description":"

Get percentage elapsed based on time it was set to, returns 0 if not set

"},{"title":"Timer#isSet","link":"isSet","description":"

Returns true if set

"},{"title":"Timer#set","link":"set","description":"

Set the timer with seconds passed in

"},{"title":"Timer#toString","link":"toString","description":"

Returns this timer expressed as a string

"},{"title":"Timer#unset","link":"unset","description":"

Unset the timer

"},{"title":"Timer#valueOf","link":"valueOf","description":"

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

"},{"title":"Utilities","link":"Utilities","description":"

LittleJS Utility Classes and Functions

\n"},{"title":"Utilities.BLACK","link":"BLACK","description":"

Color - Black

"},{"title":"Utilities.BLUE","link":"BLUE","description":"

Color - Blue

"},{"title":"Utilities.CYAN","link":"CYAN","description":"

Color - Cyan

"},{"title":"Utilities.GRAY","link":"GRAY","description":"

Color - Gray

"},{"title":"Utilities.GREEN","link":"GREEN","description":"

Color - Green

"},{"title":"Utilities.MAGENTA","link":"MAGENTA","description":"

Color - Magenta

"},{"title":"Utilities.ORANGE","link":"ORANGE","description":"

Color - Orange

"},{"title":"Utilities.PI","link":"PI","description":"

A shortcut to get Math.PI

"},{"title":"Utilities.PURPLE","link":"PURPLE","description":"

Color - Purple

"},{"title":"Utilities.RED","link":"RED","description":"

Color - Red

"},{"title":"Utilities.WHITE","link":"WHITE","description":"

Color - White

"},{"title":"Utilities.YELLOW","link":"YELLOW","description":"

Color - Yellow

"},{"title":"Utilities.abs","link":"abs","description":"

Returns absoulte value of value passed in

"},{"title":"Utilities.clamp","link":"clamp","description":"

Clamps the value beween max and min

"},{"title":"Utilities.distanceAngle","link":"distanceAngle","description":"

Returns signed wrapped distance between the two angles passed in

"},{"title":"Utilities.distanceWrap","link":"distanceWrap","description":"

Returns signed wrapped distance between the two values passed in

"},{"title":"Utilities.formatTime","link":"formatTime","description":"

Formats seconds to mm:ss style for display purposes

"},{"title":"Utilities.hsl","link":"hsl","description":"

Create a color object with HSLA values, white by default

"},{"title":"Utilities.isColor","link":"isColor","description":"

Check if object is a valid Color

"},{"title":"Utilities.isIntersecting","link":"isIntersecting","description":"

Returns true if a line segment is intersecting an axis aligned box

"},{"title":"Utilities.isOverlapping","link":"isOverlapping","description":"

Returns true if two axis aligned bounding boxes are overlapping

"},{"title":"Utilities.isVector2","link":"isVector2","description":"

Check if object is a valid Vector2

"},{"title":"Utilities.lerp","link":"lerp","description":"

Linearly interpolates between values passed in using percent

"},{"title":"Utilities.lerpAngle","link":"lerpAngle","description":"

Linearly interpolates between the angles passed in with wrapping

"},{"title":"Utilities.lerpWrap","link":"lerpWrap","description":"

Linearly interpolates between values passed in with wrapping

"},{"title":"Utilities.max","link":"max","description":"

Returns highest of two values passed in

"},{"title":"Utilities.min","link":"min","description":"

Returns lowest of two values passed in

"},{"title":"Utilities.mod","link":"mod","description":"

Returns first parm modulo the second param, but adjusted so negative numbers work as expected

"},{"title":"Utilities.nearestPowerOfTwo","link":"nearestPowerOfTwo","description":"

Returns the nearest power of two not less then the value

"},{"title":"Utilities.percent","link":"percent","description":"

Returns what percentage the value is between valueA and valueB

"},{"title":"Utilities.rgb","link":"rgb","description":"

Create a color object with RGBA values, white by default

"},{"title":"Utilities.sign","link":"sign","description":"

Returns the sign of value passed in

"},{"title":"Utilities.smoothStep","link":"smoothStep","description":"

Applies smoothstep function to the percentage value

"},{"title":"Utilities.vec2","link":"vec2","description":"

Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar

"},{"title":"Utilities.wave","link":"wave","description":"

Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default

"},{"title":"Vector2","link":"Vector2","description":"

Create a 2D vector with the x and y passed in, can also be created with vec2()

"},{"title":"Vector2#add","link":"add","description":"

Returns a copy of this vector plus the vector passed in

"},{"title":"Vector2#angle","link":"angle","description":"

Returns the angle of this vector, up is angle 0

"},{"title":"Vector2#area","link":"area","description":"

Returns the area this vector covers as a rectangle

"},{"title":"Vector2#arrayCheck","link":"arrayCheck","description":"

Returns true if this vector is within the bounds of an array size passed in

"},{"title":"Vector2#clampLength","link":"clampLength","description":"

Returns a new vector clamped to length passed in

"},{"title":"Vector2#copy","link":"copy","description":"

Returns a new vector that is a copy of this

"},{"title":"Vector2#cross","link":"cross","description":"

Returns the cross product of this and the vector passed in

"},{"title":"Vector2#direction","link":"direction","description":"

Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

"},{"title":"Vector2#distance","link":"distance","description":"

Returns the distance from this vector to vector passed in

"},{"title":"Vector2#distanceSquared","link":"distanceSquared","description":"

Returns the distance squared from this vector to vector passed in

"},{"title":"Vector2#divide","link":"divide","description":"

Returns a copy of this vector divided by the vector passed in

"},{"title":"Vector2#dot","link":"dot","description":"

Returns the dot product of this and the vector passed in

"},{"title":"Vector2#floor","link":"floor","description":"

Returns a copy of this vector with each axis floored

"},{"title":"Vector2#invert","link":"invert","description":"

Returns a copy of this vector that has been inverted

"},{"title":"Vector2#length","link":"length","description":"

Returns the length of this vector

"},{"title":"Vector2#lengthSquared","link":"lengthSquared","description":"

Returns the length of this vector squared

"},{"title":"Vector2#lerp","link":"lerp","description":"

Returns a new vector that is p percent between this and the vector passed in

"},{"title":"Vector2#multiply","link":"multiply","description":"

Returns a copy of this vector times the vector passed in

"},{"title":"Vector2#normalize","link":"normalize","description":"

Returns a new vector in same direction as this one with the length passed in

"},{"title":"Vector2#rotate","link":"rotate","description":"

Returns copy of this vector rotated by the angle passed in

"},{"title":"Vector2#scale","link":"scale","description":"

Returns a copy of this vector scaled by the vector passed in

"},{"title":"Vector2#set","link":"set","description":"

Sets values of this vector and returns self

"},{"title":"Vector2#setAngle","link":"setAngle","description":"

Sets this vector with angle and length passed in

"},{"title":"Vector2#setDirection","link":"setDirection","description":"

Set the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

"},{"title":"Vector2#subtract","link":"subtract","description":"

Returns a copy of this vector minus the vector passed in

"},{"title":"Vector2#toString","link":"toString","description":"

Returns this vector expressed as a string

"},{"title":"Vector2#x","link":"x"},{"title":"Vector2#y","link":"y"},{"title":"WebGL","link":"WebGL","description":"

LittleJS WebGL Interface

\n"},{"title":"WebGL.glAntialias","link":"glAntialias","description":"

Shoule webgl be setup with antialiasing, must be set before calling engineInit

"},{"title":"WebGL.glCanvas","link":"glCanvas","description":"

The WebGL canvas which appears above the main canvas and below the overlay canvas

"},{"title":"WebGL.glCompileShader","link":"glCompileShader","description":"

Compile WebGL shader of the given type, will throw errors if in debug mode

"},{"title":"WebGL.glContext","link":"glContext","description":"

2d context for glCanvas

"},{"title":"WebGL.glCopyToContext","link":"glCopyToContext","description":"

Draw any sprites still in the buffer, copy to main canvas and clear

"},{"title":"WebGL.glCreateProgram","link":"glCreateProgram","description":"

Create WebGL program with given shaders

"},{"title":"WebGL.glCreateTexture","link":"glCreateTexture","description":"

Create WebGL texture from an image and init the texture settings

"},{"title":"WebGL.glDraw","link":"glDraw","description":"

Add a sprite to the gl draw list, used by all gl draw functions

"},{"title":"WebGL.glFlush","link":"glFlush","description":"

Draw all sprites and clear out the buffer, called automatically by the system whenever necessary

"},{"title":"WebGL.glSetAntialias","link":"glSetAntialias","description":"

Set antialiasing for webgl canvas

"},{"title":"WebGL.glSetTexture","link":"glSetTexture","description":"

Set the WebGl texture, called automatically if using multiple textures

\n"}]} \ No newline at end of file +{"list":[{"title":"Audio","link":"Audio","description":"

LittleJS Audio System

\n"},{"title":"Audio.audioContext","link":"audioContext","description":"

Audio context used by the engine

"},{"title":"Audio.audioGainNode","link":"audioGainNode","description":"

Master gain node for all audio to pass through

"},{"title":"Audio.getNoteFrequency","link":"getNoteFrequency","description":"

Get frequency of a note on a musical scale

"},{"title":"Audio.playAudioFile","link":"playAudioFile","description":"

Play an mp3, ogg, or wav audio from a local file or url

"},{"title":"Audio.playSamples","link":"playSamples","description":"

Play cached audio samples with given settings

"},{"title":"Audio.speak","link":"speak","description":"

Speak text with passed in settings

"},{"title":"Audio.speakStop","link":"speakStop","description":"

Stop all queued speech

"},{"title":"Audio.zzfx","link":"zzfx","description":"

Generate and play a ZzFX sound

\n

Create sounds using the ZzFX Sound Designer.

"},{"title":"Audio.zzfxG","link":"zzfxG","description":"

Generate samples for a ZzFX sound

"},{"title":"Audio.zzfxM","link":"zzfxM","description":"

Generate samples for a ZzFM song with given parameters

"},{"title":"Audio.zzfxR","link":"zzfxR","description":"

Sample rate used for all ZzFX sounds

"},{"title":"Color","link":"Color","description":"

Create a color with the rgba components passed in, white by default

"},{"title":"Color#HSLA","link":"HSLA","description":"

Returns this color expressed in hsla format

"},{"title":"Color#a","link":"a"},{"title":"Color#add","link":"add","description":"

Returns a copy of this color plus the color passed in

"},{"title":"Color#b","link":"b"},{"title":"Color#clamp","link":"clamp","description":"

Returns a copy of this color clamped to the valid range between 0 and 1

"},{"title":"Color#copy","link":"copy","description":"

Returns a new color that is a copy of this

"},{"title":"Color#divide","link":"divide","description":"

Returns a copy of this color divided by the color passed in

"},{"title":"Color#g","link":"g"},{"title":"Color#isValid","link":"isValid","description":"

Checks if this is a valid color

"},{"title":"Color#lerp","link":"lerp","description":"

Returns a new color that is p percent between this and the color passed in

"},{"title":"Color#multiply","link":"multiply","description":"

Returns a copy of this color times the color passed in

"},{"title":"Color#mutate","link":"mutate","description":"

Returns a new color that has each component randomly adjusted

"},{"title":"Color#r","link":"r"},{"title":"Color#rgbaInt","link":"rgbaInt","description":"

Returns this color expressed as 32 bit RGBA value

"},{"title":"Color#scale","link":"scale","description":"

Returns a copy of this color scaled by the value passed in, alpha can be scaled separately

"},{"title":"Color#set","link":"set","description":"

Sets values of this color and returns self

"},{"title":"Color#setHSLA","link":"setHSLA","description":"

Sets this color given a hue, saturation, lightness, and alpha

"},{"title":"Color#setHex","link":"setHex","description":"

Set this color from a hex code

"},{"title":"Color#subtract","link":"subtract","description":"

Returns a copy of this color minus the color passed in

"},{"title":"Color#toString","link":"toString","description":"

Returns this color expressed as a hex color code

"},{"title":"Debug","link":"Debug","description":"

LittleJS Debug System

\n"},{"title":"Debug.ASSERT","link":"ASSERT","description":"

Asserts if the expression is false, does not do anything in release builds

"},{"title":"Debug.debug","link":"debug","description":"

True if debug is enabled

"},{"title":"Debug.debugCircle","link":"debugCircle","description":"

Draw a debug circle in world space

"},{"title":"Debug.debugClear","link":"debugClear","description":"

Clear all debug primitives in the list

"},{"title":"Debug.debugKey","link":"debugKey","description":"

Key code used to toggle debug mode, Esc by default

"},{"title":"Debug.debugLine","link":"debugLine","description":"

Draw a debug line in world space

"},{"title":"Debug.debugOverlap","link":"debugOverlap","description":"

Draw a debug combined axis aligned bounding box in world space

"},{"title":"Debug.debugOverlay","link":"debugOverlay","description":"

True if the debug overlay is active, always false in release builds

"},{"title":"Debug.debugPoint","link":"debugPoint","description":"

Draw a debug point in world space

"},{"title":"Debug.debugPointSize","link":"debugPointSize","description":"

Size to render debug points by default

"},{"title":"Debug.debugPoly","link":"debugPoly","description":"

Draw a debug poly in world space

"},{"title":"Debug.debugRect","link":"debugRect","description":"

Draw a debug rectangle in world space

"},{"title":"Debug.debugSaveCanvas","link":"debugSaveCanvas","description":"

Save a canvas to disk

"},{"title":"Debug.debugSaveDataURL","link":"debugSaveDataURL","description":"

Save a data url to disk

"},{"title":"Debug.debugSaveText","link":"debugSaveText","description":"

Save a text file to disk

"},{"title":"Debug.debugShowErrors","link":"debugShowErrors","description":"

Show error as full page of red text

"},{"title":"Debug.debugText","link":"debugText","description":"

Draw a debug axis aligned bounding box in world space

"},{"title":"Debug.enableAsserts","link":"enableAsserts","description":"

True if asserts are enaled

"},{"title":"Debug.setDebugKey","link":"setDebugKey","description":"

Set key code used to toggle debug mode, Esc by default

"},{"title":"Debug.setShowWatermark","link":"setShowWatermark","description":"

Set if watermark with FPS should be shown

"},{"title":"Debug.showWatermark","link":"showWatermark","description":"

True if watermark with FPS should be shown, false in release builds

"},{"title":"Draw","link":"Draw","description":"

LittleJS Drawing System

\n\n

LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.\nThere are 3 canvas/contexts available to draw to...\nmainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.\nglCanvas - Used by the accelerated WebGL batch rendering system.\noverlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.

\n

The WebGL rendering system is very fast with some caveats...

\n\n

The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!

"},{"title":"Draw.drawCanvas2D","link":"drawCanvas2D","description":"

Draw directly to a 2d canvas context in world space

"},{"title":"Draw.drawCircle","link":"drawCircle","description":"

Draw colored circle using passed in point

"},{"title":"Draw.drawEllipse","link":"drawEllipse","description":"

Draw colored ellipse using passed in point

"},{"title":"Draw.drawLine","link":"drawLine","description":"

Draw colored line between two points

"},{"title":"Draw.drawPoly","link":"drawPoly","description":"

Draw colored polygon using passed in points

"},{"title":"Draw.drawRect","link":"drawRect","description":"

Draw colored rect centered on pos

"},{"title":"Draw.drawText","link":"drawText","description":"

Draw text on overlay canvas in world space\nAutomatically splits new lines into rows

"},{"title":"Draw.drawTextScreen","link":"drawTextScreen","description":"

Draw text on overlay canvas in screen space\nAutomatically splits new lines into rows

"},{"title":"Draw.drawTile","link":"drawTile","description":"

Draw textured tile centered in world space, with color applied if using WebGL

"},{"title":"Draw.getCameraSize","link":"getCameraSize","description":"

Get the camera's visible area in world space

"},{"title":"Draw.isFullscreen","link":"isFullscreen","description":"

Returns true if fullscreen mode is active

"},{"title":"Draw.mainCanvas","link":"mainCanvas","description":"

The primary 2D canvas visible to the user

"},{"title":"Draw.mainCanvasSize","link":"mainCanvasSize","description":"

The size of the main canvas (and other secondary canvases)

"},{"title":"Draw.mainContext","link":"mainContext","description":"

2d context for mainCanvas

"},{"title":"Draw.overlayCanvas","link":"overlayCanvas","description":"

A canvas that appears on top of everything the same size as mainCanvas

"},{"title":"Draw.overlayContext","link":"overlayContext","description":"

2d context for overlayCanvas

"},{"title":"Draw.screenToWorld","link":"screenToWorld","description":"

Convert from screen to world space coordinates

"},{"title":"Draw.setBlendMode","link":"setBlendMode","description":"

Enable normal or additive blend mode

"},{"title":"Draw.textureInfos","link":"textureInfos","description":"

Array containing texture info for batch rendering system

"},{"title":"Draw.tile","link":"tile","description":"

Create a tile info object using a grid based system

\n"},{"title":"Draw.toggleFullscreen","link":"toggleFullscreen","description":"

Toggle fullsceen mode

"},{"title":"Draw.worldToScreen","link":"worldToScreen","description":"

Convert from world to screen space coordinates

"},{"title":"Engine","link":"Engine","description":"

LittleJS - The Tiny Fast JavaScript Game Engine\nMIT License - Copyright 2021 Frank Force

\n

Engine Features

\n"},{"title":"Engine.engineAddPlugin","link":"engineAddPlugin","description":"

Add a new update function for a plugin

"},{"title":"Engine.engineInit","link":"engineInit","description":"

Startup LittleJS engine with your callback functions

"},{"title":"Engine.engineName","link":"engineName","description":"

Name of engine

"},{"title":"Engine.engineObjects","link":"engineObjects","description":"

Array containing all engine objects

"},{"title":"Engine.engineObjectsCallback","link":"engineObjectsCallback","description":"

Triggers a callback for each object within a given area

"},{"title":"Engine.engineObjectsCollect","link":"engineObjectsCollect","description":"

Collects all object within a given area

"},{"title":"Engine.engineObjectsCollide","link":"engineObjectsCollide","description":"

Array with only objects set to collide with other objects this frame (for optimization)

"},{"title":"Engine.engineObjectsDestroy","link":"engineObjectsDestroy","description":"

Destroy and remove all objects

"},{"title":"Engine.engineObjectsRaycast","link":"engineObjectsRaycast","description":"

Return a list of objects intersecting a ray

"},{"title":"Engine.engineObjectsUpdate","link":"engineObjectsUpdate","description":"

Update each engine object, remove destroyed objects, and update time

"},{"title":"Engine.engineVersion","link":"engineVersion","description":"

Version of engine

"},{"title":"Engine.frame","link":"frame","description":"

Current update frame, used to calculate time

"},{"title":"Engine.frameRate","link":"frameRate","description":"

Frames per second to update

"},{"title":"Engine.paused","link":"paused","description":"

Is the game paused? Causes time and objects to not be updated

"},{"title":"Engine.setPaused","link":"setPaused","description":"

Set if game is paused

"},{"title":"Engine.time","link":"time","description":"

Current engine time since start in seconds

"},{"title":"Engine.timeDelta","link":"timeDelta","description":"

How many seconds each frame lasts, engine uses a fixed time step

"},{"title":"Engine.timeReal","link":"timeReal","description":"

Actual clock time since start in seconds (not affected by pause or frame rate clamping)

"},{"title":"EngineObject","link":"EngineObject","description":"

Create an engine object and adds it to the list of objects

"},{"title":"EngineObject#addChild","link":"addChild","description":"

Attaches a child to this with a given local transform

"},{"title":"EngineObject#additiveColor","link":"additiveColor"},{"title":"EngineObject#angle","link":"angle"},{"title":"EngineObject#angleDamping","link":"angleDamping"},{"title":"EngineObject#angleVelocity","link":"angleVelocity"},{"title":"EngineObject#applyAcceleration","link":"applyAcceleration","description":"

Apply acceleration to this object (adjust velocity, not affected by mass)

"},{"title":"EngineObject#applyForce","link":"applyForce","description":"

Apply force to this object (adjust velocity, affected by mass)

"},{"title":"EngineObject#children","link":"children"},{"title":"EngineObject#clampSpeedLinear","link":"clampSpeedLinear"},{"title":"EngineObject#collideRaycast","link":"collideRaycast"},{"title":"EngineObject#collideSolidObjects","link":"collideSolidObjects"},{"title":"EngineObject#collideTiles","link":"collideTiles"},{"title":"EngineObject#collideWithObject","link":"collideWithObject","description":"

Called to check if a object collision should be resolved

"},{"title":"EngineObject#collideWithTile","link":"collideWithTile","description":"

Called to check if a tile collision should be resolved

"},{"title":"EngineObject#color","link":"color"},{"title":"EngineObject#damping","link":"damping"},{"title":"EngineObject#destroy","link":"destroy","description":"

Destroy this object, destroy it's children, detach it's parent, and mark it for removal

"},{"title":"EngineObject#drawSize","link":"drawSize"},{"title":"EngineObject#elasticity","link":"elasticity"},{"title":"EngineObject#friction","link":"friction"},{"title":"EngineObject#getAliveTime","link":"getAliveTime","description":"

How long since the object was created

"},{"title":"EngineObject#getMirrorSign","link":"getMirrorSign","description":"

Get the direction of the mirror

"},{"title":"EngineObject#gravityScale","link":"gravityScale"},{"title":"EngineObject#isSolid","link":"isSolid"},{"title":"EngineObject#localAngle","link":"localAngle"},{"title":"EngineObject#localPos","link":"localPos"},{"title":"EngineObject#localToWorld","link":"localToWorld","description":"

Convert from local space to world space

"},{"title":"EngineObject#localToWorldVector","link":"localToWorldVector","description":"

Convert from local space to world space for a vector (rotation only)

"},{"title":"EngineObject#mass","link":"mass"},{"title":"EngineObject#mirror","link":"mirror"},{"title":"EngineObject#parent","link":"parent"},{"title":"EngineObject#pos","link":"pos"},{"title":"EngineObject#removeChild","link":"removeChild","description":"

Removes a child from this one

"},{"title":"EngineObject#render","link":"render","description":"

Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder

"},{"title":"EngineObject#renderDebugInfo","link":"renderDebugInfo","description":"

Render debug info for this object

"},{"title":"EngineObject#renderOrder","link":"renderOrder"},{"title":"EngineObject#setCollision","link":"setCollision","description":"

Set how this object collides

"},{"title":"EngineObject#size","link":"size"},{"title":"EngineObject#spawnTime","link":"spawnTime"},{"title":"EngineObject#tileInfo","link":"tileInfo"},{"title":"EngineObject#toString","link":"toString","description":"

Returns string containg info about this object for debugging

"},{"title":"EngineObject#update","link":"update","description":"

Update the object physics, called automatically by engine once each frame

"},{"title":"EngineObject#updateTransforms","link":"updateTransforms","description":"

Update the object transform, called automatically by engine even when paused

"},{"title":"EngineObject#velocity","link":"velocity"},{"title":"EngineObject#worldToLocal","link":"worldToLocal","description":"

Convert from world space to local space

"},{"title":"EngineObject#worldToLocalVector","link":"worldToLocalVector","description":"

Convert from world space to local space for a vector (rotation only)

"},{"title":"FontImage","link":"FontImage","description":"

Create an image font

"},{"title":"FontImage#drawText","link":"drawText","description":"

Draw text in world space using the image font

"},{"title":"FontImage#drawTextScreen","link":"drawTextScreen","description":"

Draw text in screen space using the image font

"},{"title":"Input","link":"Input","description":"

LittleJS Input System

\n"},{"title":"Input.clearInput","link":"clearInput","description":"

Clears all input

"},{"title":"Input.gamepadIsDown","link":"gamepadIsDown","description":"

Returns true if gamepad button is down

"},{"title":"Input.gamepadStick","link":"gamepadStick","description":"

Returns gamepad stick value

"},{"title":"Input.gamepadWasPressed","link":"gamepadWasPressed","description":"

Returns true if gamepad button was pressed

"},{"title":"Input.gamepadWasReleased","link":"gamepadWasReleased","description":"

Returns true if gamepad button was released

"},{"title":"Input.isTouchDevice","link":"isTouchDevice","description":"

True if a touch device has been detected

"},{"title":"Input.isUsingGamepad","link":"isUsingGamepad","description":"

Returns true if user is using gamepad (has more recently pressed a gamepad button)

"},{"title":"Input.keyIsDown","link":"keyIsDown","description":"

Returns true if device key is down

"},{"title":"Input.keyWasPressed","link":"keyWasPressed","description":"

Returns true if device key was pressed this frame

"},{"title":"Input.keyWasReleased","link":"keyWasReleased","description":"

Returns true if device key was released this frame

"},{"title":"Input.mouseIsDown","link":"mouseIsDown","description":"

Returns true if mouse button is down

"},{"title":"Input.mousePos","link":"mousePos","description":"

Mouse pos in world space

"},{"title":"Input.mousePosScreen","link":"mousePosScreen","description":"

Mouse pos in screen space

"},{"title":"Input.mouseWasPressed","link":"mouseWasPressed","description":"

Returns true if mouse button was pressed

"},{"title":"Input.mouseWasReleased","link":"mouseWasReleased","description":"

Returns true if mouse button was released

"},{"title":"Input.mouseWheel","link":"mouseWheel","description":"

Mouse wheel delta this frame

"},{"title":"Input.preventDefaultInput","link":"preventDefaultInput","description":"

Prevents input continuing to the default browser handling (false by default)

"},{"title":"Input.vibrate","link":"vibrate","description":"

Pulse the vibration hardware if it exists

"},{"title":"Input.vibrateStop","link":"vibrateStop","description":"

Cancel any ongoing vibration

"},{"title":"Medal","link":"Medal","description":"

Create a medal object and adds it to the list of medals

"},{"title":"Medal#description","link":"description"},{"title":"Medal#icon","link":"icon"},{"title":"Medal#id","link":"id"},{"title":"Medal#name","link":"name"},{"title":"Medal#render","link":"render","description":"

Render a medal

"},{"title":"Medal#renderIcon","link":"renderIcon","description":"

Render the icon for a medal

"},{"title":"Medal#unlock","link":"unlock","description":"

Unlocks a medal if not already unlocked

"},{"title":"Medal#unlocked","link":"unlocked"},{"title":"Medals","link":"Medals","description":"

LittleJS Medal System

\n"},{"title":"Medals.medals","link":"medals","description":"

List of all medals

"},{"title":"Medals.medalsForEach","link":"medalsForEach","description":"

Calls a function for each medal

"},{"title":"Medals.medalsInit","link":"medalsInit","description":"

Initialize medals with a save name used for storage

\n"},{"title":"Music","link":"Music","description":"

Create a music object and cache the zzfx music samples for later use

"},{"title":"Music#playMusic","link":"playMusic","description":"

Play the music

"},{"title":"Particle","link":"Particle","description":"

Create a particle with the passed in settings\nTypically this is created automatically by a ParticleEmitter

"},{"title":"Particle#additive","link":"additive"},{"title":"Particle#colorEndDelta","link":"colorEndDelta"},{"title":"Particle#colorStart","link":"colorStart"},{"title":"Particle#destroyCallback","link":"destroyCallback"},{"title":"Particle#fadeRate","link":"fadeRate"},{"title":"Particle#lifeTime","link":"lifeTime"},{"title":"Particle#localSpaceEmitter","link":"localSpaceEmitter"},{"title":"Particle#render","link":"render","description":"

Render the particle, automatically called each frame, sorted by renderOrder

"},{"title":"Particle#sizeEndDelta","link":"sizeEndDelta"},{"title":"Particle#sizeStart","link":"sizeStart"},{"title":"Particle#trailScale","link":"trailScale"},{"title":"ParticleEmitter","link":"ParticleEmitter","description":"

Create a particle system with the given settings

"},{"title":"ParticleEmitter#additive","link":"additive"},{"title":"ParticleEmitter#angleDamping","link":"angleDamping"},{"title":"ParticleEmitter#angleSpeed","link":"angleSpeed"},{"title":"ParticleEmitter#collideTiles","link":"collideTiles"},{"title":"ParticleEmitter#colorEndA","link":"colorEndA"},{"title":"ParticleEmitter#colorEndB","link":"colorEndB"},{"title":"ParticleEmitter#colorStartA","link":"colorStartA"},{"title":"ParticleEmitter#colorStartB","link":"colorStartB"},{"title":"ParticleEmitter#damping","link":"damping"},{"title":"ParticleEmitter#emitConeAngle","link":"emitConeAngle"},{"title":"ParticleEmitter#emitParticle","link":"emitParticle","description":"

Spawn one particle

"},{"title":"ParticleEmitter#emitRate","link":"emitRate"},{"title":"ParticleEmitter#emitSize","link":"emitSize"},{"title":"ParticleEmitter#emitTime","link":"emitTime"},{"title":"ParticleEmitter#emitTimeBuffer","link":"emitTimeBuffer"},{"title":"ParticleEmitter#fadeRate","link":"fadeRate"},{"title":"ParticleEmitter#gravityScale","link":"gravityScale"},{"title":"ParticleEmitter#localSpace","link":"localSpace"},{"title":"ParticleEmitter#particleConeAngle","link":"particleConeAngle"},{"title":"ParticleEmitter#particleCreateCallback","link":"particleCreateCallback"},{"title":"ParticleEmitter#particleDestroyCallback","link":"particleDestroyCallback"},{"title":"ParticleEmitter#particleTime","link":"particleTime"},{"title":"ParticleEmitter#randomColorLinear","link":"randomColorLinear"},{"title":"ParticleEmitter#randomness","link":"randomness"},{"title":"ParticleEmitter#sizeEnd","link":"sizeEnd"},{"title":"ParticleEmitter#sizeStart","link":"sizeStart"},{"title":"ParticleEmitter#speed","link":"speed"},{"title":"ParticleEmitter#trailScale","link":"trailScale"},{"title":"ParticleEmitter#update","link":"update","description":"

Update the emitter to spawn particles, called automatically by engine once each frame

"},{"title":"Random","link":"Random","description":"

Random global functions

"},{"title":"Random.rand","link":"rand","description":"

Returns a random value between the two values passed in

"},{"title":"Random.randColor","link":"randColor","description":"

Returns a random color between the two passed in colors, combine components if linear

"},{"title":"Random.randInCircle","link":"randInCircle","description":"

Returns a random Vector2 within a circular shape

"},{"title":"Random.randInt","link":"randInt","description":"

Returns a floored random value between the two values passed in\nThe upper bound is exclusive. (If 2 is passed in, result will be 0 or 1)

"},{"title":"Random.randSign","link":"randSign","description":"

Randomly returns either -1 or 1

"},{"title":"Random.randVector","link":"randVector","description":"

Returns a random Vector2 with the passed in length

"},{"title":"RandomGenerator","link":"RandomGenerator","description":"

Create a random number generator with the seed passed in

"},{"title":"RandomGenerator#float","link":"float","description":"

Returns a seeded random value between the two values passed in

"},{"title":"RandomGenerator#int","link":"int","description":"

Returns a floored seeded random value the two values passed in

"},{"title":"RandomGenerator#seed","link":"seed"},{"title":"RandomGenerator#sign","link":"sign","description":"

Randomly returns either -1 or 1 deterministically

"},{"title":"Settings","link":"Settings","description":"

LittleJS Engine Settings

\n"},{"title":"Settings.cameraPos","link":"cameraPos","description":"

Position of camera in world space

"},{"title":"Settings.cameraScale","link":"cameraScale","description":"

Scale of camera in world space

"},{"title":"Settings.canvasFixedSize","link":"canvasFixedSize","description":"

Fixed size of the canvas, if enabled canvas size never changes

\n"},{"title":"Settings.canvasMaxSize","link":"canvasMaxSize","description":"

The max size of the canvas, centered if window is larger

"},{"title":"Settings.canvasPixelated","link":"canvasPixelated","description":"

Use nearest neighbor scaling algorithm for canvas for more pixelated look

"},{"title":"Settings.enablePhysicsSolver","link":"enablePhysicsSolver","description":"

Enable physics solver for collisions between objects

"},{"title":"Settings.fontDefault","link":"fontDefault","description":"

Default font used for text rendering

"},{"title":"Settings.gamepadDirectionEmulateStick","link":"gamepadDirectionEmulateStick","description":"

If true, the dpad input is also routed to the left analog stick (for better accessability)

"},{"title":"Settings.gamepadsEnable","link":"gamepadsEnable","description":"

Should gamepads be allowed

"},{"title":"Settings.glEnable","link":"glEnable","description":"

Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)

"},{"title":"Settings.glOverlay","link":"glOverlay","description":"

Fixes slow rendering in some browsers by not compositing the WebGL canvas

"},{"title":"Settings.gravity","link":"gravity","description":"

How much gravity to apply to objects along the Y axis, negative is down

"},{"title":"Settings.headlessMode","link":"headlessMode","description":"

Disables all rendering, audio, and input for servers

"},{"title":"Settings.inputWASDEmulateDirection","link":"inputWASDEmulateDirection","description":"

If true the WASD keys are also routed to the direction keys (for better accessability)

"},{"title":"Settings.medalDisplayIconSize","link":"medalDisplayIconSize","description":"

Size of icon in medal display

"},{"title":"Settings.medalDisplaySize","link":"medalDisplaySize","description":"

Size of medal display

"},{"title":"Settings.medalDisplaySlideTime","link":"medalDisplaySlideTime","description":"

How quickly to slide on/off medals in seconds

"},{"title":"Settings.medalDisplayTime","link":"medalDisplayTime","description":"

How long to show medals for in seconds

"},{"title":"Settings.medalsPreventUnlock","link":"medalsPreventUnlock","description":"

Set to stop medals from being unlockable (like if cheats are enabled)

"},{"title":"Settings.objectDefaultAngleDamping","link":"objectDefaultAngleDamping","description":"

How much to slow angular velocity each frame (0-1)

"},{"title":"Settings.objectDefaultDamping","link":"objectDefaultDamping","description":"

How much to slow velocity by each frame (0-1)

"},{"title":"Settings.objectDefaultElasticity","link":"objectDefaultElasticity","description":"

How much to bounce when a collision occurs (0-1)

"},{"title":"Settings.objectDefaultFriction","link":"objectDefaultFriction","description":"

How much to slow when touching (0-1)

"},{"title":"Settings.objectDefaultMass","link":"objectDefaultMass","description":"

Default object mass for collision calcuations (how heavy objects are)

"},{"title":"Settings.objectMaxSpeed","link":"objectMaxSpeed","description":"

Clamp max speed to avoid fast objects missing collisions

"},{"title":"Settings.particleEmitRateScale","link":"particleEmitRateScale","description":"

Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)

"},{"title":"Settings.setCameraPos","link":"setCameraPos","description":"

Set position of camera in world space

"},{"title":"Settings.setCameraScale","link":"setCameraScale","description":"

Set scale of camera in world space

"},{"title":"Settings.setCanvasFixedSize","link":"setCanvasFixedSize","description":"

Set fixed size of the canvas

"},{"title":"Settings.setCanvasMaxSize","link":"setCanvasMaxSize","description":"

Set max size of the canvas

"},{"title":"Settings.setCanvasPixelated","link":"setCanvasPixelated","description":"

Use nearest neighbor scaling algorithm for canvas for more pixelated look

"},{"title":"Settings.setEnablePhysicsSolver","link":"setEnablePhysicsSolver","description":"

Set if collisions between objects are enabled

"},{"title":"Settings.setFontDefault","link":"setFontDefault","description":"

Set default font used for text rendering

"},{"title":"Settings.setGamepadDirectionEmulateStick","link":"setGamepadDirectionEmulateStick","description":"

Set if the dpad input is also routed to the left analog stick

"},{"title":"Settings.setGamepadsEnable","link":"setGamepadsEnable","description":"

Set if gamepads are enabled

"},{"title":"Settings.setGlEnable","link":"setGlEnable","description":"

Set if webgl rendering is enabled

"},{"title":"Settings.setGlOverlay","link":"setGlOverlay","description":"

Set to not composite the WebGL canvas

"},{"title":"Settings.setGravity","link":"setGravity","description":"

Set how much gravity to apply to objects along the Y axis

"},{"title":"Settings.setHeadlessMode","link":"setHeadlessMode","description":"

Set to disalbe rendering, audio, and input for servers

"},{"title":"Settings.setInputWASDEmulateDirection","link":"setInputWASDEmulateDirection","description":"

Set if true the WASD keys are also routed to the direction keys

"},{"title":"Settings.setMedalDisplayIconSize","link":"setMedalDisplayIconSize","description":"

Set size of icon in medal display

"},{"title":"Settings.setMedalDisplaySize","link":"setMedalDisplaySize","description":"

Set size of medal display

"},{"title":"Settings.setMedalDisplaySlideTime","link":"setMedalDisplaySlideTime","description":"

Set how quickly to slide on/off medals in seconds

"},{"title":"Settings.setMedalDisplayTime","link":"setMedalDisplayTime","description":"

Set how long to show medals for in seconds

"},{"title":"Settings.setMedalsPreventUnlock","link":"setMedalsPreventUnlock","description":"

Set to stop medals from being unlockable

"},{"title":"Settings.setObjectDefaultAngleDamping","link":"setObjectDefaultAngleDamping","description":"

Set how much to slow angular velocity each frame

"},{"title":"Settings.setObjectDefaultDamping","link":"setObjectDefaultDamping","description":"

Set how much to slow velocity by each frame

"},{"title":"Settings.setObjectDefaultElasticity","link":"setObjectDefaultElasticity","description":"

Set how much to bounce when a collision occur

"},{"title":"Settings.setObjectDefaultFriction","link":"setObjectDefaultFriction","description":"

Set how much to slow when touching

"},{"title":"Settings.setObjectDefaultMass","link":"setObjectDefaultMass","description":"

Set default object mass for collison calcuations

"},{"title":"Settings.setObjectMaxSpeed","link":"setObjectMaxSpeed","description":"

Set max speed to avoid fast objects missing collisions

"},{"title":"Settings.setParticleEmitRateScale","link":"setParticleEmitRateScale","description":"

Set to scales emit rate of particles

"},{"title":"Settings.setShowSplashScreen","link":"setShowSplashScreen","description":"

Set if the LittleJS splash screen be shown on startup

"},{"title":"Settings.setSoundDefaultRange","link":"setSoundDefaultRange","description":"

Set default range where sound no longer plays

"},{"title":"Settings.setSoundDefaultTaper","link":"setSoundDefaultTaper","description":"

Set default range percent to start tapering off sound

"},{"title":"Settings.setSoundEnable","link":"setSoundEnable","description":"

Set to disable all audio code

"},{"title":"Settings.setSoundVolume","link":"setSoundVolume","description":"

Set volume scale to apply to all sound, music and speech

"},{"title":"Settings.setTileFixBleedScale","link":"setTileFixBleedScale","description":"

Set to prevent tile bleeding from neighbors in pixels

"},{"title":"Settings.setTileSizeDefault","link":"setTileSizeDefault","description":"

Set default size of tiles in pixels

"},{"title":"Settings.setTilesPixelated","link":"setTilesPixelated","description":"

Disables texture filtering for crisper pixel art

"},{"title":"Settings.setTouchGamepadAlpha","link":"setTouchGamepadAlpha","description":"

Set transparency of touch gamepad overlay

"},{"title":"Settings.setTouchGamepadAnalog","link":"setTouchGamepadAnalog","description":"

Set if touch gamepad should be analog stick or 8 way dpad

"},{"title":"Settings.setTouchGamepadEnable","link":"setTouchGamepadEnable","description":"

Set if touch gamepad should appear on mobile devices

"},{"title":"Settings.setTouchGamepadSize","link":"setTouchGamepadSize","description":"

Set size of virutal gamepad for touch devices in pixels

"},{"title":"Settings.setTouchInputEnable","link":"setTouchInputEnable","description":"

Set if touch input is allowed

"},{"title":"Settings.setVibrateEnable","link":"setVibrateEnable","description":"

Set to allow vibration hardware if it exists

"},{"title":"Settings.showSplashScreen","link":"showSplashScreen","description":"

Enable to show the LittleJS splash screen be shown on startup

"},{"title":"Settings.soundDefaultRange","link":"soundDefaultRange","description":"

Default range where sound no longer plays

"},{"title":"Settings.soundDefaultTaper","link":"soundDefaultTaper","description":"

Default range percent to start tapering off sound (0-1)

"},{"title":"Settings.soundEnable","link":"soundEnable","description":"

All audio code can be disabled and removed from build

"},{"title":"Settings.soundVolume","link":"soundVolume","description":"

Volume scale to apply to all sound, music and speech

"},{"title":"Settings.tileFixBleedScale","link":"tileFixBleedScale","description":"

How many pixels smaller to draw tiles to prevent bleeding from neighbors

"},{"title":"Settings.tileSizeDefault","link":"tileSizeDefault","description":"

Default size of tiles in pixels

"},{"title":"Settings.tilesPixelated","link":"tilesPixelated","description":"

Disables texture filtering for crisper pixel art

"},{"title":"Settings.touchGamepadAlpha","link":"touchGamepadAlpha","description":"

Transparency of touch gamepad overlay

"},{"title":"Settings.touchGamepadAnalog","link":"touchGamepadAnalog","description":"

True if touch gamepad should be analog stick or false to use if 8 way dpad

"},{"title":"Settings.touchGamepadEnable","link":"touchGamepadEnable","description":"

True if touch gamepad should appear on mobile devices

\n"},{"title":"Settings.touchGamepadSize","link":"touchGamepadSize","description":"

Size of virtual gamepad for touch devices in pixels

"},{"title":"Settings.touchInputEnable","link":"touchInputEnable","description":"

True if touch input is enabled for mobile devices

\n"},{"title":"Settings.vibrateEnable","link":"vibrateEnable","description":"

Allow vibration hardware if it exists

"},{"title":"Sound","link":"Sound","description":"

Create a sound object and cache the zzfx samples for later use

"},{"title":"Sound#getDuration","link":"getDuration","description":"

Get how long this sound is in seconds

"},{"title":"Sound#getSource","link":"getSource","description":"

Get source of most recent instance of this sound that was played

"},{"title":"Sound#isLoading","link":"isLoading","description":"

Check if sound is loading, for sounds fetched from a url

"},{"title":"Sound#play","link":"play","description":"

Play the sound

"},{"title":"Sound#playNote","link":"playNote","description":"

Play the sound as a note with a semitone offset

"},{"title":"Sound#randomness","link":"randomness"},{"title":"Sound#range","link":"range"},{"title":"Sound#setVolume","link":"setVolume","description":"

Set the sound volume of the most recently played instance of this sound

"},{"title":"Sound#stop","link":"stop","description":"

Stop the last instance of this sound that was played

"},{"title":"Sound#taper","link":"taper"},{"title":"SoundWave","link":"SoundWave","description":"

Create a sound object and cache the wave file for later use

"},{"title":"TextureInfo","link":"TextureInfo","description":"

Create a TextureInfo, called automatically by the engine

"},{"title":"TextureInfo#glTexture","link":"glTexture"},{"title":"TextureInfo#image","link":"image"},{"title":"TextureInfo#size","link":"size"},{"title":"TileCollision","link":"TileCollision","description":"

LittleJS Tile Layer System

\n"},{"title":"TileCollision.getTileCollisionData","link":"getTileCollisionData","description":"

Get tile collision data for a given cell in the grid

"},{"title":"TileCollision.initTileCollision","link":"initTileCollision","description":"

Clear and initialize tile collision

"},{"title":"TileCollision.setTileCollisionData","link":"setTileCollisionData","description":"

Set tile collision data for a given cell in the grid

"},{"title":"TileCollision.tileCollision","link":"tileCollision","description":"

The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access

"},{"title":"TileCollision.tileCollisionRaycast","link":"tileCollisionRaycast","description":"

Return the center of first tile hit, undefined if nothing was hit.\nThis does not return the exact intersection, but the center of the tile hit.

"},{"title":"TileCollision.tileCollisionSize","link":"tileCollisionSize","description":"

Size of the tile collision layer 2d grid

"},{"title":"TileCollision.tileCollisionTest","link":"tileCollisionTest","description":"

Check if collision with another object should occur

"},{"title":"TileInfo","link":"TileInfo","description":"

Create a tile info object

"},{"title":"TileInfo#frame","link":"frame","description":"

Returns a copy of this tile offset by a number of animation frames

"},{"title":"TileInfo#getTextureInfo","link":"getTextureInfo","description":"

Returns the texture info for this tile

"},{"title":"TileInfo#offset","link":"offset","description":"

Returns a copy of this tile offset by a vector

"},{"title":"TileInfo#padding","link":"padding"},{"title":"TileInfo#pos","link":"pos"},{"title":"TileInfo#size","link":"size"},{"title":"TileInfo#textureIndex","link":"textureIndex"},{"title":"TileLayer","link":"TileLayer","description":"

Create a tile layer object

"},{"title":"TileLayer#canvas","link":"canvas"},{"title":"TileLayer#context","link":"context"},{"title":"TileLayer#drawCanvas2D","link":"drawCanvas2D","description":"

Draw directly to the 2D canvas in world space (bipass webgl)

"},{"title":"TileLayer#drawRect","link":"drawRect","description":"

Draw a rectangle directly onto the layer canvas in world space

"},{"title":"TileLayer#drawTile","link":"drawTile","description":"

Draw a tile directly onto the layer canvas in world space

"},{"title":"TileLayer#drawTileData","link":"drawTileData","description":"

Draw the tile at a given position in the tile grid\nThis can be used to clear out tiles when they are destroyed\nTiles can also be redrawn if isinde a redrawStart/End block

"},{"title":"TileLayer#getData","link":"getData","description":"

Get data at a given position in the array

"},{"title":"TileLayer#isOverlay","link":"isOverlay"},{"title":"TileLayer#redraw","link":"redraw","description":"

Draw all the tile data to an offscreen canvas

\n"},{"title":"TileLayer#redrawEnd","link":"redrawEnd","description":"

Call to end the redraw process

"},{"title":"TileLayer#redrawStart","link":"redrawStart","description":"

Call to start the redraw process

\n"},{"title":"TileLayer#savedRenderSettings","link":"savedRenderSettings"},{"title":"TileLayer#scale","link":"scale"},{"title":"TileLayer#setData","link":"setData","description":"

Set data at a given position in the array

"},{"title":"TileLayerData","link":"TileLayerData","description":"

Create a tile layer data object, one for each tile in a TileLayer

"},{"title":"TileLayerData#clear","link":"clear","description":"

Set this tile to clear, it will not be rendered

"},{"title":"TileLayerData#color","link":"color"},{"title":"TileLayerData#direction","link":"direction"},{"title":"TileLayerData#mirror","link":"mirror"},{"title":"TileLayerData#tile","link":"tile"},{"title":"Timer","link":"Timer","description":"

Create a timer object set time passed in

"},{"title":"Timer#active","link":"active","description":"

Returns true if set and has not elapsed

"},{"title":"Timer#elapsed","link":"elapsed","description":"

Returns true if set and elapsed

"},{"title":"Timer#get","link":"get","description":"

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

"},{"title":"Timer#getPercent","link":"getPercent","description":"

Get percentage elapsed based on time it was set to, returns 0 if not set

"},{"title":"Timer#isSet","link":"isSet","description":"

Returns true if set

"},{"title":"Timer#set","link":"set","description":"

Set the timer with seconds passed in

"},{"title":"Timer#toString","link":"toString","description":"

Returns this timer expressed as a string

"},{"title":"Timer#unset","link":"unset","description":"

Unset the timer

"},{"title":"Timer#valueOf","link":"valueOf","description":"

Get how long since elapsed, returns 0 if not set (returns negative if currently active)

"},{"title":"Utilities","link":"Utilities","description":"

LittleJS Utility Classes and Functions

\n"},{"title":"Utilities.BLACK","link":"BLACK","description":"

Color - Black

"},{"title":"Utilities.BLUE","link":"BLUE","description":"

Color - Blue

"},{"title":"Utilities.CYAN","link":"CYAN","description":"

Color - Cyan

"},{"title":"Utilities.GRAY","link":"GRAY","description":"

Color - Gray

"},{"title":"Utilities.GREEN","link":"GREEN","description":"

Color - Green

"},{"title":"Utilities.MAGENTA","link":"MAGENTA","description":"

Color - Magenta

"},{"title":"Utilities.ORANGE","link":"ORANGE","description":"

Color - Orange

"},{"title":"Utilities.PI","link":"PI","description":"

A shortcut to get Math.PI

"},{"title":"Utilities.PURPLE","link":"PURPLE","description":"

Color - Purple

"},{"title":"Utilities.RED","link":"RED","description":"

Color - Red

"},{"title":"Utilities.WHITE","link":"WHITE","description":"

Color - White

"},{"title":"Utilities.YELLOW","link":"YELLOW","description":"

Color - Yellow

"},{"title":"Utilities.abs","link":"abs","description":"

Returns absoulte value of value passed in

"},{"title":"Utilities.clamp","link":"clamp","description":"

Clamps the value beween max and min

"},{"title":"Utilities.distanceAngle","link":"distanceAngle","description":"

Returns signed wrapped distance between the two angles passed in

"},{"title":"Utilities.distanceWrap","link":"distanceWrap","description":"

Returns signed wrapped distance between the two values passed in

"},{"title":"Utilities.formatTime","link":"formatTime","description":"

Formats seconds to mm:ss style for display purposes

"},{"title":"Utilities.hsl","link":"hsl","description":"

Create a color object with HSLA values, white by default

"},{"title":"Utilities.isColor","link":"isColor","description":"

Check if object is a valid Color

"},{"title":"Utilities.isIntersecting","link":"isIntersecting","description":"

Returns true if a line segment is intersecting an axis aligned box

"},{"title":"Utilities.isOverlapping","link":"isOverlapping","description":"

Returns true if two axis aligned bounding boxes are overlapping

"},{"title":"Utilities.isVector2","link":"isVector2","description":"

Check if object is a valid Vector2

"},{"title":"Utilities.lerp","link":"lerp","description":"

Linearly interpolates between values passed in using percent

"},{"title":"Utilities.lerpAngle","link":"lerpAngle","description":"

Linearly interpolates between the angles passed in with wrapping

"},{"title":"Utilities.lerpWrap","link":"lerpWrap","description":"

Linearly interpolates between values passed in with wrapping

"},{"title":"Utilities.max","link":"max","description":"

Returns highest of two values passed in

"},{"title":"Utilities.min","link":"min","description":"

Returns lowest of two values passed in

"},{"title":"Utilities.mod","link":"mod","description":"

Returns first parm modulo the second param, but adjusted so negative numbers work as expected

"},{"title":"Utilities.nearestPowerOfTwo","link":"nearestPowerOfTwo","description":"

Returns the nearest power of two not less then the value

"},{"title":"Utilities.percent","link":"percent","description":"

Returns what percentage the value is between valueA and valueB

"},{"title":"Utilities.rgb","link":"rgb","description":"

Create a color object with RGBA values, white by default

"},{"title":"Utilities.sign","link":"sign","description":"

Returns the sign of value passed in

"},{"title":"Utilities.smoothStep","link":"smoothStep","description":"

Applies smoothstep function to the percentage value

"},{"title":"Utilities.vec2","link":"vec2","description":"

Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar

"},{"title":"Utilities.wave","link":"wave","description":"

Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default

"},{"title":"Vector2","link":"Vector2","description":"

Create a 2D vector with the x and y passed in, can also be created with vec2()

"},{"title":"Vector2#add","link":"add","description":"

Returns a copy of this vector plus the vector passed in

"},{"title":"Vector2#angle","link":"angle","description":"

Returns the angle of this vector, up is angle 0

"},{"title":"Vector2#area","link":"area","description":"

Returns the area this vector covers as a rectangle

"},{"title":"Vector2#arrayCheck","link":"arrayCheck","description":"

Returns true if this vector is within the bounds of an array size passed in

"},{"title":"Vector2#clampLength","link":"clampLength","description":"

Returns a new vector clamped to length passed in

"},{"title":"Vector2#copy","link":"copy","description":"

Returns a new vector that is a copy of this

"},{"title":"Vector2#cross","link":"cross","description":"

Returns the cross product of this and the vector passed in

"},{"title":"Vector2#direction","link":"direction","description":"

Returns the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

"},{"title":"Vector2#distance","link":"distance","description":"

Returns the distance from this vector to vector passed in

"},{"title":"Vector2#distanceSquared","link":"distanceSquared","description":"

Returns the distance squared from this vector to vector passed in

"},{"title":"Vector2#divide","link":"divide","description":"

Returns a copy of this vector divided by the vector passed in

"},{"title":"Vector2#dot","link":"dot","description":"

Returns the dot product of this and the vector passed in

"},{"title":"Vector2#floor","link":"floor","description":"

Returns a copy of this vector with each axis floored

"},{"title":"Vector2#invert","link":"invert","description":"

Returns a copy of this vector that has been inverted

"},{"title":"Vector2#isValid","link":"isValid","description":"

Checks if this is a valid vector

"},{"title":"Vector2#length","link":"length","description":"

Returns the length of this vector

"},{"title":"Vector2#lengthSquared","link":"lengthSquared","description":"

Returns the length of this vector squared

"},{"title":"Vector2#lerp","link":"lerp","description":"

Returns a new vector that is p percent between this and the vector passed in

"},{"title":"Vector2#multiply","link":"multiply","description":"

Returns a copy of this vector times the vector passed in

"},{"title":"Vector2#normalize","link":"normalize","description":"

Returns a new vector in same direction as this one with the length passed in

"},{"title":"Vector2#rotate","link":"rotate","description":"

Returns copy of this vector rotated by the angle passed in

"},{"title":"Vector2#scale","link":"scale","description":"

Returns a copy of this vector scaled by the vector passed in

"},{"title":"Vector2#set","link":"set","description":"

Sets values of this vector and returns self

"},{"title":"Vector2#setAngle","link":"setAngle","description":"

Sets this vector with angle and length passed in

"},{"title":"Vector2#setDirection","link":"setDirection","description":"

Set the integer direction of this vector, corrosponding to multiples of 90 degree rotation (0-3)

"},{"title":"Vector2#subtract","link":"subtract","description":"

Returns a copy of this vector minus the vector passed in

"},{"title":"Vector2#toString","link":"toString","description":"

Returns this vector expressed as a string

"},{"title":"Vector2#x","link":"x"},{"title":"Vector2#y","link":"y"},{"title":"WebGL","link":"WebGL","description":"

LittleJS WebGL Interface

\n"},{"title":"WebGL.glAntialias","link":"glAntialias","description":"

Shoule webgl be setup with antialiasing, must be set before calling engineInit

"},{"title":"WebGL.glCanvas","link":"glCanvas","description":"

The WebGL canvas which appears above the main canvas and below the overlay canvas

"},{"title":"WebGL.glCompileShader","link":"glCompileShader","description":"

Compile WebGL shader of the given type, will throw errors if in debug mode

"},{"title":"WebGL.glContext","link":"glContext","description":"

2d context for glCanvas

"},{"title":"WebGL.glCopyToContext","link":"glCopyToContext","description":"

Draw any sprites still in the buffer, copy to main canvas and clear

"},{"title":"WebGL.glCreateProgram","link":"glCreateProgram","description":"

Create WebGL program with given shaders

"},{"title":"WebGL.glCreateTexture","link":"glCreateTexture","description":"

Create WebGL texture from an image and init the texture settings

"},{"title":"WebGL.glDraw","link":"glDraw","description":"

Add a sprite to the gl draw list, used by all gl draw functions

"},{"title":"WebGL.glFlush","link":"glFlush","description":"

Draw all sprites and clear out the buffer, called automatically by the system whenever necessary

"},{"title":"WebGL.glSetAntialias","link":"glSetAntialias","description":"

Set antialiasing for webgl canvas

"},{"title":"WebGL.glSetTexture","link":"glSetTexture","description":"

Set the WebGl texture, called automatically if using multiple textures

\n"}]} \ No newline at end of file diff --git a/docs/engine.js.html b/docs/engine.js.html index 98f4b95c..60f40c8a 100644 --- a/docs/engine.js.html +++ b/docs/engine.js.html @@ -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} @@ -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(); @@ -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 diff --git a/docs/engineAudio.js.html b/docs/engineAudio.js.html index c49be206..a863ea76 100644 --- a/docs/engineAudio.js.html +++ b/docs/engineAudio.js.html @@ -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) { @@ -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() diff --git a/docs/engineDraw.js.html b/docs/engineDraw.js.html index beccd089..ce04688a 100644 --- a/docs/engineDraw.js.html +++ b/docs/engineDraw.js.html @@ -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); diff --git a/docs/engineSettings.js.html b/docs/engineSettings.js.html index da41ab8c..53752fbd 100644 --- a/docs/engineSettings.js.html +++ b/docs/engineSettings.js.html @@ -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 @@ -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 */ diff --git a/docs/engineTileLayer.js.html b/docs/engineTileLayer.js.html index 0d19f7b5..9b6ff661 100644 --- a/docs/engineTileLayer.js.html +++ b/docs/engineTileLayer.js.html @@ -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) { @@ -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 */ @@ -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 */ @@ -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] @@ -283,7 +284,7 @@ } // disable smoothing for pixel art - this.context.imageSmoothingEnabled = !canvasPixelated; + this.context.imageSmoothingEnabled = !tilesPixelated; // setup gl rendering if enabled glPreRender(); diff --git a/docs/engineUtilities.js.html b/docs/engineUtilities.js.html index 7ac12dff..286d7043 100644 --- a/docs/engineUtilities.js.html +++ b/docs/engineUtilities.js.html @@ -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} */ @@ -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); + } } /////////////////////////////////////////////////////////////////////////////// @@ -596,6 +610,7 @@ this.b = b; /** @property {Number} - Alpha */ this.a = a; + ASSERT(this.isValid()); } /** Sets values of this color and returns self @@ -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} */ @@ -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; } @@ -715,7 +738,6 @@ else if (b == max) h = (r - g) / d + 4; } - return [h / 6, s, l, a]; } @@ -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; } @@ -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); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/docs/engineWebGL.js.html b/docs/engineWebGL.js.html index 66f926b4..1130d17c 100644 --- a/docs/engineWebGL.js.html +++ b/docs/engineWebGL.js.html @@ -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;