LittleJS 1.28.0

Settings

LittleJS Engine Settings

  • All settings for the engine are here

Functions

Members

Functions

getCanvasPixelRatio() → numberengineSettings.js:603

Get the pixel ratio currently applied to the canvas backing store

  • Resolves canvasPixelRatio, falling back to devicePixelRatio when it is undefined
  • Game code works in css pixels so this is rarely needed, it is for sizing render targets and viewports that must match the backing store
setCameraAngle(angle)engineSettings.js:488

Set angle of camera in world space

angle number
setCameraPos(pos)engineSettings.js:479

Set position of camera in world space

pos Vector2
setCameraScale(scale)engineSettings.js:493

Set scale of camera in world space

scale number
setCameraShakeAngle(angle)engineSettings.js:503

Set how far a full camera shake turns the view, in radians

angle number
setCameraShakeDecay(decay)engineSettings.js:508

Set how much camera shake fades each second

decay number
setCameraShakeDistance(distance)engineSettings.js:498

Set how far a full camera shake moves the view, in world units

distance number
setCanvasClearColor(color)engineSettings.js:532

Set color to clear the canvas to before render, does not clear if alpha is 0

color Color
setCanvasColorTiles(colorTiles)engineSettings.js:527

Set if tiles should be colorized when using canvas2d This can be slower but results should look nearly identical to WebGL rendering It can be enabled/disabled at any time Optimized for performance, and will use faster method if color is white or untextured

colorTiles boolean
setCanvasFixedSize(size)engineSettings.js:560

Set fixed size of the canvas

size Vector2
setCanvasMaxAspect(aspect)engineSettings.js:555

Set maximum aspect ratio of the canvas (width/height), unused if 0

aspect number
setCanvasMaxSize(size)engineSettings.js:541

Set max size of the canvas

size Vector2
setCanvasMinAspect(aspect)engineSettings.js:550

Set minimum aspect ratio of the canvas (width/height), unused if 0

aspect number
setCanvasPixelated(pixelated)engineSettings.js:569

Use nearest scaling algorithm for canvas for more pixelated look

pixelated boolean
setCanvasPixelRatio(pixelRatio)engineSettings.js:595

Set the canvas pixel ratio, scales the render resolution for sharper output Pass a number for an explicit ratio, or call with no argument to track devicePixelRatio each frame.

  • The canvas stays the same size on screen and everything draws the same size, it just renders at a higher resolution so nothing looks blurry
  • Game code is unaffected, it always works in css pixels
pixelRatio number optional
// render at native resolution, capped so phones don't pay for 3x
setCanvasPixelRatio(min(devicePixelRatio, 2));
setDrawScreenSpace(screenSpace)engineSettings.js:666

Set whether the draw and debug functions draw in screen space when a call leaves screenSpace out

screenSpace boolean
setEnablePhysicsSolver(enable)engineSettings.js:714

Set if collisions are enabled, between objects and with tiles

enable boolean
setEngineManualStep(enable)engineSettings.js:631

Set if the engine only advances when engineStep is called Set before engineInit for a test or a server; turned on in a running game it stops the loop, and turned off again it starts the loop from real time

enable boolean optional, default true
setEngineVariableStep(enable)engineSettings.js:650

Set if the engine runs one update per display frame with timeDelta the time it covers Can be set before engineInit or while running; turned off it goes back to fixed updates at frameRate

enable boolean optional, default true
setFontDefault(font)engineSettings.js:609

Set default font used for text rendering

  • A family name with spaces or digits goes in quotes, as "'Press Start 2P'", or the canvas does not take it
font string
setGamepadAxisFilterEnable(enable)engineSettings.js:784

Set if axes that do not rest near center are ignored on non-standard gamepads

enable boolean
setGamepadDirectionEmulateStick(enable)engineSettings.js:779

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

enable boolean
setGamepadsEnable(enable)engineSettings.js:774

Set if gamepads are enabled

enable boolean
setGLCircleSides(sides)engineSettings.js:686

Set how many sided polygons to use when drawing circles and ellipses with WebGL

sides number
setGLEnable(enable)engineSettings.js:671

Set if WebGL rendering is enabled

enable boolean
setGravity(newGravity)engineSettings.js:760

Set how much gravity to apply to objects

newGravity Vector2
setHeadlessMode(headless)engineSettings.js:624

Set to disable rendering, audio, and input for servers, must be set before engineInit

headless boolean
setInputWASDEmulateDirection(enable)engineSettings.js:789

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

enable boolean
setLoadingScreen(callback)engineSettings.js:619

Set the loading screen, drawn after the splash while the game loads, once that takes more than half a second

callback LoadingScreenCallback optional

Draws on mainContext given the part done, 0 to 1; undefined for none

setMedalDisplaySize(size)medalSystem.js:329

Set size of medal display

size Vector2
setMedalDisplaySlideTime(time)medalSystem.js:324

Set how quickly to slide on/off medals in seconds

time number
setMedalDisplayTime(time)medalSystem.js:319

Set how long to show medals for in seconds

time number
setMedalsPreventUnlock(preventUnlock)medalSystem.js:334

Set to stop medals from being unlockable

preventUnlock boolean
setObjectDefaultAngleDamping(damp)engineSettings.js:734

Set the fraction of angular velocity objects keep each frame, 1 keeps all of it, 0 stops at once

damp number
setObjectDefaultDamping(damp)engineSettings.js:724

Set the fraction of velocity objects keep each frame, 1 keeps all of it, 0 stops at once

damp number
setObjectDefaultFriction(friction)engineSettings.js:750

Set the fraction of sliding speed objects keep each frame on the ground, 1 is no friction, 0 stops at once

friction number
setObjectDefaultMass(mass)engineSettings.js:719

Set default object mass for collision calculations

mass number
setObjectDefaultRestitution(restitution)engineSettings.js:745

Set how much to bounce when a collision occurs

restitution number
setObjectMaxSpeed(speed)engineSettings.js:755

Set max speed to avoid fast objects missing collisions

speed number
setParticleEmitRateScale(scale)engineSettings.js:769

Set the scale for the emit rate of particles, 0 disables particle emitters

scale number
setShowSplashScreen(show)engineSettings.js:614

Set if the LittleJS splash screen should be shown on startup, must be set before engineInit

show boolean
setSoundDefaultRange(range)engineSettings.js:922

Set default range where sound no longer plays

range number
setSoundDefaultTaper(taper)engineSettings.js:927

Set default range percent to start tapering off sound

taper number
setSoundEnable(enable)engineSettings.js:898

Set if audio is enabled, false turns all sound off; a setting for before sounds are made, since a sound made while it is off has nothing to play and one already playing goes on; to mute while the game runs, setSoundVolume(0)

enable boolean
setSoundIgnoreSilentSwitch(ignore)engineSettings.js:903

Set if sound plays with an iPhone's silent switch on, as media does, which also pauses the player's own music

ignore boolean
setSoundPauseWhenHidden(pause)engineSettings.js:932

Set if all sound pauses while the page is hidden

pause boolean
setSoundVolume(volume)engineSettings.js:912

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

volume number
setTextureSheetPadding(padding)textureSheet.js:600

Set default padding pixels around each frame packed by loadSprite

padding number
setTextureSheetSize(size)textureSheet.js:595

Set width and height in pixels of texture sheets created by loadSprite

size number
setTileDefaultBleed(bleed)engineSettings.js:709

Default amount of pixels smaller to draw tiles to prevent neighbor bleeding

bleed number
setTileDefaultPadding(padding)engineSettings.js:704

Default padding pixels around tiles

padding number
setTileDefaultSize(size)engineSettings.js:695

Set default size of tiles in pixels

size Vector2
setTilesPixelated(pixelated)engineSettings.js:583

Disables texture filtering for crisper pixel art

  • Leave true for pixel art; set false for smooth/high-resolution art
  • Set it before engineInit, a texture already loaded keeps the filtering it was made with
pixelated boolean
setTimeScale(scale)engineSettings.js:515

Set scale applied to engine time

  • 0 freezes the game like a pause, gameUpdatePost and input still run so the game can set it back
  • Above 1 the fixed step runs that many updates each frame, so a large scale costs as many updates
scale number

0 or more

setTouchGamepadAlpha(alpha)engineSettings.js:877

Set transparency of touch gamepad overlay

alpha number
setTouchGamepadAnalog(analog)engineSettings.js:862

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

analog boolean
setTouchGamepadButtonCount(count)engineSettings.js:821

Set number of buttons on the right side of the touch gamepad (0-4, gamepad buttons 0-3)

count number
setTouchGamepadCenterButtonSize(size)engineSettings.js:816

Set if touch gamepad should have start button in the center

  • Set size to enable the center button
  • When the game is paused, any touch will press the button
size number
setTouchGamepadDisplayTime(time)engineSettings.js:882

Set how long to display the touch gamepad on screen in seconds, set to 0 to always display

time number
setTouchGamepadEnable(enable)engineSettings.js:799

Set if touch gamepad should appear on mobile devices

enable boolean
setTouchGamepadFloating(floating)engineSettings.js:867

Set if touch gamepad directional controls should float to where you press

floating boolean
setTouchGamepadLeftButtonCount(count)engineSettings.js:842

Set number of buttons on the left side of the touch gamepad (0-4, gamepad buttons 4-7)

  • Only used when touchGamepadLeftStick is false
count number
setTouchGamepadLeftStick(enable)engineSettings.js:831

Set if the touch gamepad should have a left analog stick (or dpad)

enable boolean
setTouchGamepadPassthrough(passthrough)engineSettings.js:809

Set if touches outside the gamepad controls should still drive mouse/touch input

passthrough boolean
setTouchGamepadRightStick(rightStick)engineSettings.js:852

Set if the touch gamepad right side is an analog stick (or dpad) instead of face buttons

rightStick boolean
setTouchGamepadSize(size)engineSettings.js:872

Set size of virtual gamepad for touch devices in viewport CSS pixels

size number
setTouchGamepadVibration(ms)engineSettings.js:887

Set duration in ms to vibrate when a touch gamepad face or start button is pressed (0 disables)

ms number
setTouchInputEnable(enable)engineSettings.js:794

Set if touch input is allowed

enable boolean
setTouchPinchWheel(enable)engineSettings.js:804

Set if a pinch of two fingers turns the mouse wheel

enable boolean
setVibrateEnable(enable)engineSettings.js:892

Set to allow vibration hardware if it exists

enable boolean

Members

cameraAngle : number default 0engineSettings.js:22

Rotation angle of camera in world space

cameraPos : Vector2 default Vector2()engineSettings.js:16

Position of camera in world space

cameraScale : number default 32engineSettings.js:28

Scale of camera in world space

cameraShakeAngle : number default 0.05engineSettings.js:40

How far a full camera shake turns the view, in radians, see cameraShake

cameraShakeDecay : number default 1engineSettings.js:46

How much camera shake fades each second, 1 takes a full shake to nothing in a second, see cameraShake

cameraShakeDistance : number default 0.5engineSettings.js:34

How far a full camera shake moves the view, in world units, see cameraShake

canvasClearColor : ColorengineSettings.js:73

Color to clear the canvas to before render, does not clear if alpha is 0

canvasColorTiles : boolean default trueengineSettings.js:68

Enable applying color to tiles when using canvas2d

  • This is slower but should be the same as WebGL rendering
canvasFixedSize : Vector2 default Vector2()engineSettings.js:101

Fixed size of the canvas in css pixels, if enabled canvas size never changes

  • canvasPixelRatio still applies, it only scales the backing store
canvasMaxAspect : number default 0engineSettings.js:94

Maximum aspect ratio of the canvas (width/height), unused if 0 Can be used with canvasMinAspect to limit aspect ratio

canvasMaxSize : Vector2 default Vector2(3840,2160)engineSettings.js:80

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

  • Not affected by canvasPixelRatio, the backing store may be larger than this
canvasMinAspect : number default 0engineSettings.js:87

Minimum aspect ratio of the canvas (width/height), unused if 0 Can be used with canvasMaxAspect to limit aspect ratio

canvasPixelated : boolean default falseengineSettings.js:108

Use nearest canvas scaling for more pixelated look

  • If enabled sets css image-rendering:pixelated
canvasPixelRatio : number|undefined default 1engineSettings.js:129

Scale factor applied to the canvas resolution for sharper rendering Pass 1 for no scaling, a number for an explicit ratio, or undefined to track devicePixelRatio each frame.

  • Only the backing store scales, so this changes sharpness and nothing else
  • mainCanvasSize, cameraScale, mousePos and screen space stay in css pixels, so the same code draws the same size at any ratio
  • Pixel art usually looks best left at 1 or set to whole numbers, a fractional ratio samples texels unevenly
drawScreenSpace : boolean default falseengineSettings.js:190

Draw in screen space by default: what the screenSpace parameter of the draw and debug functions defaults to, so a heads up display, or a 3D game that only draws 2D on the screen, can turn it on and leave the flag out

  • The engine says its own space when it draws, so objects, tile layers and particles stay in world space, but a game's own draws follow it, a render() override included: turn it on around the hud, or pass false there
  • Sizes and widths keep their defaults, which are world sized, so pass them in pixels
  • drawText has no screenSpace and stays in world space, drawTextScreen is the one for the screen
enablePhysicsSolver : boolean default trueengineSettings.js:226

Enable physics solver for collisions, between objects and with tiles

engineManualStep : boolean default falseengineSettings.js:161

Disables the automatic requestAnimationFrame loop so the engine only advances when engineStep is called, for tests and frame-stepping tools

engineVariableStep : boolean default falseengineSettings.js:170

Run one update per display frame with timeDelta the time it covers, in place of fixed updates at frameRate

  • Per-frame values are not scaled: velocity, gravity, damping and particle speeds act once per update, so a game that turns this on scales its own movement by timeDelta
  • Values in seconds follow real time as they are: time, timers, particle emit rate and life, animation, Box2D
fontDefault : string default arialengineSettings.js:135

Default font used for text rendering

gamepadAxisFilterEnable : boolean default trueengineSettings.js:298

If true, axes that do not rest near center are ignored on gamepads without standard mapping. Steering wheels and flight sticks report pedal and throttle axes that rest at full deflection, which otherwise reads as a stick held down.

gamepadDirectionEmulateStick : boolean default trueengineSettings.js:290

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

gamepadsEnable : boolean default trueengineSettings.js:284

Should gamepads be allowed

glCircleSides : number default 32engineSettings.js:196

How many sided poly to use when drawing circles and ellipses with WebGL

glEnable : boolean default trueengineSettings.js:179

Enable WebGL accelerated rendering

How much gravity to apply to objects, negative Y is down, in world units per frame per frame

headlessMode : boolean default falseengineSettings.js:154

Disables all rendering, audio, and input for servers, must be set before engineInit

inputWASDEmulateDirection : boolean default trueengineSettings.js:305

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

  • Turn it off for a game with two players on one keyboard, one on WASD and one on the arrows

The loading screen, drawn after the splash while the images, gameInit and what they load are loading, once that takes more than half a second: a function given the part done, 0 to 1, or undefined for none, which leaves the screen blank; the default says Loading over a bar

medalDisplaySize : Vector2 default Vector2(640,80)medalSystem.js:35

Size of medal display

medalDisplaySlideTime : number default 0.5medalSystem.js:29

How quickly to slide on/off medals in seconds

medalDisplayTime : number default 5medalSystem.js:23

How long to show medals for in seconds

medalsPreventUnlock : boolean default falsemedalSystem.js:41

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

objectDefaultAngleDamping : number default 1engineSettings.js:244

Fraction of angular velocity objects keep each frame, 1 keeps all of it, 0 stops at once

objectDefaultDamping : number default 1engineSettings.js:238

Fraction of velocity objects keep each frame, 1 keeps all of it, 0 stops at once

objectDefaultFriction : number default 0.8engineSettings.js:257

Fraction of sliding speed objects keep each frame on the ground, 1 is no friction, 0 stops at once

  • The more slippery of an object and its ground is used
objectDefaultMass : number default 1engineSettings.js:232

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

objectDefaultRestitution : number default 0engineSettings.js:250

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

objectMaxSpeed : number default 1engineSettings.js:263

Clamp max speed to avoid fast objects missing collisions, in world units per frame on each axis

particleEmitRateScale : number default 1engineSettings.js:275

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

showSplashScreen : boolean default falseengineSettings.js:141

Enable to show the LittleJS splash screen on startup, must be set before engineInit

soundDefaultRange : number default 40engineSettings.js:457

Default range where sound no longer plays

soundDefaultTaper : number default 0.7engineSettings.js:463

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

soundEnable : boolean default trueengineSettings.js:437

All audio code can be disabled and removed from build

soundIgnoreSilentSwitch : boolean default falseengineSettings.js:444

Play sound with an iPhone's silent switch on, as media does; off by default, so the switch mutes the game as it does a ringtone, and the player's own music keeps playing beside it; Safari 16.4 and up, elsewhere it does nothing

soundPauseWhenHidden : boolean default trueengineSettings.js:471

Pause all sound while the page is hidden, and pick up where it was when it shows again

  • A hidden page stops the game, so without this a looping sound plays on over a frozen game
  • Turn it off to keep music playing in a background tab
soundVolume : number default 0.3engineSettings.js:451

Volume scale to apply to all sound, music and speech Use setSoundVolume to also update the audio master gain immediately

textureSheetPadding : number default 1textureSheet.js:26

Default padding pixels around each frame packed by loadSprite

textureSheetSize : number default 2048textureSheet.js:20

Width and height in pixels of texture sheets created by loadSprite

tileDefaultBleed : number default 0engineSettings.js:217

Default amount of pixels smaller to draw tiles to prevent neighbor bleeding

tileDefaultPadding : number default 0engineSettings.js:211

Default padding pixels around tiles

tileDefaultSize : Vector2 default Vector2(16,16)engineSettings.js:205

Default size of tiles in pixels

tilesPixelated : boolean default trueengineSettings.js:117

Disables texture filtering for crisper pixel art

  • Leave true for pixel art so sprites stay sharp when scaled (uses NEAREST filtering)
  • Set false for smooth/high-resolution art to enable bilinear filtering and mipmaps; those textures upload premultiplied, so filtering does not pull dark from see through texels into the edges
timeScale : number default 1engineSettings.js:58

Scale applied to engine time, can be used for slow motion or fast forward

  • 1 is normal speed, 2 is double speed, 0.5 is half speed
  • 0 freezes the game like a pause without setting the paused flag, gameUpdatePost and input still run
  • Should be >= 0; stacks multiplicatively with the debug +/- shortcut
touchGamepadAlpha : number default 0.3engineSettings.js:409

Transparency of touch gamepad overlay

touchGamepadAnalog : boolean default trueengineSettings.js:387

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

touchGamepadButtonCount : number default 4engineSettings.js:358

Number of buttons on the right side of the touch gamepad (0-4), using gamepad buttons 0-3

  • A count of 1 is a single large button (the size of a stick)
  • Ignored when touchGamepadRightStick is set (the right side is a stick instead)
touchGamepadCenterButtonSize : number default 0engineSettings.js:350

Size of center button if touch gamepad should have start button in the center

  • Prevents activating when pressed near virtual stick or face buttons
  • When the game is paused, any touch will press the button
  • Measured in viewport CSS pixels
touchGamepadDisplayTime : number default 3engineSettings.js:415

How long to display the touch gamepad on screen in seconds, set to 0 to always display

touchGamepadEnable : boolean default falseengineSettings.js:323

True if touch gamepad should appear on mobile devices

  • Supports left analog stick, 4 face buttons and start button (button 9)
  • setTouchGamepadRightStick(true) for a right analog stick in place of the face buttons
  • Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
  • Rendered as a full-viewport HTML/SVG overlay, so controls may sit outside the game canvas
  • It is gamepad 0 once touched; a real gamepad being used takes over and hides it until the screen is touched again
touchGamepadFloating : boolean default falseengineSettings.js:397

True if touch gamepad directional controls should float to where you press

  • Only affects analog sticks and dpads, not face buttons
  • Directional controls re-anchor to where you press within the bottom ~60% of their screen half; the top ~40% passes through to the game
  • The right side floats only when it acts as the right analog stick (touchGamepadRightStick is set)
  • A center button (touchGamepadCenterButtonSize) still works since it ignores touches near the sticks
touchGamepadLeftButtonCount : number default 0engineSettings.js:373

Number of buttons on the left side of the touch gamepad (0-4), using gamepad buttons 4-7

  • Only used when touchGamepadLeftStick is false (otherwise the left side is a stick)
  • A count of 1 is a single large button (the size of a stick)
touchGamepadLeftStick : boolean default trueengineSettings.js:365

True if the touch gamepad should have a left analog stick (or dpad)

  • When false, the left side is face buttons (touchGamepadLeftButtonCount) or nothing
touchGamepadPassthrough : boolean default falseengineSettings.js:332

True if touches outside the gamepad controls should still drive mouse/touch input

  • When false (the default), enabling the touch gamepad suppresses touch-to-mouse input entirely
  • Set true to also pass touches outside the controls through to the game as mouse/touch input
  • Touches on the gamepad controls never drive the mouse regardless of this setting
touchGamepadRightStick : boolean default falseengineSettings.js:381

True if the touch gamepad right side should be an analog stick (or dpad) instead of face buttons

  • When set, touchGamepadButtonCount is ignored and the right side is a stick
  • Uses an analog stick when touchGamepadAnalog is true, otherwise an 8 way dpad
touchGamepadSize : number default 100engineSettings.js:403

Size of virtual gamepad for touch devices in viewport CSS pixels

touchGamepadVibration : number default 0engineSettings.js:422

Duration in ms to vibrate when a touch gamepad face button or start button is pressed

  • Set to 0 to disable, also requires vibrateEnable and hardware support (ignored on iOS)
touchInputEnable : boolean default trueengineSettings.js:312

True if touch input is enabled for mobile devices

  • Touch events will be routed to mouse events
touchPinchWheel : boolean default trueengineSettings.js:341

True if a pinch of two fingers turns the mouse wheel: touchPinch is added to mouseWheel, so what zooms with the wheel zooms with a pinch, the mouse is between the two fingers, and a second finger lets go of the button the first pressed, since a pinch is not a drag; turn it off for a game with its own use for two fingers, the first finger stays the mouse and touchPinch can still be read

vibrateEnable : boolean default trueengineSettings.js:428

Allow vibration hardware if it exists