浏览代码

Introduce Viewport.aspectRatio

customisations
alemart 9 个月前
父节点
当前提交
2410d303f7
共有 2 个文件被更改,包括 18 次插入4 次删除
  1. 8
    0
      docs/api/viewport.md
  2. 10
    4
      src/core/viewport.ts

+ 8
- 0
docs/api/viewport.md 查看文件

53
 
53
 
54
 The [resolution](resolution.md) of the virtual scene.
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
 ### virtualSize
64
 ### virtualSize
57
 
65
 
58
 `viewport.virtualSize: SpeedySize, read-only`
66
 `viewport.virtualSize: SpeedySize, read-only`

+ 10
- 4
src/core/viewport.ts 查看文件

733
     {
733
     {
734
         const subContainer = viewport._subContainer;
734
         const subContainer = viewport._subContainer;
735
         const windowAspectRatio = window.innerWidth / window.innerHeight;
735
         const windowAspectRatio = window.innerWidth / window.innerHeight;
736
-        const viewportAspectRatio = viewport._realSize.width / viewport._realSize.height;
736
+        const viewportAspectRatio = viewport.aspectRatio;
737
         let width = 1, height = 1, left = '0px', top = '0px';
737
         let width = 1, height = 1, left = '0px', top = '0px';
738
 
738
 
739
         if(viewportAspectRatio <= windowAspectRatio) {
739
         if(viewportAspectRatio <= windowAspectRatio) {
904
      */
904
      */
905
     get virtualSize(): SpeedySize
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
     /**

正在加载...
取消
保存