Class cc.view

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.view is the singleton object which represents the game window.

Method Summary

Class Detail

cc.view()
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();

Method Detail

  • adjustViewPort(enabled)
    Sets whether the engine modify the "viewport" meta in your web page.
    It's enabled by default, we strongly suggest you not to disable it.
    And even when it's enabled, you can still set your own "viewport" meta, it won't be overridden
    Only useful on web
    Parameters:
    {Boolean} enabled
    Enable automatic modification to "viewport" meta
  • {Boolean} canSetContentScaleFactor()
    Returns whether developer can set content's scale factor.
    Returns:
    {Boolean}
  • centerWindow()
    Empty function
  • {cc.Point} convertToLocationInView(tx, ty, relatedPos)
    Returns the real location in view for a translation based on a related position
    Parameters:
    {Number} tx
    The X axis translation
    {Number} ty
    The Y axis translation
    {Object} relatedPos
    The related position object including "left", "top", "width", "height" informations
    Returns:
    {cc.Point}
  • ctor()
    Constructor of cc.EGLView
  • enableAutoFullScreen(enabled)
    If enabled, the application will try automatically to enter full screen mode on mobile devices
    You can pass true as parameter to enable it and disable it by passing false.
    Only useful on web
    Parameters:
    {Boolean} enabled
    Enable or disable auto full screen on mobile devices
  • enableRetina(enabled)
    Retina support is enabled by default for Apple device but disabled for other devices,
    it takes effect only when you called setDesignResolutionPolicy
    Only useful on web
    Parameters:
    {Boolean} enabled
    Enable or disable retina display
  • end()
    Force destroying EGL view, subclass must implement this method.
  • {cc.Size|Object} getContentTranslateLeftTop()
    Returns the resolution translate on EGLView
    Returns:
    {cc.Size|Object}
  • {cc.Size} getDesignResolutionSize()
    Returns the designed size for the view. Default resolution size is the same as 'getFrameSize'.
    Returns:
    {cc.Size}
  • {Number} getDevicePixelRatio()
    Returns device pixel ratio for retina display.
    Returns:
    {Number}
  • {cc.Size} getFrameSize()
    Returns the frame size of the view.
    On native platforms, it returns the screen size since the view is a fullscreen view.
    On web, it returns the size of the canvas's outer DOM element.
    Returns:
    {cc.Size}
  • {cc.ResolutionPolicy} getResolutionPolicy()
    Returns the current resolution policy
    Returns:
    {cc.ResolutionPolicy}
    See:
    cc.ResolutionPolicy
  • {Number} getScaleX()
    Returns scale factor of the horizontal direction (X axis).
    Returns:
    {Number}
  • {Number} getScaleY()
    Returns scale factor of the vertical direction (Y axis).
    Returns:
    {Number}
  • {cc.Rect} getScissorRect()
    Returns the current scissor rectangle
    Returns:
    {cc.Rect}
  • {String} getTargetDensityDPI()
    Returns the current target-densitydpi value of cc.view.
    Returns:
    {String}
  • {String} getViewName()
    Returns the name of the view
    Returns:
    {String}
  • {cc.Rect} getViewPortRect()
    Returns the view port rectangle.
    Returns:
    {cc.Rect}
  • {cc.Point} getVisibleOrigin()
    Returns the visible origin of the view port.
    Returns:
    {cc.Point}
  • {cc.Size} getVisibleSize()
    Returns the visible area size of the view port.
    Returns:
    {cc.Size}
  • {Boolean} isAutoFullScreenEnabled()
    Check whether auto full screen is enabled.
    Only useful on web
    Returns:
    {Boolean} Auto full screen enabled or not
  • {Boolean} isOpenGLReady()
    Get whether render system is ready(no matter opengl or canvas),
    this name is for the compatibility with cocos2d-x, subclass must implement this method.
    Returns:
    {Boolean}
  • {Boolean} isRetinaEnabled()
    Check whether retina display is enabled.
    Only useful on web
    Returns:
    {Boolean}
  • {Boolean} isScissorEnabled()
    Returns whether GL_SCISSOR_TEST is enable
    Returns:
    {Boolean}
  • resizeWithBrowserSize(enabled)
    Sets whether resize canvas automatically when browser's size changed.
    Useful only on web.
    Parameters:
    {Boolean} enabled
    Whether enable automatic resize with browser's resize event
  • setContentTranslateLeftTop(offsetLeft, offsetTop)
    Sets the resolution translate on EGLView
    Parameters:
    {Number} offsetLeft
    {Number} offsetTop
  • setDesignResolutionSize(width, height, resolutionPolicy)
    Sets the resolution policy with designed view size in points.
    The resolution policy include:
    [1] ResolutionExactFit Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
    [2] ResolutionNoBorder Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
    [3] ResolutionShowAll Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
    [4] ResolutionFixedHeight Scale the content's height to screen's height and proportionally scale its width
    [5] ResolutionFixedWidth Scale the content's width to screen's width and proportionally scale its height
    [cc.ResolutionPolicy] [Web only feature] Custom resolution policy, constructed by cc.ResolutionPolicy
    Parameters:
    {Number} width
    Design resolution width.
    {Number} height
    Design resolution height.
    {cc.ResolutionPolicy|Number} resolutionPolicy
    The resolution policy desired
  • setFrameSize(width, height)
    On native, it sets the frame size of view.
    On web, it sets the size of the canvas's outer DOM element.
    Parameters:
    {Number} width
    {Number} height
  • setIMEKeyboardState(isOpen)
    Open or close IME keyboard , subclass must implement this method.
    Parameters:
    {Boolean} isOpen
  • setResizeCallback(callback)
    Sets the callback function for cc.view's resize action,
    this callback will be invoked before applying resolution policy,
    so you can do any additional modifications within the callback.
    Useful only on web.
    Parameters:
    {Function|null} callback
    The callback function
  • setResolutionPolicy(resolutionPolicy)
    Sets the current resolution policy
    Parameters:
    {cc.ResolutionPolicy|Number} resolutionPolicy
    See:
    cc.ResolutionPolicy
  • setScissorInPoints(x, y, w, h)
    Sets Scissor rectangle with points.
    Parameters:
    {Number} x
    {Number} y
    {Number} w
    {Number} h
  • setTargetDensityDPI(densityDPI)

    Sets view's target-densitydpi for android mobile browser. it can be set to:
    1. cc.DENSITYDPI_DEVICE, value is "device-dpi"
    2. cc.DENSITYDPI_HIGH, value is "high-dpi" (default value)
    3. cc.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value)
    4. cc.DENSITYDPI_LOW, value is "low-dpi"
    5. Custom value, e.g: "480"

    Parameters:
    {String} densityDPI
  • setViewName(viewName)
    Sets the name of the view
    Parameters:
    {String} viewName
  • setViewPortInPoints(x, y, w, h)
    Sets view port rectangle with points.
    Parameters:
    {Number} x
    {Number} y
    {Number} w
    width
    {Number} h
    height
  • swapBuffers()
    Exchanges the front and back buffers, subclass must implement this method.