littlejsengine 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/littlejs.d.ts +64 -62
- package/build/littlejs.esm.js +91 -88
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +91 -88
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +91 -88
- package/examples/js13k/build.js +1 -1
- package/examples/starter/build.js +1 -1
- package/examples/stress/index.html +1 -1
- package/index.d.ts +2094 -0
- package/package.json +1 -1
- package/src/engine.js +1 -1
- package/src/engineDraw.js +27 -27
- package/src/engineInput.js +3 -3
- package/src/engineObject.js +7 -7
- package/src/engineParticles.js +4 -4
- package/src/engineTileLayer.js +37 -32
- package/src/engineUtilities.js +5 -5
- package/src/engineWebGL.js +7 -9
|
@@ -156,11 +156,11 @@ function smoothStep(percent) { return percent * percent * (3 - 2 * percent); }
|
|
|
156
156
|
function nearestPowerOfTwo(value) { return 2**Math.ceil(Math.log2(value)); }
|
|
157
157
|
|
|
158
158
|
/** Returns true if two axis aligned bounding boxes are overlapping
|
|
159
|
-
* @param {Vector2} pointA
|
|
160
|
-
* @param {Vector2} sizeA
|
|
161
|
-
* @param {Vector2} pointB
|
|
162
|
-
* @param {Vector2} sizeB
|
|
163
|
-
* @return {Boolean}
|
|
159
|
+
* @param {Vector2} pointA - Center of box A
|
|
160
|
+
* @param {Vector2} sizeA - Size of box A
|
|
161
|
+
* @param {Vector2} pointB - Center of box B
|
|
162
|
+
* @param {Vector2} sizeB - Size of box B
|
|
163
|
+
* @return {Boolean} - True if overlapping
|
|
164
164
|
* @memberof Utilities */
|
|
165
165
|
function isOverlapping(pointA, sizeA, pointB, sizeB)
|
|
166
166
|
{
|
|
@@ -1179,12 +1179,12 @@ function setDebugKey(key) { debugKey = key; }
|
|
|
1179
1179
|
class EngineObject
|
|
1180
1180
|
{
|
|
1181
1181
|
/** Create an engine object and adds it to the list of objects
|
|
1182
|
-
* @param {Vector2} [pos=
|
|
1183
|
-
* @param {Vector2} [size=
|
|
1184
|
-
* @param {TileInfo} [tileInfo]
|
|
1185
|
-
* @param {Number} [angle]
|
|
1186
|
-
* @param {Color} [color=
|
|
1187
|
-
* @param {Number} [renderOrder]
|
|
1182
|
+
* @param {Vector2} [pos=(0,0)] - World space position of the object
|
|
1183
|
+
* @param {Vector2} [size=(1,1)] - World space size of the object
|
|
1184
|
+
* @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
|
|
1185
|
+
* @param {Number} [angle] - Angle the object is rotated by
|
|
1186
|
+
* @param {Color} [color=(1,1,1,1)] - Color to apply to tile when rendered
|
|
1187
|
+
* @param {Number} [renderOrder] - Objects sorted by renderOrder before being rendered
|
|
1188
1188
|
*/
|
|
1189
1189
|
constructor(pos=vec2(), size=vec2(1), tileInfo, angle=0, color, renderOrder=0)
|
|
1190
1190
|
{
|
|
@@ -1484,7 +1484,7 @@ class EngineObject
|
|
|
1484
1484
|
|
|
1485
1485
|
/** Attaches a child to this with a given local transform
|
|
1486
1486
|
* @param {EngineObject} child
|
|
1487
|
-
* @param {Vector2} [localPos=
|
|
1487
|
+
* @param {Vector2} [localPos=(0,0)]
|
|
1488
1488
|
* @param {Number} [localAngle] */
|
|
1489
1489
|
addChild(child, localPos=vec2(), localAngle=0)
|
|
1490
1490
|
{
|
|
@@ -1601,7 +1601,7 @@ let drawCount;
|
|
|
1601
1601
|
* Create a tile info object
|
|
1602
1602
|
* - This can take vecs or floats for easier use and conversion
|
|
1603
1603
|
* - If an index is passed in, the tile size and index will determine the position
|
|
1604
|
-
* @param {(Number|Vector2)} [pos=
|
|
1604
|
+
* @param {(Number|Vector2)} [pos=(0,0)] - Top left corner of tile in pixels or index
|
|
1605
1605
|
* @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
|
|
1606
1606
|
* @param {Number} [textureIndex] - Texture index to use
|
|
1607
1607
|
* @return {TileInfo}
|
|
@@ -1644,7 +1644,7 @@ function tile(pos=vec2(), size=tileSizeDefault, textureIndex=0)
|
|
|
1644
1644
|
class TileInfo
|
|
1645
1645
|
{
|
|
1646
1646
|
/** Create a tile info object
|
|
1647
|
-
* @param {Vector2} [pos=
|
|
1647
|
+
* @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
|
|
1648
1648
|
* @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
|
|
1649
1649
|
* @param {Number} [textureIndex] - Texture index to use
|
|
1650
1650
|
*/
|
|
@@ -1721,16 +1721,16 @@ function worldToScreen(worldPos)
|
|
|
1721
1721
|
}
|
|
1722
1722
|
|
|
1723
1723
|
/** Draw textured tile centered in world space, with color applied if using WebGL
|
|
1724
|
-
* @param {Vector2} pos
|
|
1725
|
-
* @param {Vector2} [size=
|
|
1726
|
-
* @param {TileInfo}[tileInfo]
|
|
1727
|
-
* @param {Color} [color=
|
|
1728
|
-
* @param {Number} [angle]
|
|
1729
|
-
* @param {Boolean} [mirror]
|
|
1730
|
-
* @param {Color} [additiveColor=
|
|
1731
|
-
* @param {Boolean} [useWebGL=glEnable]
|
|
1732
|
-
* @param {Boolean} [screenSpace]
|
|
1733
|
-
* @param {CanvasRenderingContext2D} [context]
|
|
1724
|
+
* @param {Vector2} pos - Center of the tile in world space
|
|
1725
|
+
* @param {Vector2} [size=(1,1)] - Size of the tile in world space
|
|
1726
|
+
* @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
|
|
1727
|
+
* @param {Color} [color=(1,1,1,1)] - Color to modulate with
|
|
1728
|
+
* @param {Number} [angle] - Angle to rotate by
|
|
1729
|
+
* @param {Boolean} [mirror] - If true image is flipped along the Y axis
|
|
1730
|
+
* @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
|
|
1731
|
+
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
1732
|
+
* @param {Boolean} [screenSpace=false] - If true the pos and size are in screen space
|
|
1733
|
+
* @param {CanvasRenderingContext2D} [context] - Canvas 2D context to draw to
|
|
1734
1734
|
* @memberof Draw */
|
|
1735
1735
|
function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
1736
1736
|
angle=0, mirror, additiveColor=new Color(0,0,0,0), useWebGL=glEnable, screenSpace, context)
|
|
@@ -1798,11 +1798,11 @@ function drawTile(pos, size=vec2(1), tileInfo, color=new Color,
|
|
|
1798
1798
|
|
|
1799
1799
|
/** Draw colored rect centered on pos
|
|
1800
1800
|
* @param {Vector2} pos
|
|
1801
|
-
* @param {Vector2} [size=
|
|
1802
|
-
* @param {Color} [color=
|
|
1801
|
+
* @param {Vector2} [size=(1,1)]
|
|
1802
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1803
1803
|
* @param {Number} [angle]
|
|
1804
1804
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1805
|
-
* @param {Boolean} [screenSpace]
|
|
1805
|
+
* @param {Boolean} [screenSpace=false]
|
|
1806
1806
|
* @param {CanvasRenderingContext2D} [context]
|
|
1807
1807
|
* @memberof Draw */
|
|
1808
1808
|
function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
@@ -1812,8 +1812,8 @@ function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
|
1812
1812
|
|
|
1813
1813
|
/** Draw colored polygon using passed in points
|
|
1814
1814
|
* @param {Array} points - Array of Vector2 points
|
|
1815
|
-
* @param {Color} [color=
|
|
1816
|
-
* @param {Boolean} [screenSpace]
|
|
1815
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1816
|
+
* @param {Boolean} [screenSpace=false]
|
|
1817
1817
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
1818
1818
|
* @memberof Draw */
|
|
1819
1819
|
function drawPoly(points, color=new Color, screenSpace, context=mainContext)
|
|
@@ -1829,9 +1829,9 @@ function drawPoly(points, color=new Color, screenSpace, context=mainContext)
|
|
|
1829
1829
|
* @param {Vector2} posA
|
|
1830
1830
|
* @param {Vector2} posB
|
|
1831
1831
|
* @param {Number} [thickness]
|
|
1832
|
-
* @param {Color} [color=
|
|
1832
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1833
1833
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1834
|
-
* @param {Boolean} [screenSpace]
|
|
1834
|
+
* @param {Boolean} [screenSpace=false]
|
|
1835
1835
|
* @param {CanvasRenderingContext2D} [context]
|
|
1836
1836
|
* @memberof Draw */
|
|
1837
1837
|
function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, context)
|
|
@@ -1847,7 +1847,7 @@ function drawLine(posA, posB, thickness=.1, color, useWebGL, screenSpace, contex
|
|
|
1847
1847
|
* @param {Number} angle
|
|
1848
1848
|
* @param {Boolean} mirror
|
|
1849
1849
|
* @param {Function} drawFunction
|
|
1850
|
-
* @param {Boolean} [screenSpace]
|
|
1850
|
+
* @param {Boolean} [screenSpace=false]
|
|
1851
1851
|
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
1852
1852
|
* @memberof Draw */
|
|
1853
1853
|
function drawCanvas2D(pos, size, angle, mirror, drawFunction, screenSpace, context=mainContext)
|
|
@@ -1889,9 +1889,9 @@ function setBlendMode(additive, useWebGL=glEnable, context)
|
|
|
1889
1889
|
* @param {String} text
|
|
1890
1890
|
* @param {Vector2} pos
|
|
1891
1891
|
* @param {Number} [size]
|
|
1892
|
-
* @param {Color} [color=
|
|
1892
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1893
1893
|
* @param {Number} [lineWidth]
|
|
1894
|
-
* @param {Color} [lineColor=
|
|
1894
|
+
* @param {Color} [lineColor=(0,0,0,1)]
|
|
1895
1895
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
1896
1896
|
* @param {String} [font=fontDefault]
|
|
1897
1897
|
* @param {CanvasRenderingContext2D} [context=overlayContext]
|
|
@@ -1906,9 +1906,9 @@ function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, f
|
|
|
1906
1906
|
* @param {String} text
|
|
1907
1907
|
* @param {Vector2} pos
|
|
1908
1908
|
* @param {Number} [size]
|
|
1909
|
-
* @param {Color} [color=
|
|
1909
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1910
1910
|
* @param {Number} [lineWidth]
|
|
1911
|
-
* @param {Color} [lineColor=
|
|
1911
|
+
* @param {Color} [lineColor=(0,0,0,1)]
|
|
1912
1912
|
* @param {CanvasTextAlign} [textAlign]
|
|
1913
1913
|
* @param {String} [font=fontDefault]
|
|
1914
1914
|
* @param {CanvasRenderingContext2D} [context=overlayContext]
|
|
@@ -1951,9 +1951,9 @@ let engineFontImage;
|
|
|
1951
1951
|
class FontImage
|
|
1952
1952
|
{
|
|
1953
1953
|
/** Create an image font
|
|
1954
|
-
* @param {HTMLImageElement} [image]
|
|
1955
|
-
* @param {Vector2} [tileSize=
|
|
1956
|
-
* @param {Vector2} [paddingSize=
|
|
1954
|
+
* @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
|
|
1955
|
+
* @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
|
|
1956
|
+
* @param {Vector2} [paddingSize=(0,1)] - How much extra space to add between characters
|
|
1957
1957
|
* @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
|
|
1958
1958
|
*/
|
|
1959
1959
|
constructor(image, tileSize=vec2(8), paddingSize=vec2(0,1), context=overlayContext)
|
|
@@ -2231,10 +2231,10 @@ function inputUpdatePost()
|
|
|
2231
2231
|
///////////////////////////////////////////////////////////////////////////////
|
|
2232
2232
|
// Mouse event handlers
|
|
2233
2233
|
|
|
2234
|
-
onmousedown = (e)=> {isUsingGamepad = false; inputData[0][e.button] = 3;
|
|
2234
|
+
onmousedown = (e)=> {isUsingGamepad = false; inputData[0][e.button] = 3; mousePosScreen = mouseToScreen(e); e.button && e.preventDefault();}
|
|
2235
2235
|
onmouseup = (e)=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
|
|
2236
2236
|
onmousemove = (e)=> mousePosScreen = mouseToScreen(e);
|
|
2237
|
-
onwheel = (e)=> e.ctrlKey
|
|
2237
|
+
onwheel = (e)=> mouseWheel = e.ctrlKey ? 0 : sign(e.deltaY);
|
|
2238
2238
|
oncontextmenu = (e)=> false; // prevent right click menu
|
|
2239
2239
|
|
|
2240
2240
|
// convert a mouse or touch event position to screen space
|
|
@@ -2328,7 +2328,7 @@ function gamepadsUpdate()
|
|
|
2328
2328
|
///////////////////////////////////////////////////////////////////////////////
|
|
2329
2329
|
|
|
2330
2330
|
/** Pulse the vibration hardware if it exists
|
|
2331
|
-
* @param {Number} [pattern] -
|
|
2331
|
+
* @param {Number|Array} [pattern] - single value in ms or vibration interval array
|
|
2332
2332
|
* @memberof Input */
|
|
2333
2333
|
function vibrate(pattern=100)
|
|
2334
2334
|
{ vibrateEnable && navigator && navigator.vibrate && navigator.vibrate(pattern); }
|
|
@@ -3135,7 +3135,7 @@ function getTileCollisionData(pos)
|
|
|
3135
3135
|
|
|
3136
3136
|
/** Check if collision with another object should occur
|
|
3137
3137
|
* @param {Vector2} pos
|
|
3138
|
-
* @param {Vector2} [size=
|
|
3138
|
+
* @param {Vector2} [size=(1,1)]
|
|
3139
3139
|
* @param {EngineObject} [object]
|
|
3140
3140
|
* @return {Boolean}
|
|
3141
3141
|
* @memberof TileCollision */
|
|
@@ -3251,11 +3251,11 @@ class TileLayerData
|
|
|
3251
3251
|
class TileLayer extends EngineObject
|
|
3252
3252
|
{
|
|
3253
3253
|
/** Create a tile layer object
|
|
3254
|
-
* @param {Vector2} [position=
|
|
3254
|
+
* @param {Vector2} [position=(0,0)] - World space position
|
|
3255
3255
|
* @param {Vector2} [size=tileCollisionSize] - World space size
|
|
3256
|
-
* @param {TileInfo} [tileInfo]
|
|
3257
|
-
* @param {Vector2} [scale=
|
|
3258
|
-
* @param {Number} [renderOrder]
|
|
3256
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
3257
|
+
* @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
|
|
3258
|
+
* @param {Number} [renderOrder] - Objects are sorted by renderOrder
|
|
3259
3259
|
*/
|
|
3260
3260
|
constructor(position, size=tileCollisionSize, tileInfo=tile(), scale=vec2(1), renderOrder=0)
|
|
3261
3261
|
{
|
|
@@ -3316,16 +3316,18 @@ class TileLayer extends EngineObject
|
|
|
3316
3316
|
}
|
|
3317
3317
|
|
|
3318
3318
|
/** Draw all the tile data to an offscreen canvas
|
|
3319
|
-
* - This may be slow in some browsers
|
|
3320
|
-
*/
|
|
3319
|
+
* - This may be slow in some browsers but only needs to be done once */
|
|
3321
3320
|
redraw()
|
|
3322
3321
|
{
|
|
3323
3322
|
this.redrawStart(true);
|
|
3324
|
-
this.
|
|
3323
|
+
for (let x = this.size.x; x--;)
|
|
3324
|
+
for (let y = this.size.y; y--;)
|
|
3325
|
+
this.drawTileData(vec2(x,y), false);
|
|
3325
3326
|
this.redrawEnd();
|
|
3326
3327
|
}
|
|
3327
3328
|
|
|
3328
3329
|
/** Call to start the redraw process
|
|
3330
|
+
* - This can be used to manually update small parts of the level
|
|
3329
3331
|
* @param {Boolean} [clear] - Should it clear the canvas before drawing */
|
|
3330
3332
|
redrawStart(clear=false)
|
|
3331
3333
|
{
|
|
@@ -3333,17 +3335,19 @@ class TileLayer extends EngineObject
|
|
|
3333
3335
|
/** @type {[HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number]} */
|
|
3334
3336
|
this.savedRenderSettings = [mainCanvas, mainContext, mainCanvasSize, cameraPos, cameraScale];
|
|
3335
3337
|
|
|
3336
|
-
//
|
|
3338
|
+
// use webgl rendering system to render the tiles if enabled
|
|
3339
|
+
// this works by temporally taking control of the rendering system
|
|
3337
3340
|
mainCanvas = this.canvas;
|
|
3338
3341
|
mainContext = this.context;
|
|
3342
|
+
mainCanvasSize = this.size.multiply(this.tileInfo.size);
|
|
3339
3343
|
cameraPos = this.size.scale(.5);
|
|
3340
3344
|
cameraScale = this.tileInfo.size.x;
|
|
3341
3345
|
|
|
3342
3346
|
if (clear)
|
|
3343
3347
|
{
|
|
3344
3348
|
// clear and set size
|
|
3345
|
-
mainCanvas.width =
|
|
3346
|
-
mainCanvas.height =
|
|
3349
|
+
mainCanvas.width = mainCanvasSize.x;
|
|
3350
|
+
mainCanvas.height = mainCanvasSize.y;
|
|
3347
3351
|
}
|
|
3348
3352
|
|
|
3349
3353
|
// begin a new render for the tile canvas
|
|
@@ -3361,32 +3365,33 @@ class TileLayer extends EngineObject
|
|
|
3361
3365
|
[mainCanvas, mainContext, mainCanvasSize, cameraPos, cameraScale] = this.savedRenderSettings;
|
|
3362
3366
|
}
|
|
3363
3367
|
|
|
3364
|
-
/** Draw the tile at a given position
|
|
3365
|
-
*
|
|
3366
|
-
|
|
3368
|
+
/** Draw the tile at a given position in the tile grid
|
|
3369
|
+
* This can be used to clear out tiles when they are destroyed
|
|
3370
|
+
* Tiles can also be redrawn if isinde a redrawStart/End block
|
|
3371
|
+
* @param {Vector2} layerPos
|
|
3372
|
+
* @param {Boolean} [clear] - should the old tile be cleared out
|
|
3373
|
+
*/
|
|
3374
|
+
drawTileData(layerPos, clear=true)
|
|
3367
3375
|
{
|
|
3368
|
-
//
|
|
3369
|
-
const
|
|
3370
|
-
|
|
3376
|
+
// clear out where the tile was, for full opaque tiles this can be skipped
|
|
3377
|
+
const s = this.tileInfo.size;
|
|
3378
|
+
if (clear)
|
|
3379
|
+
{
|
|
3380
|
+
const pos = layerPos.multiply(s);
|
|
3381
|
+
this.context.clearRect(pos.x, this.canvas.height-pos.y, s.x, -s.y);
|
|
3382
|
+
}
|
|
3371
3383
|
|
|
3372
3384
|
// draw the tile if not undefined
|
|
3373
3385
|
const d = this.getData(layerPos);
|
|
3374
3386
|
if (d.tile != undefined)
|
|
3375
3387
|
{
|
|
3388
|
+
const pos = this.pos.add(layerPos).add(vec2(.5));
|
|
3376
3389
|
ASSERT(mainContext == this.context, 'must call redrawStart() before drawing tiles');
|
|
3377
|
-
const tileInfo = tile(d.tile,
|
|
3390
|
+
const tileInfo = tile(d.tile, s, this.tileInfo.textureIndex);
|
|
3378
3391
|
drawTile(pos, vec2(1), tileInfo, d.color, d.direction*PI/2, d.mirror);
|
|
3379
3392
|
}
|
|
3380
3393
|
}
|
|
3381
3394
|
|
|
3382
|
-
/** Draw all the tiles in this layer */
|
|
3383
|
-
drawAllTileData()
|
|
3384
|
-
{
|
|
3385
|
-
for (let x = this.size.x; x--;)
|
|
3386
|
-
for (let y = this.size.y; y--;)
|
|
3387
|
-
this.drawTileData(vec2(x,y));
|
|
3388
|
-
}
|
|
3389
|
-
|
|
3390
3395
|
/** Draw directly to the 2D canvas in world space (bipass webgl)
|
|
3391
3396
|
* @param {Vector2} pos
|
|
3392
3397
|
* @param {Vector2} size
|
|
@@ -3406,11 +3411,11 @@ class TileLayer extends EngineObject
|
|
|
3406
3411
|
context.restore();
|
|
3407
3412
|
}
|
|
3408
3413
|
|
|
3409
|
-
/** Draw a tile directly onto the layer canvas
|
|
3414
|
+
/** Draw a tile directly onto the layer canvas in world space
|
|
3410
3415
|
* @param {Vector2} pos
|
|
3411
|
-
* @param {Vector2} [size=
|
|
3416
|
+
* @param {Vector2} [size=(1,1)]
|
|
3412
3417
|
* @param {TileInfo} [tileInfo]
|
|
3413
|
-
* @param {Color} [color=
|
|
3418
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
3414
3419
|
* @param {Number} [angle=0]
|
|
3415
3420
|
* @param {Boolean} [mirror=0] */
|
|
3416
3421
|
drawTile(pos, size=vec2(1), tileInfo, color=new Color, angle, mirror)
|
|
@@ -3435,10 +3440,10 @@ class TileLayer extends EngineObject
|
|
|
3435
3440
|
});
|
|
3436
3441
|
}
|
|
3437
3442
|
|
|
3438
|
-
/** Draw a rectangle directly onto the layer canvas
|
|
3443
|
+
/** Draw a rectangle directly onto the layer canvas in world space
|
|
3439
3444
|
* @param {Vector2} pos
|
|
3440
|
-
* @param {Vector2} [size=
|
|
3441
|
-
* @param {Color} [color=
|
|
3445
|
+
* @param {Vector2} [size=(1,1)]
|
|
3446
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
3442
3447
|
* @param {Number} [angle=0] */
|
|
3443
3448
|
drawRect(pos, size, color, angle)
|
|
3444
3449
|
{ this.drawTile(pos, size, undefined, color, angle); }
|
|
@@ -3476,10 +3481,10 @@ class ParticleEmitter extends EngineObject
|
|
|
3476
3481
|
* @param {Number} [emitRate] - How many particles per second to spawn, does not emit if 0
|
|
3477
3482
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
3478
3483
|
* @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
|
|
3479
|
-
* @param {Color} [colorStartA=
|
|
3480
|
-
* @param {Color} [colorStartB=
|
|
3481
|
-
* @param {Color} [colorEndA=
|
|
3482
|
-
* @param {Color} [colorEndB=
|
|
3484
|
+
* @param {Color} [colorStartA=(1,1,1,1)] - Color at start of life 1, randomized between start colors
|
|
3485
|
+
* @param {Color} [colorStartB=(1,1,1,1)] - Color at start of life 2, randomized between start colors
|
|
3486
|
+
* @param {Color} [colorEndA=(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
3487
|
+
* @param {Color} [colorEndB=(1,1,1,0)] - Color at end of life 2, randomized between end colors
|
|
3483
3488
|
* @param {Number} [particleTime] - How long particles live
|
|
3484
3489
|
* @param {Number} [sizeStart] - How big are particles at start
|
|
3485
3490
|
* @param {Number} [sizeEnd] - How big are particles at end
|
|
@@ -4317,6 +4322,8 @@ function glCopyToContext(context, forceDraw=false)
|
|
|
4317
4322
|
* @memberof WebGL */
|
|
4318
4323
|
function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdditive=0)
|
|
4319
4324
|
{
|
|
4325
|
+
ASSERT(typeof rgba == 'number' && typeof rgbaAdditive == 'number', 'invalid color');
|
|
4326
|
+
|
|
4320
4327
|
// flush if there is not enough room or if different blend mode
|
|
4321
4328
|
if (glInstanceCount >= gl_MAX_INSTANCES-1 || glBatchAdditive != glAdditive)
|
|
4322
4329
|
glFlush();
|
|
@@ -4345,7 +4352,7 @@ let glPostShader, glPostArrayBuffer, glPostTexture, glPostIncludeOverlay;
|
|
|
4345
4352
|
* @param {String} shaderCode
|
|
4346
4353
|
* @param {Boolean} includeOverlay
|
|
4347
4354
|
* @memberof WebGL */
|
|
4348
|
-
function glInitPostProcess(shaderCode, includeOverlay)
|
|
4355
|
+
function glInitPostProcess(shaderCode, includeOverlay=false)
|
|
4349
4356
|
{
|
|
4350
4357
|
ASSERT(!glPostShader, 'can only have 1 post effects shader');
|
|
4351
4358
|
|
|
@@ -4381,6 +4388,8 @@ function glInitPostProcess(shaderCode, includeOverlay)
|
|
|
4381
4388
|
|
|
4382
4389
|
// hide the original 2d canvas
|
|
4383
4390
|
mainCanvas.style.visibility = 'hidden';
|
|
4391
|
+
if (glPostIncludeOverlay)
|
|
4392
|
+
overlayCanvas.style.visibility = 'hidden';
|
|
4384
4393
|
}
|
|
4385
4394
|
|
|
4386
4395
|
// Render the post processing shader, called automatically by the engine
|
|
@@ -4401,14 +4410,8 @@ function glRenderPostProcess()
|
|
|
4401
4410
|
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
4402
4411
|
}
|
|
4403
4412
|
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
// copy overlay canvas so it will be included in post processing
|
|
4407
|
-
mainContext.drawImage(overlayCanvas, 0, 0);
|
|
4408
|
-
|
|
4409
|
-
// clear overlay canvas
|
|
4410
|
-
overlayCanvas.width = mainCanvas.width;
|
|
4411
|
-
}
|
|
4413
|
+
// copy overlay canvas so it will be included in post processing
|
|
4414
|
+
glPostIncludeOverlay && mainContext.drawImage(overlayCanvas, 0, 0);
|
|
4412
4415
|
|
|
4413
4416
|
// setup shader program to draw one triangle
|
|
4414
4417
|
glContext.useProgram(glPostShader);
|
|
@@ -4502,7 +4505,7 @@ const engineName = 'LittleJS';
|
|
|
4502
4505
|
* @type {String}
|
|
4503
4506
|
* @default
|
|
4504
4507
|
* @memberof Engine */
|
|
4505
|
-
const engineVersion = '1.9.
|
|
4508
|
+
const engineVersion = '1.9.1';
|
|
4506
4509
|
|
|
4507
4510
|
/** Frames per second to update objects
|
|
4508
4511
|
* @type {Number}
|
package/examples/js13k/build.js
CHANGED
|
@@ -26,7 +26,7 @@ const fs = require('node:fs');
|
|
|
26
26
|
const child_process = require('node:child_process');
|
|
27
27
|
|
|
28
28
|
// rebuild engine
|
|
29
|
-
child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
29
|
+
//child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
30
30
|
|
|
31
31
|
// remove old files and setup build folder
|
|
32
32
|
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
@@ -27,7 +27,7 @@ const fs = require('node:fs');
|
|
|
27
27
|
const child_process = require('node:child_process');
|
|
28
28
|
|
|
29
29
|
// rebuild engine
|
|
30
|
-
child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
30
|
+
//child_process.execSync(`npm run build`, { stdio: 'inherit' });
|
|
31
31
|
|
|
32
32
|
// remove old files and setup build folder
|
|
33
33
|
fs.rmSync(BUILD_FOLDER, { recursive: true, force: true });
|
|
@@ -118,7 +118,7 @@ function gameRender()
|
|
|
118
118
|
statsDisplay.style.top = canvasRect.top+'px';
|
|
119
119
|
statsDisplay.style.fontSize = canvasRect.width*.04+'px';
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
// update sprites
|
|
122
122
|
for (const sprite of sprites)
|
|
123
123
|
{
|
|
124
124
|
// keep sprites above 0
|