emeraldengine 2.0.2 → 2.1.0

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.
@@ -50,7 +50,7 @@ class Drawable {
50
50
  this.texture = null;
51
51
  this.useTexture = useTexture;
52
52
  if (useTexture) {
53
- this.initTexture().then(() => {});
53
+ this.initTexture().then(() => { });
54
54
  }
55
55
  this.frameWidth = frameWidth;
56
56
  this.frameHeight = frameHeight;
@@ -73,7 +73,7 @@ class Drawable {
73
73
  this.parentObject = null;
74
74
  this.isActive = false;
75
75
  this.isWireframe = false;
76
- this.callbackFunction = () => {};
76
+ this.callbackFunction = () => { };
77
77
  this.pixelart = pixelart;
78
78
  this.useLighting = useLighting; // Default to true to maintain existing behavior
79
79
  }
@@ -430,13 +430,18 @@ class Drawable {
430
430
  const col = this.currentFrame % this.framesPerRow;
431
431
  const row = Math.floor(this.currentFrame / this.framesPerRow);
432
432
 
433
- texLeft = ((col + 1) * this.frameWidth) / this.textureWidth;
434
- texRight = (col * this.frameWidth) / this.textureWidth;
433
+ const halfTexelWidth = 0.5 / this.textureWidth;
434
+ const halfTexelHeight = 0.5 / this.textureHeight;
435
+
436
+ texLeft = ((col + 1) * this.frameWidth) / this.textureWidth - halfTexelWidth;
437
+ texRight = (col * this.frameWidth) / this.textureWidth + halfTexelWidth;
435
438
  texTop =
436
439
  (this.textureHeight - row * this.frameHeight - this.frameHeight) /
437
- this.textureHeight;
440
+ this.textureHeight +
441
+ halfTexelHeight;
438
442
  texBottom =
439
- (this.textureHeight - row * this.frameHeight) / this.textureHeight;
443
+ (this.textureHeight - row * this.frameHeight) / this.textureHeight -
444
+ halfTexelHeight;
440
445
  } else {
441
446
  // Static image
442
447
  texLeft = 1.0;
@@ -447,25 +452,25 @@ class Drawable {
447
452
  // If mirrored change texLeft and texRight in places
448
453
  const texCoords = this.mirrored
449
454
  ? new Float32Array([
450
- texRight,
451
- texBottom,
452
- texLeft,
453
- texBottom,
454
- texRight,
455
- texTop,
456
- texLeft,
457
- texTop,
458
- ])
455
+ texRight,
456
+ texBottom,
457
+ texLeft,
458
+ texBottom,
459
+ texRight,
460
+ texTop,
461
+ texLeft,
462
+ texTop,
463
+ ])
459
464
  : new Float32Array([
460
- texLeft,
461
- texBottom,
462
- texRight,
463
- texBottom,
464
- texLeft,
465
- texTop,
466
- texRight,
467
- texTop,
468
- ]);
465
+ texLeft,
466
+ texBottom,
467
+ texRight,
468
+ texBottom,
469
+ texLeft,
470
+ texTop,
471
+ texRight,
472
+ texTop,
473
+ ]);
469
474
  // Update texture coordinate buffer
470
475
  this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.texCoordBuffer);
471
476
  this.gl.bufferData(this.gl.ARRAY_BUFFER, texCoords, this.gl.STATIC_DRAW);
@@ -493,9 +498,9 @@ class Drawable {
493
498
  vertexCount = this.vertices.length / 2;
494
499
  }
495
500
 
496
- if(this.isWireframe) {
501
+ if (this.isWireframe) {
497
502
  // Fix the wireframe for square
498
- if(this.vertices.length === 8) {
503
+ if (this.vertices.length === 8) {
499
504
  let tempBuffer = this.gl.createBuffer();
500
505
  this.gl.bindBuffer(this.gl.ARRAY_BUFFER, tempBuffer);
501
506
 
@@ -406,13 +406,18 @@ class InstancedTexture extends Drawable {
406
406
  const col = frame % this.framesPerRow;
407
407
  const row = Math.floor(frame / this.framesPerRow);
408
408
 
409
- texLeft = ((col + 1) * this.frameWidth) / this.textureWidth;
410
- texRight = (col * this.frameWidth) / this.textureWidth;
409
+ const halfTexelWidth = 0.5 / this.textureWidth;
410
+ const halfTexelHeight = 0.5 / this.textureHeight;
411
+
412
+ texLeft = ((col + 1) * this.frameWidth) / this.textureWidth - halfTexelWidth;
413
+ texRight = (col * this.frameWidth) / this.textureWidth + halfTexelWidth;
411
414
  texTop =
412
415
  (this.textureHeight - row * this.frameHeight - this.frameHeight) /
413
- this.textureHeight;
416
+ this.textureHeight +
417
+ halfTexelHeight;
414
418
  texBottom =
415
- (this.textureHeight - row * this.frameHeight) / this.textureHeight;
419
+ (this.textureHeight - row * this.frameHeight) / this.textureHeight -
420
+ halfTexelHeight;
416
421
  } else {
417
422
  // Static image
418
423
  texLeft = 1.0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emeraldengine",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "2D graphics library for Web",
5
5
  "type": "module",
6
6
  "main": "index.js",