• View 类型
    • 索引
      • 方法
      • 事件
  • Details
    • 方法
      • setTargetDensityDPI
        • 参数列表
      • getTargetDensityDPI
      • resizeWithBrowserSize
        • 参数列表
      • setResizeCallback
        • 参数列表
      • setOrientation
        • 参数列表
      • adjustViewportMeta
        • 参数列表
      • enableRetina
        • 参数列表
      • isRetinaEnabled
      • enableAntiAlias
        • 参数列表
      • isAntiAliasEnabled
      • enableAutoFullScreen
        • 参数列表
      • isAutoFullScreenEnabled
      • getCanvasSize
      • getFrameSize
      • setFrameSize
        • 参数列表
      • getVisibleSize
      • getVisibleSizeInPixel
      • getVisibleOrigin
      • getVisibleOriginInPixel
      • getResolutionPolicy
      • setResolutionPolicy
        • 参数列表
      • setDesignResolutionSize
        • 参数列表
      • getDesignResolutionSize
      • setRealPixelResolution
        • 参数列表
      • setViewportInPoints
        • 参数列表
      • setScissorInPoints
        • 参数列表
      • isScissorEnabled
      • getScissorRect
      • getViewportRect
      • getScaleX
      • getScaleY
      • getDevicePixelRatio
      • convertToLocationInView
        • 参数列表
    • 事件
  • design-resolution-changed Event
  • 索引
  • Details
  • canvas-resize Event
  • 索引
  • Details

    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 translationSince 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

    设置目标内容的每英寸像素点密度。

    metadescription
    定义于cocos2d/core/platform/CCView.js:237
    废弃(Deprecated)since v2.0
    参数列表
    • densityDPI String
    getTargetDensityDPI

    获取目标内容的每英寸像素点密度。

    metadescription
    返回String
    定义于cocos2d/core/platform/CCView.js:252
    废弃(Deprecated)since v2.0
    resizeWithBrowserSize

    设置当发现浏览器的尺寸改变时,是否自动调整 canvas 尺寸大小。仅在 Web 模式下有效。

    metadescription
    定义于cocos2d/core/platform/CCView.js:261
    参数列表
    • enabled Boolean Whether enable automatic resize with browser's resize event
    setResizeCallback

    设置 cc.view 调整视窗尺寸行为的回调函数,这个回调函数会在应用适配模式之前被调用,因此你可以在这个回调函数内添加任意附加改变,仅在 Web 平台下有效。

    metadescription
    定义于cocos2d/core/platform/CCView.js:288
    参数列表
    • callback Function | Null The callback function
    setOrientation

    设置游戏屏幕朝向,它能够是横版,竖版或自动。当设置为横版或竖版,并且屏幕的宽高比例不匹配时,cc.view 会自动用 CSS 旋转游戏场景的 canvas,这个方法不会对 native 部分产生任何影响,对于 native 而言,你需要在应用设置中的设置排版。

    metadescription
    定义于cocos2d/core/platform/CCView.js:307
    参数列表
    • orientation Number Possible values: cc.macro.ORIENTATION_LANDSCAPE | cc.macro.ORIENTATION_PORTRAIT | cc.macro.ORIENTATION_AUTO
    adjustViewportMeta

    设置引擎是否调整 viewport meta 来配合屏幕适配。默认设置为启动,我们强烈建议你不要将它设置为关闭。即使当它启动时,你仍然能够设置你的 viewport meta,它不会被覆盖。仅在 Web 模式下有效

    metadescription
    定义于cocos2d/core/platform/CCView.js:413
    参数列表
    • enabled Boolean Enable automatic modification to "viewport" meta
    enableRetina

    对于 Apple 这种支持 Retina 显示的设备上默认进行优化而其他类型设备默认不进行优化,它仅会在你调用 setDesignResolutionPolicy 方法时有影响。仅在 Web 模式下有效。

    metadescription
    定义于cocos2d/core/platform/CCView.js:430
    参数列表
    • enabled Boolean Enable or disable retina display
    isRetinaEnabled

    检查是否对 Retina 显示设备进行优化。仅在 Web 模式下有效。

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/CCView.js:445
    enableAntiAlias

    控制抗锯齿是否开启

    metadescription
    定义于cocos2d/core/platform/CCView.js:458
    参数列表
    • enabled Boolean Enable or not anti-alias
    isAntiAliasEnabled

    返回当前是否抗锯齿

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/CCView.js:492
    enableAutoFullScreen

    启动时,移动端游戏会在移动端自动尝试进入全屏模式。你能够传入 true 为参数去启动它,用 false 参数来关闭它。

    metadescription
    定义于cocos2d/core/platform/CCView.js:501
    参数列表
    • enabled Boolean Enable or disable auto full screen on mobile devices
    isAutoFullScreenEnabled

    检查自动进入全屏模式是否启动。仅在 Web 模式下有效。

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/CCView.js:525
    getCanvasSize

    返回视图中 canvas 的尺寸。在 native 平台下,它返回全屏视图下屏幕的尺寸。在 Web 平台下,它返回 canvas 元素尺寸。

    metadescription
    返回Size
    定义于cocos2d/core/platform/CCView.js:562
    getFrameSize

    返回视图中边框尺寸。在 native 平台下,它返回全屏视图下屏幕的尺寸。在 web 平台下,它返回 canvas 元素的外层 DOM 元素尺寸。

    metadescription
    返回Size
    定义于cocos2d/core/platform/CCView.js:577
    setFrameSize

    在 native 平台下,设置视图框架尺寸。在 web 平台下,设置 canvas 外层 DOM 元素尺寸。

    metadescription
    定义于cocos2d/core/platform/CCView.js:592
    参数列表
    • width Number
    • height Number
    getVisibleSize

    返回视图窗口可见区域尺寸。

    metadescription
    返回Size
    定义于cocos2d/core/platform/CCView.js:610
    getVisibleSizeInPixel

    返回视图窗口可见区域像素尺寸。

    metadescription
    返回Size
    定义于cocos2d/core/platform/CCView.js:621
    getVisibleOrigin

    返回视图窗口可见区域原点。

    metadescription
    返回Vec2
    定义于cocos2d/core/platform/CCView.js:633
    getVisibleOriginInPixel

    返回视图窗口可见区域像素原点。

    metadescription
    返回Vec2
    定义于cocos2d/core/platform/CCView.js:644
    getResolutionPolicy

    返回当前分辨率方案

    metadescription
    返回ResolutionPolicy
    定义于cocos2d/core/platform/CCView.js:656
    setResolutionPolicy

    设置当前分辨率模式

    metadescription
    定义于cocos2d/core/platform/CCView.js:668
    参数列表
    • resolutionPolicy ResolutionPolicy | Number
    setDesignResolutionSize

    通过设置设计分辨率和匹配模式来进行游戏画面的屏幕适配。

    metadescription
    定义于cocos2d/core/platform/CCView.js:697
    参数列表
    • width Number Design resolution width.
    • height Number Design resolution height.
    • resolutionPolicy ResolutionPolicy | Number The resolution policy desired
    getDesignResolutionSize

    返回视图的设计分辨率。默认下分辨率尺寸同 getFrameSize 方法相同

    metadescription
    返回Size
    定义于cocos2d/core/platform/CCView.js:777
    setRealPixelResolution

    设置容器(container)需要的像素分辨率并且适配相应分辨率的游戏内容。

    metadescription
    定义于cocos2d/core/platform/CCView.js:790
    参数列表
    • width Number Design resolution width.
    • height Number Design resolution height.
    • resolutionPolicy ResolutionPolicy | Number The resolution policy desired
    setViewportInPoints

    用设计分辨率下的点尺寸来设置视窗。

    metadescription
    定义于cocos2d/core/platform/CCView.js:823
    废弃(Deprecated)since v2.0
    参数列表
    • x Number
    • y Number
    • w Number width
    • h Number height
    setScissorInPoints

    用设计分辨率下的点的尺寸来设置 scissor 剪裁区域。

    metadescription
    定义于cocos2d/core/platform/CCView.js:842
    废弃(Deprecated)since v2.0
    参数列表
    • x Number
    • y Number
    • w Number
    • h Number
    isScissorEnabled

    检查 scissor 是否生效。

    metadescription
    返回Boolean
    定义于cocos2d/core/platform/CCView.js:875
    废弃(Deprecated)since v2.0
    getScissorRect

    返回当前的 scissor 剪裁区域。

    metadescription
    返回Rect
    定义于cocos2d/core/platform/CCView.js:887
    废弃(Deprecated)since v2.0
    getViewportRect

    返回视窗剪裁区域。

    metadescription
    返回Rect
    定义于cocos2d/core/platform/CCView.js:910
    getScaleX

    返回横轴的缩放比,这个缩放比是将画布像素分辨率放到设计分辨率的比例。

    metadescription
    返回Number
    定义于cocos2d/core/platform/CCView.js:921
    getScaleY

    返回纵轴的缩放比,这个缩放比是将画布像素分辨率缩放到设计分辨率的比例。

    metadescription
    返回Number
    定义于cocos2d/core/platform/CCView.js:932
    getDevicePixelRatio

    返回设备或浏览器像素比例。

    metadescription
    返回Number
    定义于cocos2d/core/platform/CCView.js:943
    convertToLocationInView

    将屏幕坐标转换为游戏视图下的坐标。

    metadescription
    返回Vec2
    定义于cocos2d/core/platform/CCView.js:954
    参数列表
    • tx Number The X axis translation
    • ty Number The Y axis translation
    • relatedPos Object The related position object including "left", "top", "width", "height" informations

    事件

    design-resolution-changed Event

    模块: _decorator父模块: cc

    !enEmit when design resolution changed.!zh当设计分辨率改变时发送。

    索引

    Details

    canvas-resize Event

    模块: _decorator父模块: cc

    !enEmit when canvas resize.!zh当画布大小改变时发送。

    索引

    Details