@unboxy/phaser-sdk 0.2.27 → 0.2.28

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.
@@ -259,27 +259,26 @@ function computeScreenRect(game, go) {
259
259
  const canvasY = (worldRect.y - cam.scrollY) * cam.zoom;
260
260
  const canvasW = worldRect.width * cam.zoom;
261
261
  const canvasH = worldRect.height * cam.zoom;
262
- // Phaser FIT scale factor the actual rendered canvas is scaled by this
263
- // ratio inside the iframe, with letterbox/pillarbox margins centered.
264
- const scaleManager = game.scale;
265
- const renderScale = scaleManager.displayScale.x; // x and y are equal under FIT
266
- // Canvas's offset inside the iframe (CSS pixels).
262
+ // Convert logical canvas pixels CSS pixels using the canvas's actual
263
+ // displayed size (avoids depending on which direction Phaser's displayScale
264
+ // goes we just measure it). Canvas may be letterboxed/pillarboxed inside
265
+ // the iframe under Scale.FIT; getBoundingClientRect gives both the size
266
+ // and the offset.
267
267
  const canvas = game.canvas;
268
- let offsetX = 0;
269
- let offsetY = 0;
270
- // Walk the offset chain — iframe canvas is usually centered under
271
- // CENTER_BOTH, so its parent has padding. getBoundingClientRect on the
272
- // canvas vs the iframe document root tells us the offset.
273
- if (canvas && typeof canvas.getBoundingClientRect === 'function') {
274
- const r = canvas.getBoundingClientRect();
275
- offsetX = r.left;
276
- offsetY = r.top;
277
- }
268
+ if (!canvas || typeof canvas.getBoundingClientRect !== 'function')
269
+ return null;
270
+ const cssRect = canvas.getBoundingClientRect();
271
+ const logicalW = game.scale.width;
272
+ const logicalH = game.scale.height;
273
+ if (!logicalW || !logicalH)
274
+ return null;
275
+ const sx = cssRect.width / logicalW;
276
+ const sy = cssRect.height / logicalH;
278
277
  return {
279
- x: offsetX + canvasX * renderScale,
280
- y: offsetY + canvasY * renderScale,
281
- width: canvasW * renderScale,
282
- height: canvasH * renderScale,
278
+ x: cssRect.left + canvasX * sx,
279
+ y: cssRect.top + canvasY * sy,
280
+ width: canvasW * sx,
281
+ height: canvasH * sy,
283
282
  };
284
283
  }
285
284
  function readActiveManifest(game) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboxy/phaser-sdk",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "description": "Unboxy Phaser 3 SDK — game infrastructure for the Unboxy platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",