littlejsengine 1.14.28 → 1.15.2
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/dist/littlejs.d.ts +85 -10
- package/dist/littlejs.esm.js +212 -18
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +211 -18
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +211 -18
- package/examples/electron/index.html +2 -2
- package/examples/index.html +1 -0
- package/examples/shorts/base.html +2 -2
- package/examples/shorts/song.mp3 +0 -0
- package/examples/shorts/video.webm +0 -0
- package/examples/shorts/videoPlayer.js +33 -0
- package/examples/starter/index.html +3 -3
- package/package.json +1 -1
- package/plugins/pluginExport.js +1 -0
- package/plugins/uiSystem.js +174 -0
- package/src/engine.js +5 -5
- package/src/engineDraw.js +1 -1
- package/src/engineParticles.js +3 -0
- package/src/engineUtilities.js +28 -12
package/src/engine.js
CHANGED
|
@@ -30,7 +30,7 @@ const engineName = 'LittleJS';
|
|
|
30
30
|
* @type {string}
|
|
31
31
|
* @default
|
|
32
32
|
* @memberof Engine */
|
|
33
|
-
const engineVersion = '1.15.
|
|
33
|
+
const engineVersion = '1.15.2';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update
|
|
36
36
|
* @type {number}
|
|
@@ -131,7 +131,7 @@ function engineAddPlugin(update, render, glContextLost, glContextRestored)
|
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
133
|
* @callback GameInitCallback - Called after the engine starts, can be async
|
|
134
|
-
* @
|
|
134
|
+
* @return {void|Promise<void>}
|
|
135
135
|
* @memberof Engine
|
|
136
136
|
*/
|
|
137
137
|
/**
|
|
@@ -487,10 +487,10 @@ function engineObjectsDestroy()
|
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
/** Collects all object within a given area
|
|
490
|
-
* @param {Vector2} [pos]
|
|
491
|
-
* @param {Vector2|number} [size]
|
|
490
|
+
* @param {Vector2} [pos] - Center of test area, or undefined for all objects
|
|
491
|
+
* @param {Vector2|number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
492
492
|
* @param {Array<EngineObject>} [objects=engineObjects] - List of objects to check
|
|
493
|
-
* @return {Array<EngineObject>}
|
|
493
|
+
* @return {Array<EngineObject>} - List of collected objects
|
|
494
494
|
* @memberof Engine */
|
|
495
495
|
function engineObjectsCollect(pos, size, objects=engineObjects)
|
|
496
496
|
{
|
package/src/engineDraw.js
CHANGED
|
@@ -294,7 +294,7 @@ function drawTile(pos, size=new Vector2(1), tileInfo, color=WHITE,
|
|
|
294
294
|
{
|
|
295
295
|
// normal canvas 2D rendering method (slower)
|
|
296
296
|
++drawCount;
|
|
297
|
-
size = new Vector2(size.x, -size.y); //
|
|
297
|
+
size = new Vector2(size.x, -size.y); // flip upside down sprites
|
|
298
298
|
drawCanvas2D(pos, size, angle, mirror, (context)=>
|
|
299
299
|
{
|
|
300
300
|
if (textureInfo)
|
package/src/engineParticles.js
CHANGED
|
@@ -160,6 +160,9 @@ class ParticleEmitter extends EngineObject
|
|
|
160
160
|
this.previousPos = this.pos.copy();
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/** Emitters do not have physics */
|
|
164
|
+
updatePhysics() {}
|
|
165
|
+
|
|
163
166
|
/** Update the emitter to spawn particles, called automatically by engine once each frame */
|
|
164
167
|
update()
|
|
165
168
|
{
|
package/src/engineUtilities.js
CHANGED
|
@@ -148,7 +148,7 @@ function percentLerp(value, percentA, percentB, lerpA, lerpB)
|
|
|
148
148
|
* @param {number} valueA
|
|
149
149
|
* @param {number} valueB
|
|
150
150
|
* @param {number} [wrapSize]
|
|
151
|
-
* @
|
|
151
|
+
* @return {number}
|
|
152
152
|
* @memberof Utilities */
|
|
153
153
|
function distanceWrap(valueA, valueB, wrapSize=1)
|
|
154
154
|
{ const d = (valueA - valueB) % wrapSize; return d*2 % wrapSize - d; }
|
|
@@ -158,7 +158,7 @@ function distanceWrap(valueA, valueB, wrapSize=1)
|
|
|
158
158
|
* @param {number} valueB
|
|
159
159
|
* @param {number} percent
|
|
160
160
|
* @param {number} [wrapSize]
|
|
161
|
-
* @
|
|
161
|
+
* @return {number}
|
|
162
162
|
* @memberof Utilities */
|
|
163
163
|
function lerpWrap(valueA, valueB, percent, wrapSize=1)
|
|
164
164
|
{
|
|
@@ -170,7 +170,7 @@ function lerpWrap(valueA, valueB, percent, wrapSize=1)
|
|
|
170
170
|
/** Returns signed wrapped distance between the two angles passed in
|
|
171
171
|
* @param {number} angleA
|
|
172
172
|
* @param {number} angleB
|
|
173
|
-
* @
|
|
173
|
+
* @return {number}
|
|
174
174
|
* @memberof Utilities */
|
|
175
175
|
function distanceAngle(angleA, angleB) { return distanceWrap(angleA, angleB, 2*PI); }
|
|
176
176
|
|
|
@@ -178,7 +178,7 @@ function distanceAngle(angleA, angleB) { return distanceWrap(angleA, angleB, 2*P
|
|
|
178
178
|
* @param {number} angleA
|
|
179
179
|
* @param {number} angleB
|
|
180
180
|
* @param {number} percent
|
|
181
|
-
* @
|
|
181
|
+
* @return {number}
|
|
182
182
|
* @memberof Utilities */
|
|
183
183
|
function lerpAngle(angleA, angleB, percent) { return lerpWrap(angleA, angleB, percent, 2*PI); }
|
|
184
184
|
|
|
@@ -1147,11 +1147,14 @@ const MAGENTA = debugProtectConstant(rgb(1,0,1));
|
|
|
1147
1147
|
class Timer
|
|
1148
1148
|
{
|
|
1149
1149
|
/** Create a timer object set time passed in
|
|
1150
|
-
* @param {number} [timeLeft] - How much time left before the timer
|
|
1151
|
-
|
|
1150
|
+
* @param {number} [timeLeft] - How much time left before the timer
|
|
1151
|
+
* @param {boolean} [useRealTime] - Should the timer keep running even when the game is paused? (useful for UI) */
|
|
1152
|
+
constructor(timeLeft, useRealTime=false)
|
|
1152
1153
|
{
|
|
1153
1154
|
ASSERT(timeLeft === undefined || isNumber(timeLeft), 'Constructed Timer is invalid.', timeLeft);
|
|
1154
|
-
this.
|
|
1155
|
+
this.useRealTime = useRealTime;
|
|
1156
|
+
const globalTime = this.getGlobalTime();
|
|
1157
|
+
this.time = timeLeft === undefined ? undefined : globalTime + timeLeft;
|
|
1155
1158
|
this.setTime = timeLeft;
|
|
1156
1159
|
}
|
|
1157
1160
|
|
|
@@ -1160,10 +1163,19 @@ class Timer
|
|
|
1160
1163
|
set(timeLeft=0)
|
|
1161
1164
|
{
|
|
1162
1165
|
ASSERT(isNumber(timeLeft), 'Timer is invalid.', timeLeft);
|
|
1163
|
-
|
|
1166
|
+
const globalTime = this.getGlobalTime();
|
|
1167
|
+
this.time = globalTime + timeLeft;
|
|
1164
1168
|
this.setTime = timeLeft;
|
|
1165
1169
|
}
|
|
1166
1170
|
|
|
1171
|
+
/** Set if the timer should keep running even when the game is paused
|
|
1172
|
+
* @param {boolean} [useRealTime] */
|
|
1173
|
+
setUseRealTime(useRealTime=true)
|
|
1174
|
+
{
|
|
1175
|
+
ASSERT(!this.isSet(), 'Cannot change global time setting while timer is set.');
|
|
1176
|
+
this.useRealTime = useRealTime;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1167
1179
|
/** Unset the timer */
|
|
1168
1180
|
unset() { this.time = undefined; }
|
|
1169
1181
|
|
|
@@ -1173,24 +1185,28 @@ class Timer
|
|
|
1173
1185
|
|
|
1174
1186
|
/** Returns true if set and has not elapsed
|
|
1175
1187
|
* @return {boolean} */
|
|
1176
|
-
active() { return
|
|
1188
|
+
active() { return this.getGlobalTime() < this.time; }
|
|
1177
1189
|
|
|
1178
1190
|
/** Returns true if set and elapsed
|
|
1179
1191
|
* @return {boolean} */
|
|
1180
|
-
elapsed() { return
|
|
1192
|
+
elapsed() { return this.getGlobalTime() >= this.time; }
|
|
1181
1193
|
|
|
1182
1194
|
/** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
|
|
1183
1195
|
* @return {number} */
|
|
1184
|
-
get() { return this.isSet()?
|
|
1196
|
+
get() { return this.isSet()? this.getGlobalTime() - this.time : 0; }
|
|
1185
1197
|
|
|
1186
1198
|
/** Get percentage elapsed based on time it was set to, returns 0 if not set
|
|
1187
1199
|
* @return {number} */
|
|
1188
|
-
getPercent() { return this.isSet()? 1-percent(this.time -
|
|
1200
|
+
getPercent() { return this.isSet()? 1-percent(this.time - this.getGlobalTime(), 0, this.setTime) : 0; }
|
|
1189
1201
|
|
|
1190
1202
|
/** Get the time this timer was set to, returns 0 if not set
|
|
1191
1203
|
* @return {number} */
|
|
1192
1204
|
getSetTime() { return this.isSet() ? this.setTime : 0; }
|
|
1193
1205
|
|
|
1206
|
+
/** Get the current global time this timer is based on
|
|
1207
|
+
* @return {number} */
|
|
1208
|
+
getGlobalTime() { return this.useRealTime ? timeReal : time; }
|
|
1209
|
+
|
|
1194
1210
|
/** Returns this timer expressed as a string
|
|
1195
1211
|
* @return {string} */
|
|
1196
1212
|
toString() { return this.isSet() ? abs(this.get()) + ' seconds ' + (this.get()<0 ? 'before' : 'after' ) : 'unset'; }
|