Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

View

Module: 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();

Methods

setTargetDensityDPI
(
  • densityDPI
)

Sets view's target-densitydpi for android mobile browser. it can be set to:

  1. cc.macro.DENSITYDPI_DEVICE, value is "device-dpi"
  2. cc.macro.DENSITYDPI_HIGH, value is "high-dpi" (default value)
  3. cc.macro.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value)
  4. cc.macro.DENSITYDPI_LOW, value is "low-dpi"
  5. Custom value, e.g: "480"

name type description
densityDPI String

getTargetDensityDPI ( ) String

Returns the current target-densitydpi value of cc.view.

returns:

type: String

resizeWithBrowserSize
(
  • enabled
)

Sets whether resize canvas automatically when browser's size changed.
Useful only on web.

name type description
enabled Boolean

Whether enable automatic resize with browser's resize event

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.

name type description
callback Function | Null

The callback function

setOrientation
(
  • orientation
)

Sets the orientation of the game, it can be landscape, portrait or auto. When set it to landscape or portrait, and screen w/h ratio doesn't fit, cc.view will automatically rotate the game canvas using CSS. Note that this function doesn't have any effect in native, in native, you need to set the application orientation in native project settings

name type description
orientation Number

Possible values: cc.macro.ORIENTATION_LANDSCAPE | cc.macro.ORIENTATION_PORTRAIT | cc.macro.ORIENTATION_AUTO

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

name type description
enabled Boolean

Enable automatic modification to "viewport" meta

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

name type description
enabled Boolean

Enable or disable retina display

isRetinaEnabled ( ) Boolean

Check whether retina display is enabled.
Only useful on web

returns:

type: Boolean

enableAntiAlias
(
  • enabled
)

Whether to Enable on anti-alias

name type description
enabled Boolean

Enable or not anti-alias

isAntiAliasEnabled ( ) Boolean

Returns whether the current enable on anti-alias

returns:

type: Boolean