littlejsengine 1.8.1 → 1.8.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/README.md +15 -10
- package/build/littlejs.esm.js +140 -127
- package/build/littlejs.js +57 -44
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +57 -44
- package/examples/breakout/gameObjects.js +1 -1
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/README.md +3 -1
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/index.html +2 -2
- package/examples/js13k/index.html +13 -13
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/starter/index.html +13 -13
- package/examples/stress/index.html +3 -3
- package/examples/typescript/game.ts +1 -1
- package/examples/typescript/index.html +1 -1
- package/package.json +2 -1
- package/src/engine.js +2 -2
- package/src/engineAudio.js +2 -1
- package/src/engineDraw.js +35 -18
- package/src/engineExport.js +83 -83
- package/src/engineObject.js +1 -0
- package/src/engineWebGL.js +17 -23
- package/build/littlejs.d.ts +0 -2003
- package/build/littlejs.esm.min.js +0 -1
package/src/engineExport.js
CHANGED
|
@@ -1,10 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* LittleJS Module Export
|
|
3
|
-
* - Export engine as a module
|
|
3
|
+
* - Export engine as a module
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
// Engine
|
|
9
|
+
engineName,
|
|
10
|
+
engineVersion,
|
|
11
|
+
frameRate,
|
|
12
|
+
timeDelta,
|
|
13
|
+
engineObjects,
|
|
14
|
+
frame,
|
|
15
|
+
time,
|
|
16
|
+
timeReal,
|
|
17
|
+
paused,
|
|
18
|
+
setPaused,
|
|
19
|
+
engineInit,
|
|
20
|
+
engineObjectsUpdate,
|
|
21
|
+
engineObjectsDestroy,
|
|
22
|
+
engineObjectsCallback,
|
|
23
|
+
|
|
24
|
+
// Globals
|
|
25
|
+
debug,
|
|
26
|
+
showWatermark,
|
|
27
|
+
|
|
28
|
+
// Debug
|
|
29
|
+
ASSERT,
|
|
30
|
+
debugRect,
|
|
31
|
+
debugCircle,
|
|
32
|
+
debugPoint,
|
|
33
|
+
debugLine,
|
|
34
|
+
debugAABB,
|
|
35
|
+
debugText,
|
|
36
|
+
debugClear,
|
|
37
|
+
debugSaveCanvas,
|
|
38
|
+
|
|
39
|
+
// Settings
|
|
40
|
+
cameraPos,
|
|
41
|
+
cameraScale,
|
|
42
|
+
canvasMaxSize,
|
|
43
|
+
canvasFixedSize,
|
|
44
|
+
canvasPixelated,
|
|
45
|
+
fontDefault,
|
|
46
|
+
tileSizeDefault,
|
|
47
|
+
tileFixBleedScale,
|
|
48
|
+
enablePhysicsSolver,
|
|
49
|
+
objectDefaultMass,
|
|
50
|
+
objectDefaultDamping,
|
|
51
|
+
objectDefaultAngleDamping,
|
|
52
|
+
objectDefaultElasticity,
|
|
53
|
+
objectDefaultFriction,
|
|
54
|
+
objectMaxSpeed,
|
|
55
|
+
gravity,
|
|
56
|
+
particleEmitRateScale,
|
|
57
|
+
glEnable,
|
|
58
|
+
glOverlay,
|
|
59
|
+
gamepadsEnable,
|
|
60
|
+
gamepadDirectionEmulateStick,
|
|
61
|
+
inputWASDEmulateDirection,
|
|
62
|
+
touchGamepadEnable,
|
|
63
|
+
touchGamepadAnalog,
|
|
64
|
+
touchGamepadSize,
|
|
65
|
+
touchGamepadAlpha,
|
|
66
|
+
vibrateEnable,
|
|
67
|
+
soundEnable,
|
|
68
|
+
soundVolume,
|
|
69
|
+
soundDefaultRange,
|
|
70
|
+
soundDefaultTaper,
|
|
71
|
+
medalDisplayTime,
|
|
72
|
+
medalDisplaySlideTime,
|
|
73
|
+
medalDisplaySize,
|
|
74
|
+
medalDisplayIconSize,
|
|
75
|
+
|
|
76
|
+
// Setters for globals
|
|
8
77
|
setCameraPos,
|
|
9
78
|
setCameraScale,
|
|
10
79
|
setCanvasMaxSize,
|
|
@@ -44,58 +113,6 @@ export {
|
|
|
44
113
|
setShowWatermark,
|
|
45
114
|
setDebugKey,
|
|
46
115
|
|
|
47
|
-
// Settings
|
|
48
|
-
canvasMaxSize,
|
|
49
|
-
canvasFixedSize,
|
|
50
|
-
canvasPixelated,
|
|
51
|
-
fontDefault,
|
|
52
|
-
tileSizeDefault,
|
|
53
|
-
tileFixBleedScale,
|
|
54
|
-
enablePhysicsSolver,
|
|
55
|
-
objectDefaultMass,
|
|
56
|
-
objectDefaultDamping,
|
|
57
|
-
objectDefaultAngleDamping,
|
|
58
|
-
objectDefaultElasticity,
|
|
59
|
-
objectDefaultFriction,
|
|
60
|
-
objectMaxSpeed,
|
|
61
|
-
gravity,
|
|
62
|
-
particleEmitRateScale,
|
|
63
|
-
cameraPos,
|
|
64
|
-
cameraScale,
|
|
65
|
-
glEnable,
|
|
66
|
-
glOverlay,
|
|
67
|
-
gamepadsEnable,
|
|
68
|
-
gamepadDirectionEmulateStick,
|
|
69
|
-
inputWASDEmulateDirection,
|
|
70
|
-
touchGamepadEnable,
|
|
71
|
-
touchGamepadAnalog,
|
|
72
|
-
touchGamepadSize,
|
|
73
|
-
touchGamepadAlpha,
|
|
74
|
-
vibrateEnable,
|
|
75
|
-
soundEnable,
|
|
76
|
-
soundVolume,
|
|
77
|
-
soundDefaultRange,
|
|
78
|
-
soundDefaultTaper,
|
|
79
|
-
medalDisplayTime,
|
|
80
|
-
medalDisplaySlideTime,
|
|
81
|
-
medalDisplaySize,
|
|
82
|
-
medalDisplayIconSize,
|
|
83
|
-
|
|
84
|
-
// Globals
|
|
85
|
-
debug,
|
|
86
|
-
showWatermark,
|
|
87
|
-
|
|
88
|
-
// Debug
|
|
89
|
-
ASSERT,
|
|
90
|
-
debugRect,
|
|
91
|
-
debugCircle,
|
|
92
|
-
debugPoint,
|
|
93
|
-
debugLine,
|
|
94
|
-
debugAABB,
|
|
95
|
-
debugText,
|
|
96
|
-
debugClear,
|
|
97
|
-
debugSaveCanvas,
|
|
98
|
-
|
|
99
116
|
// Utilities
|
|
100
117
|
PI,
|
|
101
118
|
abs,
|
|
@@ -133,9 +150,6 @@ export {
|
|
|
133
150
|
rgb,
|
|
134
151
|
hsl,
|
|
135
152
|
|
|
136
|
-
// Base
|
|
137
|
-
EngineObject,
|
|
138
|
-
|
|
139
153
|
// Draw
|
|
140
154
|
textureInfos,
|
|
141
155
|
tile,
|
|
@@ -160,6 +174,15 @@ export {
|
|
|
160
174
|
isFullscreen,
|
|
161
175
|
toggleFullscreen,
|
|
162
176
|
|
|
177
|
+
// WebGL
|
|
178
|
+
glCanvas,
|
|
179
|
+
glContext,
|
|
180
|
+
glSetTexture,
|
|
181
|
+
glCompileShader,
|
|
182
|
+
glCreateProgram,
|
|
183
|
+
glCreateTexture,
|
|
184
|
+
glInitPostProcess,
|
|
185
|
+
|
|
163
186
|
// Input
|
|
164
187
|
keyIsDown,
|
|
165
188
|
keyWasPressed,
|
|
@@ -194,6 +217,9 @@ export {
|
|
|
194
217
|
playSamples,
|
|
195
218
|
zzfx,
|
|
196
219
|
|
|
220
|
+
// Base Object
|
|
221
|
+
EngineObject,
|
|
222
|
+
|
|
197
223
|
// Tiles
|
|
198
224
|
tileCollision,
|
|
199
225
|
tileCollisionSize,
|
|
@@ -216,30 +242,4 @@ export {
|
|
|
216
242
|
newgroundsInit,
|
|
217
243
|
Medal,
|
|
218
244
|
Newgrounds,
|
|
219
|
-
|
|
220
|
-
// WebGL
|
|
221
|
-
glCanvas,
|
|
222
|
-
glContext,
|
|
223
|
-
glSetBlendMode,
|
|
224
|
-
glSetTexture,
|
|
225
|
-
glCompileShader,
|
|
226
|
-
glCreateProgram,
|
|
227
|
-
glCreateTexture,
|
|
228
|
-
glInitPostProcess,
|
|
229
|
-
|
|
230
|
-
// Engine
|
|
231
|
-
engineName,
|
|
232
|
-
engineVersion,
|
|
233
|
-
frameRate,
|
|
234
|
-
timeDelta,
|
|
235
|
-
engineObjects,
|
|
236
|
-
frame,
|
|
237
|
-
time,
|
|
238
|
-
timeReal,
|
|
239
|
-
paused,
|
|
240
|
-
setPaused,
|
|
241
|
-
engineInit,
|
|
242
|
-
engineObjectsUpdate,
|
|
243
|
-
engineObjectsDestroy,
|
|
244
|
-
engineObjectsCallback,
|
|
245
245
|
};
|
package/src/engineObject.js
CHANGED
|
@@ -44,6 +44,7 @@ class EngineObject
|
|
|
44
44
|
// set passed in params
|
|
45
45
|
ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
|
|
46
46
|
ASSERT(typeof tileInfo !== 'number' || !tileInfo); // prevent old style calls
|
|
47
|
+
ASSERT(!(renderOrder instanceof Color)); // prevent old style calls
|
|
47
48
|
// to fix old calls, replace with tile(tileIndex, tileSize)
|
|
48
49
|
|
|
49
50
|
/** @property {Vector2} - World space position of the object */
|
package/src/engineWebGL.js
CHANGED
|
@@ -42,21 +42,20 @@ function glInit()
|
|
|
42
42
|
'#version 300 es\n' + // specify GLSL ES version
|
|
43
43
|
'precision highp float;'+ // use highp for better accuracy
|
|
44
44
|
'uniform mat4 m;'+ // transform matrix
|
|
45
|
-
'in
|
|
46
|
-
'in vec4 c,a;'+ // color, additiveColor
|
|
45
|
+
'in vec4 p,c,a;'+ // position, uv, color, additiveColor
|
|
47
46
|
'out vec4 v,d,e;'+ // return uv, color, additiveColor
|
|
48
47
|
'void main(){'+ // shader entry point
|
|
49
|
-
'gl_Position=m*vec4(p,1,1);'+ // transform position
|
|
50
|
-
'v=
|
|
48
|
+
'gl_Position=m*vec4(p.xy,1,1);'+ // transform position
|
|
49
|
+
'v=p;d=c;e=a;'+ // pass stuff to fragment shader
|
|
51
50
|
'}' // end of shader
|
|
52
51
|
,
|
|
53
52
|
'#version 300 es\n' + // specify GLSL ES version
|
|
54
53
|
'precision highp float;'+ // use highp for better accuracy
|
|
55
|
-
'in vec4 v,d,e;'+ // uv, color, additiveColor
|
|
54
|
+
'in vec4 v,d,e;'+ // position, uv, color, additiveColor
|
|
56
55
|
'uniform sampler2D s;'+ // texture
|
|
57
56
|
'out vec4 c;'+ // out color
|
|
58
57
|
'void main(){'+ // shader entry point
|
|
59
|
-
'c=texture(s,v.
|
|
58
|
+
'c=texture(s,v.zw)*d+e;'+ // modulate texture by color plus additive
|
|
60
59
|
'}' // end of shader
|
|
61
60
|
);
|
|
62
61
|
|
|
@@ -81,7 +80,7 @@ function glPreRender()
|
|
|
81
80
|
glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = textureInfos[0].glTexture);
|
|
82
81
|
glContext.bindBuffer(gl_ARRAY_BUFFER, glArrayBuffer);
|
|
83
82
|
glContext.bufferData(gl_ARRAY_BUFFER, gl_VERTEX_BUFFER_SIZE, gl_DYNAMIC_DRAW);
|
|
84
|
-
|
|
83
|
+
glAdditive = 0;
|
|
85
84
|
|
|
86
85
|
// set vertex attributes
|
|
87
86
|
let offset = 0;
|
|
@@ -92,33 +91,25 @@ function glPreRender()
|
|
|
92
91
|
glContext.vertexAttribPointer(location, size, type, normalize, gl_VERTEX_BYTE_STRIDE, offset);
|
|
93
92
|
offset += size*typeSize;
|
|
94
93
|
}
|
|
95
|
-
initVertexAttribArray('p', gl_FLOAT, 4,
|
|
96
|
-
initVertexAttribArray('t', gl_FLOAT, 4, 2); // texture coords
|
|
94
|
+
initVertexAttribArray('p', gl_FLOAT, 4, 4); // position & texture coords
|
|
97
95
|
initVertexAttribArray('c', gl_UNSIGNED_BYTE, 1, 4, 1); // color
|
|
98
96
|
initVertexAttribArray('a', gl_UNSIGNED_BYTE, 1, 4, 1); // additiveColor
|
|
99
97
|
|
|
100
98
|
// build the transform matrix
|
|
101
99
|
const sx = 2 * cameraScale / mainCanvas.width;
|
|
102
100
|
const sy = 2 * cameraScale / mainCanvas.height;
|
|
101
|
+
const cx = -1 - sx*cameraPos.x;
|
|
102
|
+
const cy = -1 - sy*cameraPos.y;
|
|
103
103
|
glContext.uniformMatrix4fv(glContext.getUniformLocation(glShader, 'm'), 0,
|
|
104
104
|
new Float32Array([
|
|
105
|
-
sx,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
sx, 0, 0, 0,
|
|
106
|
+
0, sy, 0, 0,
|
|
107
|
+
1, 1, -1, 1,
|
|
108
|
+
cx, cy, 0, 0
|
|
109
109
|
])
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
/** Set the WebGl blend mode, normally you should call setBlendMode instead
|
|
114
|
-
* @param {Boolean} [additive=0]
|
|
115
|
-
* @memberof WebGL */
|
|
116
|
-
function glSetBlendMode(additive=0)
|
|
117
|
-
{
|
|
118
|
-
// setup blending
|
|
119
|
-
glAdditive = additive;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
113
|
/** Set the WebGl texture, called automatically if using multiple textures
|
|
123
114
|
* - This may also flush the gl buffer resulting in more draw calls and worse performance
|
|
124
115
|
* @param {WebGLTexture} texture
|
|
@@ -354,8 +345,11 @@ function glRenderPostProcess()
|
|
|
354
345
|
glFlush(); // clear out the buffer
|
|
355
346
|
mainContext.drawImage(glCanvas, 0, 0); // copy to the main canvas
|
|
356
347
|
}
|
|
357
|
-
else
|
|
348
|
+
else
|
|
349
|
+
{
|
|
350
|
+
// set the viewport
|
|
358
351
|
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
352
|
+
}
|
|
359
353
|
|
|
360
354
|
if (glPostIncludeOverlay)
|
|
361
355
|
{
|