View 类型
模块: _decorator 父模块: cc
cc.view is the singleton object which represents the game window.
It's main task include:
- Apply the design resolution policy
- Provide interaction with the window, like resize event on web, retina display support, etc...
- Manage the game view port which can be different with the window
- Manage the content scale and translation
Since the cc.view is a singleton, you don't need to call any constructor or create functions,
the standard way to use it is by calling: - cc.view.methodName();
索引
方法
setTargetDensityDPI设置目标内容的每英寸像素点密度。getTargetDensityDPI获取目标内容的每英寸像素点密度。resizeWithBrowserSize设置当发现浏览器的尺寸改变时,是否自动调整 canvas 尺寸大小。setResizeCallback仅在 Web 平台下有效。setOrientation设置游戏屏幕朝向,它能够是横版,竖版或自动。adjustViewportMeta设置引擎是否调整 viewport meta 来配合屏幕适配。enableRetina它仅会在你调用 setDesignResolutionPolicy 方法时有影响。isRetinaEnabled检查是否对 Retina 显示设备进行优化。enableAntiAlias控制抗锯齿是否开启isAntiAliasEnabled返回当前是否抗锯齿enableAutoFullScreen启动时,移动端游戏会在移动端自动尝试进入全屏模式。isAutoFullScreenEnabled检查自动进入全屏模式是否启动。getCanvasSize返回视图中 canvas 的尺寸。getFrameSize返回视图中边框尺寸。setFrameSize在 native 平台下,设置视图框架尺寸。getVisibleSize返回视图窗口可见区域尺寸。getVisibleSizeInPixel返回视图窗口可见区域像素尺寸。getVisibleOrigin返回视图窗口可见区域原点。getVisibleOriginInPixel返回视图窗口可见区域像素原点。getResolutionPolicy返回当前分辨率方案setResolutionPolicy设置当前分辨率模式setDesignResolutionSize通过设置设计分辨率和匹配模式来进行游戏画面的屏幕适配。getDesignResolutionSize返回视图的设计分辨率。setRealPixelResolution设置容器(container)需要的像素分辨率并且适配相应分辨率的游戏内容。setViewportInPoints用设计分辨率下的点尺寸来设置视窗。setScissorInPoints用设计分辨率下的点的尺寸来设置 scissor 剪裁区域。isScissorEnabled检查 scissor 是否生效。getScissorRect返回当前的 scissor 剪裁区域。getViewportRect返回视窗剪裁区域。getScaleX返回横轴的缩放比,这个缩放比是将画布像素分辨率放到设计分辨率的比例。getScaleY返回纵轴的缩放比,这个缩放比是将画布像素分辨率缩放到设计分辨率的比例。getDevicePixelRatio返回设备或浏览器像素比例。convertToLocationInView将屏幕坐标转换为游戏视图下的坐标。
事件
design-resolution-changed当设计分辨率改变时发送。canvas-resize当画布大小改变时发送。
Details
方法
setTargetDensityDPI
设置目标内容的每英寸像素点密度。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:249 |
| 废弃(Deprecated) | since v2.0 |
参数列表
densityDPIString
getTargetDensityDPI
获取目标内容的每英寸像素点密度。
| meta | description |
|---|---|
| 返回 | String |
| 定义于 | cocos2d/core/platform/CCView.js:264 |
| 废弃(Deprecated) | since v2.0 |
resizeWithBrowserSize
设置当发现浏览器的尺寸改变时,是否自动调整 canvas 尺寸大小。 仅在 Web 模式下有效。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:273 |
参数列表
enabledBoolean Whether enable automatic resize with browser's resize event
setResizeCallback
设置 cc.view 调整视窗尺寸行为的回调函数, 这个回调函数会在应用适配模式之前被调用, 因此你可以在这个回调函数内添加任意附加改变, 仅在 Web 平台下有效。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:300 |
参数列表
callbackFunction | Null The callback function
setOrientation
设置游戏屏幕朝向,它能够是横版,竖版或自动。 当设置为横版或竖版,并且屏幕的宽高比例不匹配时, cc.view 会自动用 CSS 旋转游戏场景的 canvas, 这个方法不会对 native 部分产生任何影响,对于 native 而言,你需要在应用设置中的设置排版。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:320 |
参数列表
orientationNumber Possible values: cc.macro.ORIENTATION_LANDSCAPE | cc.macro.ORIENTATION_PORTRAIT | cc.macro.ORIENTATION_AUTO
adjustViewportMeta
设置引擎是否调整 viewport meta 来配合屏幕适配。 默认设置为启动,我们强烈建议你不要将它设置为关闭。 即使当它启动时,你仍然能够设置你的 viewport meta,它不会被覆盖。 仅在 Web 模式下有效
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:426 |
参数列表
enabledBoolean Enable automatic modification to "viewport" meta
enableRetina
对于 Apple 这种支持 Retina 显示的设备上默认进行优化而其他类型设备默认不进行优化, 它仅会在你调用 setDesignResolutionPolicy 方法时有影响。 仅在 Web 模式下有效。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:443 |
参数列表
enabledBoolean Enable or disable retina display
isRetinaEnabled
检查是否对 Retina 显示设备进行优化。 仅在 Web 模式下有效。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCView.js:458 |
enableAntiAlias
控制抗锯齿是否开启
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:471 |
参数列表
enabledBoolean Enable or not anti-alias
isAntiAliasEnabled
返回当前是否抗锯齿
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCView.js:505 |
enableAutoFullScreen
启动时,移动端游戏会在移动端自动尝试进入全屏模式。 你能够传入 true 为参数去启动它,用 false 参数来关闭它。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:514 |
参数列表
enabledBoolean Enable or disable auto full screen on mobile devices
isAutoFullScreenEnabled
检查自动进入全屏模式是否启动。 仅在 Web 模式下有效。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCView.js:538 |
getCanvasSize
返回视图中 canvas 的尺寸。 在 native 平台下,它返回全屏视图下屏幕的尺寸。 在 Web 平台下,它返回 canvas 元素尺寸。
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/platform/CCView.js:575 |
getFrameSize
返回视图中边框尺寸。 在 native 平台下,它返回全屏视图下屏幕的尺寸。 在 web 平台下,它返回 canvas 元素的外层 DOM 元素尺寸。
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/platform/CCView.js:590 |
setFrameSize
在 native 平台下,设置视图框架尺寸。 在 web 平台下,设置 canvas 外层 DOM 元素尺寸。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:605 |
参数列表
getVisibleSize
返回视图窗口可见区域尺寸。
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/platform/CCView.js:623 |
getVisibleSizeInPixel
返回视图窗口可见区域像素尺寸。
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/platform/CCView.js:634 |
getVisibleOrigin
返回视图窗口可见区域原点。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/platform/CCView.js:646 |
getVisibleOriginInPixel
返回视图窗口可见区域像素原点。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/platform/CCView.js:657 |
getResolutionPolicy
返回当前分辨率方案
| meta | description |
|---|---|
| 返回 | ResolutionPolicy |
| 定义于 | cocos2d/core/platform/CCView.js:669 |
setResolutionPolicy
设置当前分辨率模式
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:681 |
参数列表
resolutionPolicyResolutionPolicy | Number
setDesignResolutionSize
通过设置设计分辨率和匹配模式来进行游戏画面的屏幕适配。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:710 |
参数列表
widthNumber Design resolution width.heightNumber Design resolution height.resolutionPolicyResolutionPolicy | Number The resolution policy desired
getDesignResolutionSize
返回视图的设计分辨率。
默认下分辨率尺寸同 getFrameSize 方法相同
| meta | description |
|---|---|
| 返回 | Size |
| 定义于 | cocos2d/core/platform/CCView.js:790 |
setRealPixelResolution
设置容器(container)需要的像素分辨率并且适配相应分辨率的游戏内容。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:803 |
参数列表
widthNumber Design resolution width.heightNumber Design resolution height.resolutionPolicyResolutionPolicy | Number The resolution policy desired
setViewportInPoints
用设计分辨率下的点尺寸来设置视窗。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:836 |
| 废弃(Deprecated) | since v2.0 |
参数列表
setScissorInPoints
用设计分辨率下的点的尺寸来设置 scissor 剪裁区域。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/platform/CCView.js:855 |
| 废弃(Deprecated) | since v2.0 |
参数列表
isScissorEnabled
检查 scissor 是否生效。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/platform/CCView.js:888 |
| 废弃(Deprecated) | since v2.0 |
getScissorRect
返回当前的 scissor 剪裁区域。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/platform/CCView.js:900 |
| 废弃(Deprecated) | since v2.0 |
getViewportRect
返回视窗剪裁区域。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/platform/CCView.js:923 |
getScaleX
返回横轴的缩放比,这个缩放比是将画布像素分辨率放到设计分辨率的比例。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCView.js:934 |
getScaleY
返回纵轴的缩放比,这个缩放比是将画布像素分辨率缩放到设计分辨率的比例。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCView.js:945 |
getDevicePixelRatio
返回设备或浏览器像素比例。
| meta | description |
|---|---|
| 返回 | Number |
| 定义于 | cocos2d/core/platform/CCView.js:956 |
convertToLocationInView
将屏幕坐标转换为游戏视图下的坐标。
| meta | description |
|---|---|
| 返回 | Vec2 |
| 定义于 | cocos2d/core/platform/CCView.js:967 |
参数列表
txNumber The X axis translationtyNumber The Y axis translationrelatedPosObject The related position object including "left", "top", "width", "height" informations
事件
design-resolution-changed Event
模块: _decorator 父模块: cc
!en Emit when design resolution changed. !zh 当设计分辨率改变时发送。
索引
Details
canvas-resize Event
模块: _decorator 父模块: cc
!en Emit when canvas resize. !zh 当画布大小改变时发送。