Skip to content

Commit db5605d

Browse files
committed
auto-respect scale of instance passed to be a parallax instance
1 parent c78e770 commit db5605d

8 files changed

Lines changed: 20827 additions & 16462 deletions

File tree

docs/ast/source/parallax.mjs.json

Lines changed: 20764 additions & 16407 deletions
Large diffs are not rendered by default.

docs/class/src/parallax.mjs~ParallaxSingleton.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,7 @@ <h3 data-ice="anchor" id="instance-method-remove">
20382038
<span class="right-info">
20392039

20402040

2041-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber361">source</a></span></span>
2041+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber364">source</a></span></span>
20422042
</span>
20432043
</h3>
20442044

@@ -2482,7 +2482,7 @@ <h3 data-ice="anchor" id="instance-method-update">
24822482
<span class="right-info">
24832483

24842484

2485-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber377">source</a></span></span>
2485+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber380">source</a></span></span>
24862486
</span>
24872487
</h3>
24882488

@@ -2552,7 +2552,7 @@ <h3 data-ice="anchor" id="instance-method-add">
25522552
<span class="right-info">
25532553

25542554

2555-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber290">source</a></span></span>
2555+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber292">source</a></span></span>
25562556
</span>
25572557
</h3>
25582558

@@ -2702,7 +2702,7 @@ <h3 data-ice="anchor" id="instance-method-handleOnRelocated">
27022702
<span class="right-info">
27032703

27042704

2705-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber492">source</a></span></span>
2705+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber496">source</a></span></span>
27062706
</span>
27072707
</h3>
27082708

@@ -2763,7 +2763,7 @@ <h3 data-ice="anchor" id="instance-method-init">
27632763
<span class="right-info">
27642764

27652765

2766-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber326">source</a></span></span>
2766+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber328">source</a></span></span>
27672767
</span>
27682768
</h3>
27692769

@@ -2892,7 +2892,7 @@ <h3 data-ice="anchor" id="instance-method-toggleInfinitePlanes">
28922892
<span class="right-info">
28932893

28942894

2895-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber264">source</a></span></span>
2895+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber266">source</a></span></span>
28962896
</span>
28972897
</h3>
28982898

@@ -2953,7 +2953,7 @@ <h3 data-ice="anchor" id="instance-method-toggleInfiniteVertical">
29532953
<span class="right-info">
29542954

29552955

2956-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber233">source</a></span></span>
2956+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber234">source</a></span></span>
29572957
</span>
29582958
</h3>
29592959

@@ -3014,7 +3014,7 @@ <h3 data-ice="anchor" id="instance-method-updateInstance">
30143014
<span class="right-info">
30153015

30163016

3017-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber393">source</a></span></span>
3017+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber396">source</a></span></span>
30183018
</span>
30193019
</h3>
30203020

docs/file/src/parallax.mjs.html

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,15 @@
240240
*/
241241
toggleInfiniteHorizontal(pInstance) {
242242
const [left, right] = this.createLoopInstances(pInstance);
243+
const { x: scaleX } = pInstance.scale;
243244

244245
// Position the left clone
245-
left.x = pInstance.x - pInstance.icon.width;
246+
left.x = pInstance.x - pInstance.icon.width * scaleX;
246247
left.y = pInstance.y;
247248
left.mapName = pInstance.mapName;
248249

249250
// Position the right clone
250-
right.x = pInstance.x + pInstance.icon.width;
251+
right.x = pInstance.x + pInstance.icon.width * scaleX;
251252
right.y = pInstance.y;
252253
right.mapName = pInstance.mapName;
253254

@@ -272,15 +273,16 @@
272273
*/
273274
toggleInfiniteVertical(pInstance) {
274275
const [top, bottom] = this.createLoopInstances(pInstance);
276+
const { y: scaleY } = pInstance.scale;
275277

276278
// Position the left clone
277279
top.x = pInstance.x;
278-
top.y = pInstance.y - pInstance.icon.height;
280+
top.y = pInstance.y - pInstance.icon.height * scaleY;
279281
top.mapName = pInstance.mapName;
280282

281283
// Position the right clone
282284
bottom.x = pInstance.x;
283-
bottom.y = pInstance.y + pInstance.icon.height;
285+
bottom.y = pInstance.y + pInstance.icon.height * scaleY;
284286
bottom.mapName = pInstance.mapName;
285287

286288
// Store the clones in a temporary array
@@ -378,7 +380,8 @@
378380
const { ground, groundY, groundMapname, infiniteHorizontal, infiniteVertical } = pConfig;
379381

380382
if (ground) {
381-
pInstance.x = x - pInstance.icon.width / 2;
383+
const { x: scaleX } = pInstance.scale;
384+
pInstance.x = x - pInstance.icon.width * scaleX / 2;
382385
pInstance.y = groundY;
383386
pInstance.mapName = groundMapname;
384387
} else {
@@ -439,6 +442,7 @@
439442

440443
let lastCamPosX = this.lastCamPos.x;
441444
let lastCamPosY = this.lastCamPos.y;
445+
const { x: scaleX, y: scaleY } = pInstance.scale;
442446

443447
if (!ground) {
444448
if (pAnchor) {
@@ -458,15 +462,15 @@
458462
let x;
459463
let y;
460464
if (isBackgroundX) {
461-
x = pCameraX - pInstance.icon.width / 2;
465+
x = pCameraX - pInstance.icon.width * scaleX / 2;
462466
} else {
463467
let deltaX = pCameraX - lastCamPosX;
464468
let distX = deltaX * horizontalSpeed;
465469
x = pInstance.x + distX;
466470
}
467471

468472
if (isBackgroundY) {
469-
y = pCameraY - pInstance.icon.height / 2;
473+
y = pCameraY - pInstance.icon.height * scaleY / 2;
470474
} else {
471475
let deltaY = pCameraY - lastCamPosY;
472476
let distY = deltaY * verticalSpeed;
@@ -483,29 +487,29 @@
483487
if (infiniteHorizontal) {
484488
if (lastCamPosX !== pCameraX) {
485489
// The start pos + total width
486-
const rightEnd = pInstance.x + pInstance.icon.width;
490+
const rightEnd = pInstance.x + pInstance.icon.width * scaleX;
487491
// The start pos - total width / 6
488-
const leftEnd = Math.floor(pInstance.x - pInstance.icon.width / 6);
492+
const leftEnd = Math.floor(pInstance.x - pInstance.icon.width * scaleX / 6);
489493

490494
if (pCameraX &gt; rightEnd) {
491-
pInstance.x += pInstance.icon.width;
495+
pInstance.x += pInstance.icon.width * scaleX;
492496
} else if (pCameraX &lt; leftEnd) {
493-
pInstance.x -= pInstance.icon.width;
497+
pInstance.x -= pInstance.icon.width * scaleX;
494498
}
495499
}
496500
}
497501

498502
if (infiniteVertical) {
499503
if (lastCamPosY !== pCameraY) {
500504
// The start pos + total height
501-
const bottomEnd = pInstance.y + pInstance.icon.height;
505+
const bottomEnd = pInstance.y + pInstance.icon.height * scaleY;
502506
// The start pos - total height / 6
503-
const topEnd = Math.floor(pInstance.y - pInstance.icon.height / 6);
507+
const topEnd = Math.floor(pInstance.y - pInstance.icon.height * scaleY / 6);
504508

505509
if (pCameraY &gt; bottomEnd) {
506-
pInstance.y += pInstance.icon.height;
510+
pInstance.y += pInstance.icon.height * scaleY;
507511
} else if (pCameraY &lt; topEnd) {
508-
pInstance.y -= pInstance.icon.height;
512+
pInstance.y -= pInstance.icon.height * scaleY;
509513
}
510514
}
511515
}

docs/index.json

Lines changed: 11 additions & 11 deletions
Large diffs are not rendered by default.

docs/source.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
<td data-ice="identifier" class="identifiers"><span><a href="variable/index.html#static-variable-Parallax">Parallax</a></span>
7474
<span><a href="class/src/parallax.mjs~ParallaxSingleton.html">ParallaxSingleton</a></span></td>
7575
<td class="coverage"><span data-ice="coverage">-</span></td>
76-
<td style="display: none;" data-ice="size">18566 byte</td>
77-
<td style="display: none;" data-ice="lines">512</td>
78-
<td style="display: none;" data-ice="updated">2025-03-05 06:59:22 (UTC)</td>
76+
<td style="display: none;" data-ice="size">18904 byte</td>
77+
<td style="display: none;" data-ice="lines">516</td>
78+
<td style="display: none;" data-ice="updated">2025-07-07 21:35:23 (UTC)</td>
7979
</tr>
8080
</tbody>
8181
</table>

docs/variable/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ <h3 data-ice="anchor" id="static-variable-Parallax">
8787
<span class="right-info">
8888

8989

90-
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber512">source</a></span></span>
90+
<span data-ice="source"><span><a href="file/src/parallax.mjs.html#lineNumber516">source</a></span></span>
9191
</span>
9292
</h3>
9393

94-
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import {Parallax} from &apos;<span><a href="file/src/parallax.mjs.html#lineNumber512">parallax</a></span>&apos;</code></pre></div>
94+
<div data-ice="importPath" class="import-path"><pre class="prettyprint"><code data-ice="importPathCode">import {Parallax} from &apos;<span><a href="file/src/parallax.mjs.html#lineNumber516">parallax</a></span>&apos;</code></pre></div>
9595

9696

9797

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parallax",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "A parallax module that will enable effortless integration of depth effects into your game.",
55
"main": "src/parallax.mjs",
66
"scripts": {

src/parallax.mjs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,15 @@ class ParallaxSingleton {
200200
*/
201201
toggleInfiniteHorizontal(pInstance) {
202202
const [left, right] = this.createLoopInstances(pInstance);
203+
const { x: scaleX } = pInstance.scale;
203204

204205
// Position the left clone
205-
left.x = pInstance.x - pInstance.icon.width;
206+
left.x = pInstance.x - pInstance.icon.width * scaleX;
206207
left.y = pInstance.y;
207208
left.mapName = pInstance.mapName;
208209

209210
// Position the right clone
210-
right.x = pInstance.x + pInstance.icon.width;
211+
right.x = pInstance.x + pInstance.icon.width * scaleX;
211212
right.y = pInstance.y;
212213
right.mapName = pInstance.mapName;
213214

@@ -232,15 +233,16 @@ class ParallaxSingleton {
232233
*/
233234
toggleInfiniteVertical(pInstance) {
234235
const [top, bottom] = this.createLoopInstances(pInstance);
236+
const { y: scaleY } = pInstance.scale;
235237

236238
// Position the left clone
237239
top.x = pInstance.x;
238-
top.y = pInstance.y - pInstance.icon.height;
240+
top.y = pInstance.y - pInstance.icon.height * scaleY;
239241
top.mapName = pInstance.mapName;
240242

241243
// Position the right clone
242244
bottom.x = pInstance.x;
243-
bottom.y = pInstance.y + pInstance.icon.height;
245+
bottom.y = pInstance.y + pInstance.icon.height * scaleY;
244246
bottom.mapName = pInstance.mapName;
245247

246248
// Store the clones in a temporary array
@@ -338,7 +340,8 @@ class ParallaxSingleton {
338340
const { ground, groundY, groundMapname, infiniteHorizontal, infiniteVertical } = pConfig;
339341

340342
if (ground) {
341-
pInstance.x = x - pInstance.icon.width / 2;
343+
const { x: scaleX } = pInstance.scale;
344+
pInstance.x = x - pInstance.icon.width * scaleX / 2;
342345
pInstance.y = groundY;
343346
pInstance.mapName = groundMapname;
344347
} else {
@@ -399,6 +402,7 @@ class ParallaxSingleton {
399402

400403
let lastCamPosX = this.lastCamPos.x;
401404
let lastCamPosY = this.lastCamPos.y;
405+
const { x: scaleX, y: scaleY } = pInstance.scale;
402406

403407
if (!ground) {
404408
if (pAnchor) {
@@ -418,15 +422,15 @@ class ParallaxSingleton {
418422
let x;
419423
let y;
420424
if (isBackgroundX) {
421-
x = pCameraX - pInstance.icon.width / 2;
425+
x = pCameraX - pInstance.icon.width * scaleX / 2;
422426
} else {
423427
let deltaX = pCameraX - lastCamPosX;
424428
let distX = deltaX * horizontalSpeed;
425429
x = pInstance.x + distX;
426430
}
427431

428432
if (isBackgroundY) {
429-
y = pCameraY - pInstance.icon.height / 2;
433+
y = pCameraY - pInstance.icon.height * scaleY / 2;
430434
} else {
431435
let deltaY = pCameraY - lastCamPosY;
432436
let distY = deltaY * verticalSpeed;
@@ -443,29 +447,29 @@ class ParallaxSingleton {
443447
if (infiniteHorizontal) {
444448
if (lastCamPosX !== pCameraX) {
445449
// The start pos + total width
446-
const rightEnd = pInstance.x + pInstance.icon.width;
450+
const rightEnd = pInstance.x + pInstance.icon.width * scaleX;
447451
// The start pos - total width / 6
448-
const leftEnd = Math.floor(pInstance.x - pInstance.icon.width / 6);
452+
const leftEnd = Math.floor(pInstance.x - pInstance.icon.width * scaleX / 6);
449453

450454
if (pCameraX > rightEnd) {
451-
pInstance.x += pInstance.icon.width;
455+
pInstance.x += pInstance.icon.width * scaleX;
452456
} else if (pCameraX < leftEnd) {
453-
pInstance.x -= pInstance.icon.width;
457+
pInstance.x -= pInstance.icon.width * scaleX;
454458
}
455459
}
456460
}
457461

458462
if (infiniteVertical) {
459463
if (lastCamPosY !== pCameraY) {
460464
// The start pos + total height
461-
const bottomEnd = pInstance.y + pInstance.icon.height;
465+
const bottomEnd = pInstance.y + pInstance.icon.height * scaleY;
462466
// The start pos - total height / 6
463-
const topEnd = Math.floor(pInstance.y - pInstance.icon.height / 6);
467+
const topEnd = Math.floor(pInstance.y - pInstance.icon.height * scaleY / 6);
464468

465469
if (pCameraY > bottomEnd) {
466-
pInstance.y += pInstance.icon.height;
470+
pInstance.y += pInstance.icon.height * scaleY;
467471
} else if (pCameraY < topEnd) {
468-
pInstance.y -= pInstance.icon.height;
472+
pInstance.y -= pInstance.icon.height * scaleY;
469473
}
470474
}
471475
}

0 commit comments

Comments
 (0)