Kaynağa Gözat

Introduce Viewport.aspectRatio

customisations
alemart 9 ay önce
ebeveyn
işleme
2410d303f7
2 değiştirilmiş dosya ile 18 ekleme ve 4 silme
  1. 8
    0
      docs/api/viewport.md
  2. 10
    4
      src/core/viewport.ts

+ 8
- 0
docs/api/viewport.md Dosyayı Görüntüle

@@ -53,6 +53,14 @@ The [HUD](hud.md).
53 53
 
54 54
 The [resolution](resolution.md) of the virtual scene.
55 55
 
56
+### aspectRatio
57
+
58
+`viewport.aspectRatio: number, read-only`
59
+
60
+The aspect ratio of the viewport.
61
+
62
+*Since:* 0.4.0
63
+
56 64
 ### virtualSize
57 65
 
58 66
 `viewport.virtualSize: SpeedySize, read-only`

+ 10
- 4
src/core/viewport.ts Dosyayı Görüntüle

@@ -733,7 +733,7 @@ class BestFitResizeStrategy extends ImmersiveResizeStrategy
733 733
     {
734 734
         const subContainer = viewport._subContainer;
735 735
         const windowAspectRatio = window.innerWidth / window.innerHeight;
736
-        const viewportAspectRatio = viewport._realSize.width / viewport._realSize.height;
736
+        const viewportAspectRatio = viewport.aspectRatio;
737 737
         let width = 1, height = 1, left = '0px', top = '0px';
738 738
 
739 739
         if(viewportAspectRatio <= windowAspectRatio) {
@@ -904,10 +904,16 @@ export class Viewport extends ViewportEventTarget
904 904
      */
905 905
     get virtualSize(): SpeedySize
906 906
     {
907
-        const size = this._realSize;
908
-        const aspectRatio = size.width / size.height;
907
+        return Utils.resolution(this._resolution, this.aspectRatio);
908
+    }
909 909
 
910
-        return Utils.resolution(this._resolution, aspectRatio);
910
+    /**
911
+     * Aspect ratio of the viewport
912
+     */
913
+    get aspectRatio(): number
914
+    {
915
+        const size = this._realSize;
916
+        return size.width / size.height;
911 917
     }
912 918
 
913 919
     /**

Loading…
İptal
Kaydet