littlejsengine 1.18.2 → 1.18.4
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/AI.md +1 -0
- package/LICENSE +5 -27
- package/dist/littlejs.d.ts +201 -3
- package/dist/littlejs.esm.js +713 -18
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +701 -18
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +701 -18
- package/examples/index.html +62 -800
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/textureWrapped.js +12 -0
- package/examples/shorts/tween.js +24 -0
- package/examples/shorts.js +743 -0
- package/examples/starter/index.html +2 -2
- package/examples/tweenSystem/game.js +171 -0
- package/examples/tweenSystem/index.html +10 -0
- package/examples/tweenSystem/tiles.png +0 -0
- package/package.json +1 -1
- package/plugins/box2d.js +4 -2
- package/plugins/pluginExport.js +7 -0
- package/plugins/tween.js +509 -0
- package/plugins/uiSystem.js +1 -1
- package/reference.md +1 -0
- package/src/engine.js +9 -6
- package/src/engineBuild.mjs +1 -0
- package/src/engineDraw.js +133 -2
- package/src/engineExport.js +5 -0
- package/src/engineInput.js +26 -0
- package/src/engineSettings.js +17 -0
- package/src/engineWebGL.js +3 -7
- package/test/smoke.test.mjs +16 -0
- package/test/tween.test.mjs +576 -0
- package/.claude/settings.local.json +0 -7
package/AI.md
CHANGED
|
@@ -141,6 +141,7 @@ drawEllipse(pos, size, color) // filled ellipse
|
|
|
141
141
|
|
|
142
142
|
## Common pitfalls
|
|
143
143
|
|
|
144
|
+
- **New public APIs must be added to `src/engineExport.js`** - Variables and functions added to engine source files are accessible in script-tag builds automatically, but the ESM build (`littlejs.esm.js`) and TypeScript definitions (`littlejs.d.ts`) only include what's listed in `engineExport.js`. Plugin exports go in `plugins/pluginExport.js`. Forgetting this means ESM/TS users can't access the new API.
|
|
144
145
|
- **ASSERT and LOG are stripped in release builds** - Don't rely on side effects
|
|
145
146
|
- **Don't modify constant colors** - `WHITE`, `BLACK`, `RED`, etc. are frozen; use `.copy()` first
|
|
146
147
|
- **Time variables are global** - `time`, `frame` update automatically each frame
|
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
The MIT License
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2021 Frank Force http://www.frankforce.com
|
|
4
4
|
|
|
@@ -9,35 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
|
10
10
|
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
copies or substantial portions of the Software.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
14
|
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
-------------------------------------------------------------------------------
|
|
24
|
-
|
|
25
|
-
Box2D License
|
|
26
|
-
|
|
27
|
-
Copyright (c) 2006-2013 Erin Catto http://www.gphysics.com
|
|
28
|
-
|
|
29
|
-
This software is provided 'as-is', without any express or implied
|
|
30
|
-
warranty. In no event will the authors be held liable for any damages
|
|
31
|
-
arising from the use of this software.
|
|
32
|
-
|
|
33
|
-
Permission is granted to anyone to use this software for any purpose,
|
|
34
|
-
including commercial applications, and to alter it and redistribute it
|
|
35
|
-
freely, subject to the following restrictions:
|
|
36
|
-
|
|
37
|
-
1. The origin of this software must not be misrepresented; you must not
|
|
38
|
-
claim that you wrote the original software. If you use this software
|
|
39
|
-
in a product, an acknowledgment in the product documentation would be
|
|
40
|
-
appreciated but is not required.
|
|
41
|
-
2. Altered source versions must be plainly marked as such, and must not be
|
|
42
|
-
misrepresented as being the original software.
|
|
43
|
-
3. This notice may not be removed or altered from any source distribution.
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ declare module "littlejsengine" {
|
|
|
96
96
|
* @type {number}
|
|
97
97
|
* @memberof Engine */
|
|
98
98
|
export let time: number;
|
|
99
|
-
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
99
|
+
/** Actual clock time since start in seconds (not affected by pause, timescale, or frame rate clamping)
|
|
100
100
|
* @type {number}
|
|
101
101
|
* @memberof Engine */
|
|
102
102
|
export let timeReal: number;
|
|
@@ -333,6 +333,14 @@ declare module "littlejsengine" {
|
|
|
333
333
|
* @default
|
|
334
334
|
* @memberof Settings */
|
|
335
335
|
export let cameraScale: number;
|
|
336
|
+
/** Scale applied to engine time, can be used for slow motion or fast forward
|
|
337
|
+
* - 1 is normal speed, 2 is double speed, 0.5 is half speed
|
|
338
|
+
* - 0 freezes the simulation without setting the paused flag
|
|
339
|
+
* - Should be >= 0; stacks multiplicatively with the debug +/- shortcut
|
|
340
|
+
* @type {number}
|
|
341
|
+
* @default
|
|
342
|
+
* @memberof Settings */
|
|
343
|
+
export let timeScale: number;
|
|
336
344
|
/** Enable applying color to tiles when using canvas2d
|
|
337
345
|
* - This is slower but should be the same as WebGL rendering
|
|
338
346
|
* @type {boolean}
|
|
@@ -567,6 +575,10 @@ declare module "littlejsengine" {
|
|
|
567
575
|
* @param {number} scale
|
|
568
576
|
* @memberof Settings */
|
|
569
577
|
export function setCameraScale(scale: number): void;
|
|
578
|
+
/** Set scale applied to engine time
|
|
579
|
+
* @param {number} scale
|
|
580
|
+
* @memberof Settings */
|
|
581
|
+
export function setTimeScale(scale: number): void;
|
|
570
582
|
/** Set if tiles should be colorized when using canvas2d
|
|
571
583
|
* This can be slower but results should look nearly identical to WebGL rendering
|
|
572
584
|
* It can be enabled/disabled at any time
|
|
@@ -1733,6 +1745,21 @@ declare module "littlejsengine" {
|
|
|
1733
1745
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1734
1746
|
* @memberof Draw */
|
|
1735
1747
|
export function drawRectGradient(pos: Vector2, size?: Vector2, colorTop?: Color, colorBottom?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1748
|
+
/** Draw a texture tiled (wrapped) across a rectangle in world space.
|
|
1749
|
+
* Useful for backgrounds, repeating patterns, and seamless fills.
|
|
1750
|
+
* The whole texture is tiled — sub-region (TileInfo) wrapping is not supported.
|
|
1751
|
+
* @param {Vector2} pos - Center of the rect in world space
|
|
1752
|
+
* @param {Vector2} size - Size of the rect in world space
|
|
1753
|
+
* @param {Vector2} wrapCount - How many times the texture repeats (x, y)
|
|
1754
|
+
* @param {TextureInfo|number} [texture=0] - TextureInfo or texture index into textureInfos
|
|
1755
|
+
* @param {Color} [color=WHITE] - Color to modulate with
|
|
1756
|
+
* @param {number} [angle=0] - Angle to rotate by
|
|
1757
|
+
* @param {Color} [additiveColor] - Additive color to be applied if any
|
|
1758
|
+
* @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering?
|
|
1759
|
+
* @param {boolean} [screenSpace=false] - Are pos and size in screen space?
|
|
1760
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
|
|
1761
|
+
* @memberof Draw */
|
|
1762
|
+
export function drawTextureWrapped(pos: Vector2, size: Vector2, wrapCount: Vector2, texture?: TextureInfo | number, color?: Color, angle?: number, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1736
1763
|
/** Draw connected lines between a series of points
|
|
1737
1764
|
* @param {Array<Vector2>} points
|
|
1738
1765
|
* @param {number} [width]
|
|
@@ -1943,9 +1970,8 @@ declare module "littlejsengine" {
|
|
|
1943
1970
|
/** Set the WebGL texture, called automatically if using multiple textures
|
|
1944
1971
|
* - This may also flush the gl buffer resulting in more draw calls and worse performance
|
|
1945
1972
|
* @param {WebGLTexture} texture
|
|
1946
|
-
* @param {boolean} [wrap] - Should the texture wrap or clamp
|
|
1947
1973
|
* @memberof WebGL */
|
|
1948
|
-
export function glSetTexture(texture: WebGLTexture
|
|
1974
|
+
export function glSetTexture(texture: WebGLTexture): void;
|
|
1949
1975
|
/** Compile WebGL shader of the given type, will throw errors if in debug mode
|
|
1950
1976
|
* @param {string} source
|
|
1951
1977
|
* @param {number} type
|
|
@@ -2189,6 +2215,18 @@ declare module "littlejsengine" {
|
|
|
2189
2215
|
* @return {boolean}
|
|
2190
2216
|
* @memberof Input */
|
|
2191
2217
|
export function gamepadConnected(gamepad?: number): boolean;
|
|
2218
|
+
/** Pulse a gamepad's vibration hardware using the dual-rumble effect if it exists
|
|
2219
|
+
* Strong magnitude is usually the left side motor, weak magnitude is usually the right side motor
|
|
2220
|
+
* @param {number} [gamepad] - gamepad index
|
|
2221
|
+
* @param {number} [duration] - effect duration in ms
|
|
2222
|
+
* @param {number} [strongMagnitude] - strong (left) motor intensity, 0 to 1
|
|
2223
|
+
* @param {number} [weakMagnitude] - weak (right) motor intensity, 0 to 1
|
|
2224
|
+
* @param {number} [startDelay] - delay in ms before the effect starts
|
|
2225
|
+
* @memberof Input */
|
|
2226
|
+
export function gamepadVibrate(gamepad?: number, duration?: number, strongMagnitude?: number, weakMagnitude?: number, startDelay?: number): void;
|
|
2227
|
+
/** Stop vibration on a gamepad
|
|
2228
|
+
* @memberof Input */
|
|
2229
|
+
export function gamepadVibrateStop(gamepad?: number): void;
|
|
2192
2230
|
/** Pulse the vibration hardware if it exists
|
|
2193
2231
|
* @param {number|Array} [pattern] - single value in ms or vibration interval array
|
|
2194
2232
|
* @memberof Input */
|
|
@@ -4873,4 +4911,164 @@ declare module "littlejsengine" {
|
|
|
4873
4911
|
* @param {number} [angle] - Angle to rotate by
|
|
4874
4912
|
* @memberof DrawUtilities */
|
|
4875
4913
|
export function drawThreeSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number, angle?: number): void;
|
|
4914
|
+
/** A numeric tween: drives a callback with a value interpolated between
|
|
4915
|
+
* `start` and `end` over `duration` seconds. Pauses with the game by default.
|
|
4916
|
+
* @memberof TweenSystem
|
|
4917
|
+
* @example
|
|
4918
|
+
* // Animate a fade-out over 2 seconds with an ease-out sine curve.
|
|
4919
|
+
* new Tween((v) => obj.alpha = v, 1, 0, 2, { ease: Ease.OUT(Ease.SINE) });
|
|
4920
|
+
*/
|
|
4921
|
+
export class Tween {
|
|
4922
|
+
/** Create a new tween. The callback fires immediately with `start` so the
|
|
4923
|
+
* target snaps to the start value on the same frame the tween is created.
|
|
4924
|
+
*
|
|
4925
|
+
* `start` and `end` may be numbers, Vector2 instances, Color instances, or
|
|
4926
|
+
* any object exposing a `lerp(other, percent) => sameType` method. The
|
|
4927
|
+
* callback receives the interpolated value (a number, or a fresh instance
|
|
4928
|
+
* for lerp-able types). Both endpoints must be the same type.
|
|
4929
|
+
* @param {function(number|Vector2|Color):void} callback - Called with the interpolated value each frame
|
|
4930
|
+
* @param {number|Vector2|Color} [start=0] - Starting value
|
|
4931
|
+
* @param {number|Vector2|Color} [end=1] - Ending value
|
|
4932
|
+
* @param {number} [duration=1] - Duration in seconds
|
|
4933
|
+
* @param {Object} [options]
|
|
4934
|
+
* @param {function(number):number} [options.ease] - Easing function (defaults to LINEAR)
|
|
4935
|
+
* @param {boolean} [options.useRealTime=false] - Advance even when the game is paused (matches Timer's useRealTime)
|
|
4936
|
+
* @param {boolean} [options.paused=false] - Start in paused state */
|
|
4937
|
+
constructor(callback: (arg0: number | Vector2 | Color) => void, start?: number | Vector2 | Color, end?: number | Vector2 | Color, duration?: number, options?: {
|
|
4938
|
+
ease?: (arg0: number) => number;
|
|
4939
|
+
useRealTime?: boolean;
|
|
4940
|
+
paused?: boolean;
|
|
4941
|
+
});
|
|
4942
|
+
callback: (arg0: number | Vector2 | Color) => void;
|
|
4943
|
+
start: number | Vector2 | Color;
|
|
4944
|
+
end: number | Vector2 | Color;
|
|
4945
|
+
duration: number;
|
|
4946
|
+
life: number;
|
|
4947
|
+
ease: (arg0: number) => number;
|
|
4948
|
+
useRealTime: boolean;
|
|
4949
|
+
paused: boolean;
|
|
4950
|
+
/** @private completion callback set by then(), loop(), pingPong(). */
|
|
4951
|
+
private thenCallback;
|
|
4952
|
+
/** @private remaining iterations including the current run (loop/pingPong only). */
|
|
4953
|
+
private loopRemaining;
|
|
4954
|
+
/** Set the easing curve and return this for chaining.
|
|
4955
|
+
* @param {function(number):number} easeFn
|
|
4956
|
+
* @returns {Tween}
|
|
4957
|
+
* @memberof TweenSystem */
|
|
4958
|
+
setEase(easeFn: (arg0: number) => number): Tween;
|
|
4959
|
+
/** Set a single completion callback. Calling `then` again replaces the
|
|
4960
|
+
* previous callback. Returns this for chaining.
|
|
4961
|
+
*
|
|
4962
|
+
* Calling `then` after `loop` or `pingPong` overrides the loop chain
|
|
4963
|
+
* (last call wins).
|
|
4964
|
+
* @param {function():void} callback
|
|
4965
|
+
* @returns {Tween}
|
|
4966
|
+
* @memberof TweenSystem */
|
|
4967
|
+
then(callback: () => void): Tween;
|
|
4968
|
+
/** Repeat this tween `n` total times. After each iteration finishes, a
|
|
4969
|
+
* fresh tween with the same parameters takes over via the `then` slot.
|
|
4970
|
+
* `loop()` with no argument loops forever.
|
|
4971
|
+
*
|
|
4972
|
+
* Mutually exclusive with `pingPong`; calling either replaces the other,
|
|
4973
|
+
* and calling `then` after either clears the loop (last call wins).
|
|
4974
|
+
* @param {number} [count=Infinity]
|
|
4975
|
+
* @returns {Tween}
|
|
4976
|
+
* @memberof TweenSystem */
|
|
4977
|
+
loop(count?: number): Tween;
|
|
4978
|
+
/** Like `loop`, but swap `start` and `end` between iterations so the value
|
|
4979
|
+
* bounces back and forth. `pingPong()` with no argument bounces forever.
|
|
4980
|
+
*
|
|
4981
|
+
* Mutually exclusive with `loop`; calling either replaces the other, and
|
|
4982
|
+
* calling `then` after either clears the loop (last call wins).
|
|
4983
|
+
* @param {number} [count=Infinity]
|
|
4984
|
+
* @returns {Tween}
|
|
4985
|
+
* @memberof TweenSystem */
|
|
4986
|
+
pingPong(count?: number): Tween;
|
|
4987
|
+
/** Pause this tween. While paused, tweenUpdate skips it.
|
|
4988
|
+
* @memberof TweenSystem */
|
|
4989
|
+
pause(): void;
|
|
4990
|
+
/** Resume a paused tween.
|
|
4991
|
+
* @memberof TweenSystem */
|
|
4992
|
+
resume(): void;
|
|
4993
|
+
/** Reset this tween to the start: life back to duration, pause cleared,
|
|
4994
|
+
* re-added to the active list if previously stopped, and the callback
|
|
4995
|
+
* re-fired with the start value.
|
|
4996
|
+
* @memberof TweenSystem */
|
|
4997
|
+
restart(): void;
|
|
4998
|
+
/** True if this tween is in the active list and not paused.
|
|
4999
|
+
* @returns {boolean}
|
|
5000
|
+
* @memberof TweenSystem */
|
|
5001
|
+
isActive(): boolean;
|
|
5002
|
+
/** Get how far this tween has progressed, from 0 (just started) to 1
|
|
5003
|
+
* (completed). Clamped — overshoot past completion still reads 1.
|
|
5004
|
+
* @returns {number}
|
|
5005
|
+
* @memberof TweenSystem */
|
|
5006
|
+
getPercent(): number;
|
|
5007
|
+
/** Get the current interpolated value (the value most recently passed to
|
|
5008
|
+
* the callback). Returns a number, Vector2, or Color depending on the
|
|
5009
|
+
* tween's start/end types.
|
|
5010
|
+
* @returns {number|Vector2|Color}
|
|
5011
|
+
* @memberof TweenSystem */
|
|
5012
|
+
getValue(): number | Vector2 | Color;
|
|
5013
|
+
/** Compute the interpolated value at the given remaining `life`.
|
|
5014
|
+
* At life === duration the result is `start`; at life === 0 it is `end`.
|
|
5015
|
+
* @param {number} life
|
|
5016
|
+
* @returns {number}
|
|
5017
|
+
* @memberof TweenSystem */
|
|
5018
|
+
interp(life: number): number;
|
|
5019
|
+
/** Remove this tween from the active list and prevent any pending then-callback.
|
|
5020
|
+
* @memberof TweenSystem */
|
|
5021
|
+
stop(): void;
|
|
5022
|
+
}
|
|
5023
|
+
/** Tween a property on an object by dot-path. Returns the underlying Tween
|
|
5024
|
+
* so all chaining methods (`setEase`, `then`, `loop`, `pingPong`, etc.)
|
|
5025
|
+
* remain available.
|
|
5026
|
+
*
|
|
5027
|
+
* `start` and `end` may be numbers, Vector2 instances, Color instances, or
|
|
5028
|
+
* any object with a `lerp(other, percent) => sameType` method.
|
|
5029
|
+
* @param {Object} target - The object whose property is being animated
|
|
5030
|
+
* @param {string} propertyPath - Dot-separated path, e.g. `'pos.x'` or `'color'`
|
|
5031
|
+
* @param {number|Vector2|Color} start - Starting value
|
|
5032
|
+
* @param {number|Vector2|Color} end - Ending value
|
|
5033
|
+
* @param {number} [duration=1] - Duration in seconds
|
|
5034
|
+
* @param {Object} [options] - Same options as the Tween constructor
|
|
5035
|
+
* @returns {Tween}
|
|
5036
|
+
* @memberof TweenSystem
|
|
5037
|
+
* @example
|
|
5038
|
+
* // Numeric: slide an object's x with an ease-out sine curve
|
|
5039
|
+
* tweenProperty(player, 'pos.x', 0, 10, 2).setEase(Ease.OUT(Ease.SINE));
|
|
5040
|
+
* // Vector2: animate a position diagonally
|
|
5041
|
+
* tweenProperty(player, 'pos', vec2(-5, 0), vec2(5, 3), 2);
|
|
5042
|
+
* // Color: pulse between two colors
|
|
5043
|
+
* tweenProperty(sprite, 'color', RED, BLUE, 1).pingPong();
|
|
5044
|
+
*/
|
|
5045
|
+
export function tweenProperty(target: any, propertyPath: string, start: number | Vector2 | Color, end: number | Vector2 | Color, duration?: number, options?: any): Tween;
|
|
5046
|
+
/** Stop every active tween and clear their then-callbacks. Useful for resets
|
|
5047
|
+
* on level transitions or when changing scenes.
|
|
5048
|
+
* @memberof TweenSystem */
|
|
5049
|
+
export function tweenStopAll(): void;
|
|
5050
|
+
/** Engine plugin hook: advance every active tween by the appropriate delta.
|
|
5051
|
+
* Called once per render frame by the engine (no arguments). May also be
|
|
5052
|
+
* called explicitly with `(gameDelta, realDelta)` to drive tweens manually
|
|
5053
|
+
* — useful for headless tests or custom replay/scrubbing systems.
|
|
5054
|
+
* @param {number} [gameDelta] - Game-time delta in seconds; default: time - lastTime
|
|
5055
|
+
* @param {number} [realDelta] - Real-time delta in seconds; default: timeReal - lastTimeReal
|
|
5056
|
+
* @memberof TweenSystem */
|
|
5057
|
+
export function tweenUpdate(gameDelta?: number, realDelta?: number): void;
|
|
5058
|
+
export namespace Ease {
|
|
5059
|
+
function LINEAR(x: number): number;
|
|
5060
|
+
function POWER(n: number): (arg0: number) => number;
|
|
5061
|
+
function SINE(x: number): number;
|
|
5062
|
+
function CIRC(x: number): number;
|
|
5063
|
+
function EXPO(x: number): number;
|
|
5064
|
+
function BACK(x: number): number;
|
|
5065
|
+
function ELASTIC(x: number): number;
|
|
5066
|
+
function SPRING(x: number): number;
|
|
5067
|
+
function BOUNCE(x: number): number;
|
|
5068
|
+
function IN(f: (arg0: number) => number): (arg0: number) => number;
|
|
5069
|
+
function OUT(f: (arg0: number) => number): (arg0: number) => number;
|
|
5070
|
+
function IN_OUT(f: (arg0: number) => number): (arg0: number) => number;
|
|
5071
|
+
function PIECEWISE(...fns: ((arg0: number) => number)[]): (arg0: number) => number;
|
|
5072
|
+
function BEZIER(x1: number, y1: number, x2: number, y2: number): (arg0: number) => number;
|
|
5073
|
+
}
|
|
4876
5074
|
}
|