@penabt/pixi-expo 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -292,7 +292,7 @@ module.exports = config;
292
292
 
293
293
  ## Design Resolution
294
294
 
295
- Cocos2d-style fixed coordinate system for your game. Define a virtual resolution and the library automatically scales the stage to fit any device screen.
295
+ fFixed coordinate system for your game. Define a virtual resolution and the library renders at native device quality no GPU texture stretching.
296
296
 
297
297
  ```tsx
298
298
  <PixiView
@@ -319,11 +319,11 @@ Cocos2d-style fixed coordinate system for your game. Define a virtual resolution
319
319
 
320
320
  ### How It Works
321
321
 
322
- The renderer runs at the device's real screen size for full quality. The stage is transformed (scaled + positioned) so your game logic always works in the design coordinate space.
322
+ The renderer operates directly in design coordinates and uses PixiJS's `resolution` property to bridge to physical pixels. Textures render at native device resolution with no GPU upscaling artifacts.
323
323
 
324
- - **NO_BORDER**: `scale = max(screenW/designW, screenH/designH)` — uniform scale, no gaps, edges cropped
325
- - **SHOW_ALL**: `scale = min(screenW/designW, screenH/designH)` — uniform scale, no crop, bars on short axis
326
- - **EXACT_FIT**: `scaleX = screenW/designW, scaleY = screenH/designH` non-uniform, fills exactly
324
+ - **NO_BORDER**: `resolution = max(physicalW/designW, physicalH/designH)` — viewport smaller than design, edges cropped
325
+ - **SHOW_ALL**: `resolution = min(physicalW/designW, physicalH/designH)` — viewport larger than design, letterbox bars
326
+ - **EXACT_FIT**: `resolution = max(resX, resY)` with per-axis stage scale compensation for the non-uniform axis
327
327
 
328
328
  ### Design Tips
329
329
 
@@ -337,8 +337,8 @@ The renderer runs at the device's real screen size for full quality. The stage i
337
337
  ```tsx
338
338
  import { calculateDesignScale } from '@penabt/pixi-expo';
339
339
 
340
- const scale = calculateDesignScale(720, 1280, screenWidth, screenHeight, 'NO_BORDER');
341
- // scale.scaleX, scale.scaleY, scale.offsetX, scale.offsetY
340
+ const scale = calculateDesignScale(720, 1280, physicalWidth, physicalHeight, 'NO_BORDER');
341
+ // scale.resolution, scale.viewportWidth, scale.viewportHeight, scale.offsetX, scale.offsetY
342
342
  ```
343
343
 
344
344
  ## Safe Area
@@ -397,10 +397,11 @@ export default function App() {
397
397
 
398
398
  ### How It Works
399
399
 
400
- `getSafeArea()` converts physical screen insets to your design coordinate space using the current stage transform:
400
+ `getSafeArea()` converts physical screen insets to your design coordinate space through the resolution pipeline:
401
401
 
402
402
  ```
403
- designInset = (physicalInset - stageOffset) / stageScale
403
+ viewport_coord = physicalInset × pixelRatio / resolution
404
+ design_coord = (viewport_coord - stageOffset) / stageScale
404
405
  ```
405
406
 
406
407
  - **NO_BORDER**: Insets are larger because the cropped edges are accounted for
@@ -413,9 +414,10 @@ Use `calculateDesignSafeArea()` outside of `PixiView` for custom setups:
413
414
 
414
415
  ```tsx
415
416
  import { calculateDesignScale, calculateDesignSafeArea } from '@penabt/pixi-expo';
417
+ import { PixelRatio } from 'react-native';
416
418
 
417
- const scale = calculateDesignScale(720, 1280, screenW, screenH, 'NO_BORDER');
418
- const safe = calculateDesignSafeArea(physicalInsets, scale, 720, 1280, screenW, screenH);
419
+ const scale = calculateDesignScale(720, 1280, physicalW, physicalH, 'NO_BORDER');
420
+ const safe = calculateDesignSafeArea(insets, scale, 720, 1280, PixelRatio.get());
419
421
  // safe.top, safe.bottom, safe.left, safe.right — all in 720x1280 space
420
422
  ```
421
423
 
@@ -425,7 +427,7 @@ const safe = calculateDesignSafeArea(physicalInsets, scale, 720, 1280, screenW,
425
427
  | --- | --- | --- |
426
428
  | `safeAreaInsets` | `SafeAreaInsets` | Physical insets `{ top, bottom, left, right }` in screen points |
427
429
  | `getSafeArea()` | `() => DesignSafeArea \| null` | Returns insets in design coordinates (ref handle method) |
428
- | `calculateDesignSafeArea()` | `(insets, scale, dw, dh, sw, sh) => DesignSafeArea` | Standalone conversion utility |
430
+ | `calculateDesignSafeArea()` | `(insets, scale, dw, dh, pixelRatio) => DesignSafeArea` | Standalone conversion utility |
429
431
 
430
432
  ## Performance Tips
431
433
 
package/dist/index.d.mts CHANGED
@@ -543,13 +543,6 @@ declare const loadExpoFont: LoaderParser<string>;
543
543
  * ```
544
544
  */
545
545
  declare function registerBitmapFont(xmlModuleId: number, pageModuleIds: number[]): string;
546
- /**
547
- * Expo Bitmap Font Loader
548
- *
549
- * A PixiJS LoadParser that handles local bitmap fonts registered via
550
- * registerBitmapFont(). Runs at High priority to intercept before
551
- * PixiJS's built-in loadBitmapFont (which can't handle module IDs).
552
- */
553
546
  declare const loadExpoBitmapFont: LoaderParser;
554
547
 
555
548
  /**
@@ -625,11 +618,15 @@ declare function createExpoBundle(assets: ExpoAssetsBundle['assets']): AssetsBun
625
618
  declare function createExpoManifest(manifest: ExpoAssetsManifest): AssetsManifest;
626
619
 
627
620
  /**
628
- * Design resolution scaling utilities.
621
+ * Design resolution utilities (Cocos2d-style).
622
+ *
623
+ * Instead of scaling the PixiJS stage, we set the renderer to operate in
624
+ * design coordinates and use PixiJS's `resolution` property to bridge
625
+ * the gap to physical pixels. This means:
629
626
  *
630
- * Provides Cocos2d-style design resolution support: define a fixed logical
631
- * size (e.g. 768×1024) and the library automatically scales the PixiJS stage
632
- * to fit the device screen.
627
+ * - Textures render at native device resolution (no GPU upscaling)
628
+ * - Game code works in a fixed coordinate space (e.g. 720×1280)
629
+ * - The stage has no scale transform — only a position offset for centering
633
630
  */
634
631
  /** How the design resolution maps to the physical screen. */
635
632
  type DesignScaleMode =
@@ -657,25 +654,41 @@ interface DesignSafeArea {
657
654
  /** Inset from the right edge of the design coordinate space */
658
655
  right: number;
659
656
  }
660
- /** Result of the design-to-screen scale calculation. */
657
+ /**
658
+ * Result of the design-to-screen scale calculation.
659
+ *
660
+ * The renderer is initialised at `viewportWidth × viewportHeight` with the
661
+ * returned `resolution`. Physical backing = viewport × resolution = screen.
662
+ * The stage receives only a position offset (and stageScale for EXACT_FIT).
663
+ */
661
664
  interface DesignScaleResult {
662
- /** Scale factor applied to stage X axis */
663
- scaleX: number;
664
- /** Scale factor applied to stage Y axis */
665
- scaleY: number;
666
- /** X offset for centering the stage (positive = letterbox, negative = crop) */
665
+ /** PixiJS resolution: physical pixels per logical (design) unit */
666
+ resolution: number;
667
+ /** Logical viewport width for the PixiJS renderer */
668
+ viewportWidth: number;
669
+ /** Logical viewport height for the PixiJS renderer */
670
+ viewportHeight: number;
671
+ /** Stage X position to centre the design area inside the viewport */
667
672
  offsetX: number;
668
- /** Y offset for centering the stage */
673
+ /** Stage Y position to centre the design area inside the viewport */
669
674
  offsetY: number;
675
+ /** Stage scale X — 1.0 for SHOW_ALL / NO_BORDER, may differ for EXACT_FIT */
676
+ stageScaleX: number;
677
+ /** Stage scale Y — 1.0 for SHOW_ALL / NO_BORDER, may differ for EXACT_FIT */
678
+ stageScaleY: number;
670
679
  }
671
680
  /**
672
- * Calculate how to transform the PixiJS stage so that a fixed design
673
- * resolution maps onto the actual screen dimensions.
681
+ * Calculate how to set up the PixiJS renderer so that game code can work in
682
+ * a fixed design coordinate space while rendering at native device resolution.
674
683
  *
675
- * The renderer stays at the real screen size for full-quality rendering;
676
- * the returned values are applied to `app.stage.scale` and `app.stage.position`.
684
+ * @param designWidth - Fixed design width (e.g. 720)
685
+ * @param designHeight - Fixed design height (e.g. 1280)
686
+ * @param physicalWidth - Physical screen width in pixels
687
+ * @param physicalHeight - Physical screen height in pixels
688
+ * @param scaleMode - How to handle aspect-ratio mismatch
689
+ * @returns Values to feed into PixiJS app.init() and stage transform
677
690
  */
678
- declare function calculateDesignScale(designWidth: number, designHeight: number, screenWidth: number, screenHeight: number, scaleMode: DesignScaleMode): DesignScaleResult;
691
+ declare function calculateDesignScale(designWidth: number, designHeight: number, physicalWidth: number, physicalHeight: number, scaleMode: DesignScaleMode): DesignScaleResult;
679
692
  /**
680
693
  * Convert physical safe area insets (screen points) to design resolution coordinates.
681
694
  *
@@ -687,15 +700,14 @@ declare function calculateDesignScale(designWidth: number, designHeight: number,
687
700
  * In SHOW_ALL mode with letterboxing, insets may be zero if the bars
688
701
  * already cover the unsafe region.
689
702
  *
690
- * @param insets - Physical safe area insets in screen points
703
+ * @param insets - Physical safe area insets in logical screen points
691
704
  * @param scale - The current design scale result from calculateDesignScale()
692
705
  * @param designWidth - The design resolution width
693
706
  * @param designHeight - The design resolution height
694
- * @param screenWidth - The physical screen width in points
695
- * @param screenHeight - The physical screen height in points
707
+ * @param pixelRatio - Device pixel ratio (PixelRatio.get())
696
708
  * @returns Safe area insets in design resolution coordinates
697
709
  */
698
- declare function calculateDesignSafeArea(insets: SafeAreaInsets, scale: DesignScaleResult, designWidth: number, designHeight: number, screenWidth: number, screenHeight: number): DesignSafeArea;
710
+ declare function calculateDesignSafeArea(insets: SafeAreaInsets, scale: DesignScaleResult, designWidth: number, designHeight: number, pixelRatio: number): DesignSafeArea;
699
711
 
700
712
  /**
701
713
  * Props for the PixiView component.
package/dist/index.d.ts CHANGED
@@ -543,13 +543,6 @@ declare const loadExpoFont: LoaderParser<string>;
543
543
  * ```
544
544
  */
545
545
  declare function registerBitmapFont(xmlModuleId: number, pageModuleIds: number[]): string;
546
- /**
547
- * Expo Bitmap Font Loader
548
- *
549
- * A PixiJS LoadParser that handles local bitmap fonts registered via
550
- * registerBitmapFont(). Runs at High priority to intercept before
551
- * PixiJS's built-in loadBitmapFont (which can't handle module IDs).
552
- */
553
546
  declare const loadExpoBitmapFont: LoaderParser;
554
547
 
555
548
  /**
@@ -625,11 +618,15 @@ declare function createExpoBundle(assets: ExpoAssetsBundle['assets']): AssetsBun
625
618
  declare function createExpoManifest(manifest: ExpoAssetsManifest): AssetsManifest;
626
619
 
627
620
  /**
628
- * Design resolution scaling utilities.
621
+ * Design resolution utilities (Cocos2d-style).
622
+ *
623
+ * Instead of scaling the PixiJS stage, we set the renderer to operate in
624
+ * design coordinates and use PixiJS's `resolution` property to bridge
625
+ * the gap to physical pixels. This means:
629
626
  *
630
- * Provides Cocos2d-style design resolution support: define a fixed logical
631
- * size (e.g. 768×1024) and the library automatically scales the PixiJS stage
632
- * to fit the device screen.
627
+ * - Textures render at native device resolution (no GPU upscaling)
628
+ * - Game code works in a fixed coordinate space (e.g. 720×1280)
629
+ * - The stage has no scale transform — only a position offset for centering
633
630
  */
634
631
  /** How the design resolution maps to the physical screen. */
635
632
  type DesignScaleMode =
@@ -657,25 +654,41 @@ interface DesignSafeArea {
657
654
  /** Inset from the right edge of the design coordinate space */
658
655
  right: number;
659
656
  }
660
- /** Result of the design-to-screen scale calculation. */
657
+ /**
658
+ * Result of the design-to-screen scale calculation.
659
+ *
660
+ * The renderer is initialised at `viewportWidth × viewportHeight` with the
661
+ * returned `resolution`. Physical backing = viewport × resolution = screen.
662
+ * The stage receives only a position offset (and stageScale for EXACT_FIT).
663
+ */
661
664
  interface DesignScaleResult {
662
- /** Scale factor applied to stage X axis */
663
- scaleX: number;
664
- /** Scale factor applied to stage Y axis */
665
- scaleY: number;
666
- /** X offset for centering the stage (positive = letterbox, negative = crop) */
665
+ /** PixiJS resolution: physical pixels per logical (design) unit */
666
+ resolution: number;
667
+ /** Logical viewport width for the PixiJS renderer */
668
+ viewportWidth: number;
669
+ /** Logical viewport height for the PixiJS renderer */
670
+ viewportHeight: number;
671
+ /** Stage X position to centre the design area inside the viewport */
667
672
  offsetX: number;
668
- /** Y offset for centering the stage */
673
+ /** Stage Y position to centre the design area inside the viewport */
669
674
  offsetY: number;
675
+ /** Stage scale X — 1.0 for SHOW_ALL / NO_BORDER, may differ for EXACT_FIT */
676
+ stageScaleX: number;
677
+ /** Stage scale Y — 1.0 for SHOW_ALL / NO_BORDER, may differ for EXACT_FIT */
678
+ stageScaleY: number;
670
679
  }
671
680
  /**
672
- * Calculate how to transform the PixiJS stage so that a fixed design
673
- * resolution maps onto the actual screen dimensions.
681
+ * Calculate how to set up the PixiJS renderer so that game code can work in
682
+ * a fixed design coordinate space while rendering at native device resolution.
674
683
  *
675
- * The renderer stays at the real screen size for full-quality rendering;
676
- * the returned values are applied to `app.stage.scale` and `app.stage.position`.
684
+ * @param designWidth - Fixed design width (e.g. 720)
685
+ * @param designHeight - Fixed design height (e.g. 1280)
686
+ * @param physicalWidth - Physical screen width in pixels
687
+ * @param physicalHeight - Physical screen height in pixels
688
+ * @param scaleMode - How to handle aspect-ratio mismatch
689
+ * @returns Values to feed into PixiJS app.init() and stage transform
677
690
  */
678
- declare function calculateDesignScale(designWidth: number, designHeight: number, screenWidth: number, screenHeight: number, scaleMode: DesignScaleMode): DesignScaleResult;
691
+ declare function calculateDesignScale(designWidth: number, designHeight: number, physicalWidth: number, physicalHeight: number, scaleMode: DesignScaleMode): DesignScaleResult;
679
692
  /**
680
693
  * Convert physical safe area insets (screen points) to design resolution coordinates.
681
694
  *
@@ -687,15 +700,14 @@ declare function calculateDesignScale(designWidth: number, designHeight: number,
687
700
  * In SHOW_ALL mode with letterboxing, insets may be zero if the bars
688
701
  * already cover the unsafe region.
689
702
  *
690
- * @param insets - Physical safe area insets in screen points
703
+ * @param insets - Physical safe area insets in logical screen points
691
704
  * @param scale - The current design scale result from calculateDesignScale()
692
705
  * @param designWidth - The design resolution width
693
706
  * @param designHeight - The design resolution height
694
- * @param screenWidth - The physical screen width in points
695
- * @param screenHeight - The physical screen height in points
707
+ * @param pixelRatio - Device pixel ratio (PixelRatio.get())
696
708
  * @returns Safe area insets in design resolution coordinates
697
709
  */
698
- declare function calculateDesignSafeArea(insets: SafeAreaInsets, scale: DesignScaleResult, designWidth: number, designHeight: number, screenWidth: number, screenHeight: number): DesignSafeArea;
710
+ declare function calculateDesignSafeArea(insets: SafeAreaInsets, scale: DesignScaleResult, designWidth: number, designHeight: number, pixelRatio: number): DesignSafeArea;
699
711
 
700
712
  /**
701
713
  * Props for the PixiView component.