littlejsengine 1.9.3 → 1.9.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/dist/littlejs.d.ts +8 -3
- package/dist/littlejs.esm.js +49 -36
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +49 -36
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +45 -36
- package/examples/module/game.js +1 -1
- package/examples/platformer/gameCharacter.js +1 -2
- package/examples/platformer/gameLevel.js +0 -1
- package/examples/typescript/game.js +1 -1
- package/examples/typescript/game.ts +1 -1
- package/package.json +1 -1
- package/src/engine.js +2 -2
- package/src/engineAudio.js +1 -1
- package/src/engineDebug.js +4 -0
- package/src/engineDraw.js +11 -16
- package/src/engineInput.js +30 -16
- package/src/engineUtilities.js +1 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
'use strict';
|
|
7
7
|
// import module
|
|
8
8
|
import * as LittleJS from '../../dist/littlejs.esm.js';
|
|
9
|
-
const {
|
|
9
|
+
const { tile, vec2, hsl } = LittleJS;
|
|
10
10
|
// show the LittleJS splash screen
|
|
11
11
|
LittleJS.setShowSplashScreen(true);
|
|
12
12
|
// sound effects
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
// import module
|
|
10
10
|
import * as LittleJS from '../../dist/littlejs.esm.js';
|
|
11
|
-
const {
|
|
11
|
+
const {tile, vec2, hsl} = LittleJS;
|
|
12
12
|
|
|
13
13
|
// show the LittleJS splash screen
|
|
14
14
|
LittleJS.setShowSplashScreen(true);
|
package/package.json
CHANGED
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.9.
|
|
33
|
+
const engineVersion = '1.9.4';
|
|
34
34
|
|
|
35
35
|
/** Frames per second to update
|
|
36
36
|
* @type {Number}
|
|
@@ -112,7 +112,7 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
112
112
|
timeReal += frameTimeDeltaMS / 1e3;
|
|
113
113
|
frameTimeBufferMS += paused ? 0 : frameTimeDeltaMS;
|
|
114
114
|
if (!debugSpeedUp)
|
|
115
|
-
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp
|
|
115
|
+
frameTimeBufferMS = min(frameTimeBufferMS, 50); // clamp in case of slow framerate
|
|
116
116
|
updateCanvas();
|
|
117
117
|
|
|
118
118
|
if (paused)
|
package/src/engineAudio.js
CHANGED
package/src/engineDebug.js
CHANGED
|
@@ -260,6 +260,10 @@ function debugRender()
|
|
|
260
260
|
{
|
|
261
261
|
const saveContext = mainContext;
|
|
262
262
|
mainContext = overlayContext;
|
|
263
|
+
|
|
264
|
+
// draw red rectangle around screen
|
|
265
|
+
const cameraSize = getCameraSize();
|
|
266
|
+
debugRect(cameraPos, cameraSize.subtract(vec2(.1)), '#f008');
|
|
263
267
|
|
|
264
268
|
// mouse pick
|
|
265
269
|
let bestDistance = Infinity, bestObject;
|
package/src/engineDraw.js
CHANGED
|
@@ -114,13 +114,23 @@ class TileInfo
|
|
|
114
114
|
this.textureIndex = textureIndex;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/** Returns
|
|
117
|
+
/** Returns a copy of this tile offset by a vector
|
|
118
118
|
* @param {Vector2} offset - Offset to apply in pixels
|
|
119
119
|
* @return {TileInfo}
|
|
120
120
|
*/
|
|
121
121
|
offset(offset)
|
|
122
122
|
{ return new TileInfo(this.pos.add(offset), this.size, this.textureIndex); }
|
|
123
123
|
|
|
124
|
+
/** Returns a copy of this tile offset by a number of animation frames
|
|
125
|
+
* @param {Number} frame - Offset to apply in animation frames
|
|
126
|
+
* @return {TileInfo}
|
|
127
|
+
*/
|
|
128
|
+
frame(frame)
|
|
129
|
+
{
|
|
130
|
+
ASSERT(typeof frame == 'number');
|
|
131
|
+
return this.offset(vec2(frame*this.size.x, 0));
|
|
132
|
+
}
|
|
133
|
+
|
|
124
134
|
/** Returns the texture info for this tile
|
|
125
135
|
* @return {TextureInfo}
|
|
126
136
|
*/
|
|
@@ -271,21 +281,6 @@ function drawRect(pos, size, color, angle, useWebGL, screenSpace, context)
|
|
|
271
281
|
drawTile(pos, size, undefined, color, angle, false, undefined, useWebGL, screenSpace, context);
|
|
272
282
|
}
|
|
273
283
|
|
|
274
|
-
/** Draw colored polygon using passed in points
|
|
275
|
-
* @param {Array} points - Array of Vector2 points
|
|
276
|
-
* @param {Color} [color=(1,1,1,1)]
|
|
277
|
-
* @param {Boolean} [screenSpace=false]
|
|
278
|
-
* @param {CanvasRenderingContext2D} [context=mainContext]
|
|
279
|
-
* @memberof Draw */
|
|
280
|
-
function drawPoly(points, color=new Color, screenSpace, context=mainContext)
|
|
281
|
-
{
|
|
282
|
-
context.fillStyle = color.toString();
|
|
283
|
-
context.beginPath();
|
|
284
|
-
for (const point of screenSpace ? points : points.map(worldToScreen))
|
|
285
|
-
context.lineTo(point.x, point.y);
|
|
286
|
-
context.fill();
|
|
287
|
-
}
|
|
288
|
-
|
|
289
284
|
/** Draw colored line between two points
|
|
290
285
|
* @param {Vector2} posA
|
|
291
286
|
* @param {Vector2} posB
|
package/src/engineInput.js
CHANGED
|
@@ -211,9 +211,21 @@ function mouseToScreen(mousePos)
|
|
|
211
211
|
///////////////////////////////////////////////////////////////////////////////
|
|
212
212
|
// Gamepad input
|
|
213
213
|
|
|
214
|
+
// gamepad internal variables
|
|
214
215
|
const stickData = [];
|
|
216
|
+
|
|
217
|
+
// gamepads are updated by engine every frame automatically
|
|
215
218
|
function gamepadsUpdate()
|
|
216
219
|
{
|
|
220
|
+
const applyDeadZones = (v)=>
|
|
221
|
+
{
|
|
222
|
+
const min=.3, max=.8;
|
|
223
|
+
const deadZone = (v)=>
|
|
224
|
+
v > min ? percent( v, min, max) :
|
|
225
|
+
v < -min ? -percent(-v, min, max) : 0;
|
|
226
|
+
return vec2(deadZone(v.x), deadZone(-v.y)).clampLength();
|
|
227
|
+
}
|
|
228
|
+
|
|
217
229
|
// update touch gamepad if enabled
|
|
218
230
|
if (touchGamepadEnable && isTouchDevice)
|
|
219
231
|
{
|
|
@@ -225,7 +237,16 @@ function gamepadsUpdate()
|
|
|
225
237
|
{
|
|
226
238
|
// read virtual analog stick
|
|
227
239
|
const sticks = stickData[0] || (stickData[0] = []);
|
|
228
|
-
sticks[0] = vec2(
|
|
240
|
+
sticks[0] = vec2();
|
|
241
|
+
if (touchGamepadAnalog)
|
|
242
|
+
sticks[0] = applyDeadZones(touchGamepadStick);
|
|
243
|
+
else if (touchGamepadStick.lengthSquared() > .3)
|
|
244
|
+
{
|
|
245
|
+
// convert to 8 way dpad
|
|
246
|
+
sticks[0].x = Math.round(touchGamepadStick.x);
|
|
247
|
+
sticks[0].y = -Math.round(touchGamepadStick.y);
|
|
248
|
+
sticks[0] = sticks[0].clampLength();
|
|
249
|
+
}
|
|
229
250
|
|
|
230
251
|
// read virtual gamepad buttons
|
|
231
252
|
const data = inputData[1] || (inputData[1] = []);
|
|
@@ -237,7 +258,12 @@ function gamepadsUpdate()
|
|
|
237
258
|
}
|
|
238
259
|
}
|
|
239
260
|
|
|
240
|
-
|
|
261
|
+
// return if gamepads are disabled or not supported
|
|
262
|
+
if (!gamepadsEnable || !navigator || !navigator.getGamepads)
|
|
263
|
+
return;
|
|
264
|
+
|
|
265
|
+
// only poll gamepads when focused or in debug mode
|
|
266
|
+
if (!debug && !document.hasFocus())
|
|
241
267
|
return;
|
|
242
268
|
|
|
243
269
|
// poll gamepads
|
|
@@ -251,14 +277,9 @@ function gamepadsUpdate()
|
|
|
251
277
|
|
|
252
278
|
if (gamepad)
|
|
253
279
|
{
|
|
254
|
-
// read clamp dead zone of analog sticks
|
|
255
|
-
const deadZone = .3, deadZoneMax = .8, applyDeadZone = (v)=>
|
|
256
|
-
v > deadZone ? percent( v, deadZone, deadZoneMax) :
|
|
257
|
-
v < -deadZone ? -percent(-v, deadZone, deadZoneMax) : 0;
|
|
258
|
-
|
|
259
280
|
// read analog sticks
|
|
260
281
|
for (let j = 0; j < gamepad.axes.length-1; j+=2)
|
|
261
|
-
sticks[j>>1] = vec2(
|
|
282
|
+
sticks[j>>1] = applyDeadZones(vec2(gamepad.axes[j],gamepad.axes[j+1]));
|
|
262
283
|
|
|
263
284
|
// read buttons
|
|
264
285
|
for (let j = gamepad.buttons.length; j--;)
|
|
@@ -387,14 +408,7 @@ function createTouchGamepad()
|
|
|
387
408
|
if (touchPos.distance(stickCenter) < touchGamepadSize)
|
|
388
409
|
{
|
|
389
410
|
// virtual analog stick
|
|
390
|
-
|
|
391
|
-
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
|
|
392
|
-
else
|
|
393
|
-
{
|
|
394
|
-
// 8 way dpad
|
|
395
|
-
const angle = touchPos.subtract(stickCenter).angle();
|
|
396
|
-
touchGamepadStick.setAngle((angle * 4 / PI + 8.5 | 0) * PI / 4);
|
|
397
|
-
}
|
|
411
|
+
touchGamepadStick = touchPos.subtract(stickCenter).scale(2/touchGamepadSize).clampLength();
|
|
398
412
|
}
|
|
399
413
|
else if (touchPos.distance(buttonCenter) < touchGamepadSize)
|
|
400
414
|
{
|