littlejsengine 1.9.2 → 1.9.3

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/src/engineDraw.js CHANGED
@@ -85,13 +85,9 @@ function tile(pos=vec2(), size=tileSizeDefault, textureIndex=0)
85
85
  if (typeof pos === 'number')
86
86
  {
87
87
  const textureInfo = textureInfos[textureIndex];
88
- if (textureInfo)
89
- {
90
- const cols = textureInfo.size.x / size.x |0;
91
- pos = vec2((pos%cols)*size.x, (pos/cols|0)*size.y);
92
- }
93
- else
94
- pos = vec2();
88
+ ASSERT(textureInfo, 'Texture not loaded');
89
+ const cols = textureInfo.size.x / size.x |0;
90
+ pos = vec2((pos%cols)*size.x, (pos/cols|0)*size.y);
95
91
  }
96
92
 
97
93
  // return a tile info object
@@ -180,6 +176,11 @@ function worldToScreen(worldPos)
180
176
  );
181
177
  }
182
178
 
179
+ /** Get the camera's visible area in world space
180
+ * @return {Vector2}
181
+ * @memberof Draw */
182
+ function getCameraSize() { return mainCanvasSize.scale(1/cameraScale); }
183
+
183
184
  /** Draw textured tile centered in world space, with color applied if using WebGL
184
185
  * @param {Vector2} pos - Center of the tile in world space
185
186
  * @param {Vector2} [size=(1,1)] - Size of the tile in world space
@@ -357,7 +357,7 @@ function createTouchGamepad()
357
357
  touchGamepadStick = vec2();
358
358
 
359
359
  const touchHandler = ontouchstart;
360
- ontouchstart = ontouchmove = ontouchend = (e)=>
360
+ ontouchstart = ontouchmove = ontouchend = (e)=>
361
361
  {
362
362
  // clear touch gamepad input
363
363
  touchGamepadStick = vec2();
@@ -270,7 +270,7 @@ class Newgrounds
270
270
  }
271
271
 
272
272
  // build the input object
273
- const input =
273
+ const input =
274
274
  {
275
275
  'app_id': this.app_id,
276
276
  'session_id': this.session_id,
@@ -10,7 +10,7 @@
10
10
  * - Automatically adds self to object list
11
11
  * - Will be updated and rendered each frame
12
12
  * - Renders as a sprite from a tilesheet by default
13
- * - Can have color and addtive color applied
13
+ * - Can have color and additive color applied
14
14
  * - 2D Physics and collision system
15
15
  * - Sorted by renderOrder
16
16
  * - Objects can have children attached
@@ -289,7 +289,7 @@ class EngineObject
289
289
  }
290
290
 
291
291
  /** Destroy this object, destroy it's children, detach it's parent, and mark it for removal */
292
- destroy()
292
+ destroy()
293
293
  {
294
294
  if (this.destroyed)
295
295
  return;
@@ -202,16 +202,17 @@ class ParticleEmitter extends EngineObject
202
202
 
203
203
  // build particle
204
204
  const particle = new Particle(pos, this.tileInfo, angle, colorStart, colorEnd, particleTime, sizeStart, sizeEnd, this.fadeRate, this.additive, this.trailScale, this.localSpace && this, this.particleDestroyCallback);
205
- particle.velocity = vec2().setAngle(velocityAngle, speed);
206
- particle.fadeRate = this.fadeRate;
207
- particle.damping = this.damping;
208
- particle.angleDamping = this.angleDamping;
209
- particle.elasticity = this.elasticity;
210
- particle.friction = this.friction;
211
- particle.gravityScale = this.gravityScale;
212
- particle.collideTiles = this.collideTiles;
213
- particle.renderOrder = this.renderOrder;
214
- particle.mirror = !!randInt(2);
205
+ particle.velocity = vec2().setAngle(velocityAngle, speed);
206
+ particle.angleVelocity = angleSpeed;
207
+ particle.fadeRate = this.fadeRate;
208
+ particle.damping = this.damping;
209
+ particle.angleDamping = this.angleDamping;
210
+ particle.elasticity = this.elasticity;
211
+ particle.friction = this.friction;
212
+ particle.gravityScale = this.gravityScale;
213
+ particle.collideTiles = this.collideTiles;
214
+ particle.renderOrder = this.renderOrder;
215
+ particle.mirror = !!randInt(2);
215
216
 
216
217
  // call particle create callaback
217
218
  this.particleCreateCallback && this.particleCreateCallback(particle);
@@ -83,7 +83,7 @@ let tileSizeDefault = vec2(16);
83
83
  * @type {Number}
84
84
  * @default
85
85
  * @memberof Settings */
86
- let tileFixBleedScale = .3;
86
+ let tileFixBleedScale = .1;
87
87
 
88
88
  ///////////////////////////////////////////////////////////////////////////////
89
89
  // Object settings
@@ -94,7 +94,7 @@ let tileFixBleedScale = .3;
94
94
  * @memberof Settings */
95
95
  let enablePhysicsSolver = true;
96
96
 
97
- /** Default object mass for collison calcuations (how heavy objects are)
97
+ /** Default object mass for collision calcuations (how heavy objects are)
98
98
  * @type {Number}
99
99
  * @default
100
100
  * @memberof Settings */
@@ -177,7 +177,7 @@ let touchGamepadEnable = false;
177
177
  * @memberof Settings */
178
178
  let touchGamepadAnalog = true;
179
179
 
180
- /** Size of virutal gamepad for touch devices in pixels
180
+ /** Size of virtual gamepad for touch devices in pixels
181
181
  * @type {Number}
182
182
  * @default
183
183
  * @memberof Settings */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * LittleJS Tile Layer System
3
3
  * - Caches arrays of tiles to off screen canvas for fast rendering
4
- * - Unlimted numbers of layers, allocates canvases as needed
4
+ * - Unlimited numbers of layers, allocates canvases as needed
5
5
  * - Interfaces with EngineObject for collision
6
6
  * - Collision layer is separate from visible layers
7
7
  * - It is recommended to have a visible layer that matches the collision
@@ -53,7 +53,7 @@ function getTileCollisionData(pos)
53
53
 
54
54
  /** Check if collision with another object should occur
55
55
  * @param {Vector2} pos
56
- * @param {Vector2} [size=(1,1)]
56
+ * @param {Vector2} [size=(0,0)]
57
57
  * @param {EngineObject} [object]
58
58
  * @return {Boolean}
59
59
  * @memberof TileCollision */
@@ -36,7 +36,7 @@ function min(valueA, valueB) { return Math.min(valueA, valueB); }
36
36
  * @memberof Utilities */
37
37
  function max(valueA, valueB) { return Math.max(valueA, valueB); }
38
38
 
39
- /** Returns the sign of value passed in (also returns 1 if 0)
39
+ /** Returns the sign of value passed in
40
40
  * @param {Number} value
41
41
  * @return {Number}
42
42
  * @memberof Utilities */
@@ -83,7 +83,7 @@ function lerp(percent, valueA, valueB) { return valueA + clamp(percent) * (value
83
83
  function distanceWrap(valueA, valueB, wrapSize=1)
84
84
  { const d = (valueA - valueB) % wrapSize; return d*2 % wrapSize - d; }
85
85
 
86
- /** Linearly interpolates between values passed in with wrappping
86
+ /** Linearly interpolates between values passed in with wrapping
87
87
  * @param {Number} percent
88
88
  * @param {Number} valueA
89
89
  * @param {Number} valueB
@@ -100,7 +100,7 @@ function lerpWrap(percent, valueA, valueB, wrapSize=1)
100
100
  * @memberof Utilities */
101
101
  function distanceAngle(angleA, angleB) { return distanceWrap(angleA, angleB, 2*PI); }
102
102
 
103
- /** Linearly interpolates between the angles passed in with wrappping
103
+ /** Linearly interpolates between the angles passed in with wrapping
104
104
  * @param {Number} percent
105
105
  * @param {Number} angleA
106
106
  * @param {Number} angleB
@@ -193,8 +193,6 @@ function glCreateTexture(image)
193
193
  const filter = canvasPixelated ? gl_NEAREST : gl_LINEAR;
194
194
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, filter);
195
195
  glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, filter);
196
- glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_S, gl_CLAMP_TO_EDGE);
197
- glContext.texParameteri(gl_TEXTURE_2D, gl_TEXTURE_WRAP_T, gl_CLAMP_TO_EDGE);
198
196
 
199
197
  return texture;
200
198
  }
@@ -272,7 +270,7 @@ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdd
272
270
  ///////////////////////////////////////////////////////////////////////////////
273
271
  // post processing - can be enabled to pass other canvases through a final shader
274
272
 
275
- let glPostShader, glPostArrayBuffer, glPostTexture, glPostIncludeOverlay;
273
+ let glPostShader, glPostTexture, glPostIncludeOverlay;
276
274
 
277
275
  /** Set up a post processing shader
278
276
  * @param {String} shaderCode
@@ -308,7 +306,6 @@ function glInitPostProcess(shaderCode, includeOverlay=false)
308
306
  );
309
307
 
310
308
  // create buffer and texture
311
- glPostArrayBuffer = glContext.createBuffer();
312
309
  glPostTexture = glCreateTexture(undefined);
313
310
  glPostIncludeOverlay = includeOverlay;
314
311
 
@@ -380,10 +377,7 @@ gl_NEAREST = 9728,
380
377
  gl_LINEAR = 9729,
381
378
  gl_TEXTURE_MAG_FILTER = 10240,
382
379
  gl_TEXTURE_MIN_FILTER = 10241,
383
- gl_TEXTURE_WRAP_S = 10242,
384
- gl_TEXTURE_WRAP_T = 10243,
385
380
  gl_COLOR_BUFFER_BIT = 16384,
386
- gl_CLAMP_TO_EDGE = 33071,
387
381
  gl_TEXTURE0 = 33984,
388
382
  gl_ARRAY_BUFFER = 34962,
389
383
  gl_STATIC_DRAW = 35044,