Screen

屏幕对象包含了当前所选设备的屏幕尺寸信息。当你切换设备时,它的尺寸信息也会跟着变化。你也可以改变屏幕的背景色和透视景深值。

The Screen object contains the size of the current device screen. The size changes when switching to a different device. You can also change the background color and the perspective of the device screen.

Screen.backgroundColor <string>

设置屏幕的背景色。

Sets the background color of the device screen.

  1. # Change the device screen background color
  2. Screen.backgroundColor = "#28affa"

Screen.width <number>

读取屏幕的宽度。(只读)

The width of the current device screen in pixels. (Read-only)

  1. print Screen.width
  2. # Output: 640

Screen.height <number>

读取屏幕的高度。(只读)

The height of the current device screen in pixels. (Read-only)

  1. print Screen.height
  2. # Output: 1080

Screen.size ≶object>

读取屏幕的宽度和高度信息。(只读)

The width and height of the current device screen in pixels. (Read-only)

  1. print Screen.size
  2. # Output: { width:640, height: 1080 }

Screen.frame ≶object>

读取屏幕的坐标和尺寸信息。(只读)

The x, y, width and height of the current device screen in pixels. (Read-only)

  1. print Screen.frame
  2. # Output: { x:0, y:0, width:640, height: 1080 }

Screen.perspective <number>

屏幕的透视景深值,默认设置为 1200 。

The perspective of the current device screen. Set to 1200 by default.

  1. # Rotate layer in 3D
  2. layerA = new Layer
  3. rotationX: 30
  4. # Adjust perspective
  5. Screen.perspective = 1000

Screen.perspectiveOriginX <number>

设置 3D 转换的 x 轴中心。他的只是一个数字,0 表示该中心处于屏幕左边缘,1 表示该中心处于屏幕右边缘。默认值是 0.5 ,即屏幕的水平中心。

Sets the x origin for 3D transformations. The origin is defined as a number, where 0 is the left edge of the screen and 1 the right edge. The default value is 0.5, the center of the screen.

  1. # Rotate layer in 3D
  2. layerA = new Layer
  3. rotationX: 30
  4. # Set horizontal perspective origin
  5. Screen.perspectiveOriginX = 1

Screen.perspectiveOriginY <number>

设置 3D 转换的 y 轴中心。他的只是一个数字,0 表示该中心处于屏幕上边缘,1 表示该中心处于屏幕下边缘。默认值是 0.5 ,即屏幕的垂直中心。

Sets the y origin for 3D transformations. The origin is defined as a number, where 0 is the top edge of the screen and 1 the bottom edge. The default value is 0.5, the center of the screen.

  1. # Rotate layer in 3D
  2. layerA = new Layer
  3. rotationX: 30
  4. # Set vertical perspective origin
  5. Screen.perspectiveOriginY = 1

Screen.convertPointToCanvas(point)

将屏幕上的一个点坐标转换成相对于画布的点坐标。

Converts a point from the Screen to the Canvas.

  1. point =
  2. x: 20
  3. y: 40
  4. pointInCanvas = Screen.convertPointToCanvas(point)

Screen.convertPointToLayer(point, layer)

将屏幕上的一个点坐标转换成相对于某个图层的点坐标。

Converts a point from the Screen to a layer.

  1. point =
  2. x: 20
  3. y: 40
  4. layer = new Layer
  5. pointInLayer = Screen.convertPointToLayer(point, layer)