1 /**************************************************************************** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies Inc. 5 6 http://www.cocos2d-x.org 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy 9 of this software and associated documentation files (the "Software"), to deal 10 in the Software without restriction, including without limitation the rights 11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 copies of the Software, and to permit persons to whom the Software is 13 furnished to do so, subject to the following conditions: 14 15 The above copyright notice and this permission notice shall be included in 16 all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 THE SOFTWARE. 25 ****************************************************************************/ 26 27 /** 28 * @ignore 29 */ 30 cc.Touches = []; 31 cc.TouchesIntergerDict = {}; 32 33 cc.DENSITYDPI_DEVICE = "device-dpi"; 34 cc.DENSITYDPI_HIGH = "high-dpi"; 35 cc.DENSITYDPI_MEDIUM = "medium-dpi"; 36 cc.DENSITYDPI_LOW = "low-dpi"; 37 38 cc.__BrowserGetter = { 39 init: function(){ 40 this.html = document.getElementsByTagName("html")[0]; 41 }, 42 availWidth: function(frame){ 43 if(!frame || frame === this.html) 44 return window.innerWidth; 45 else 46 return frame.clientWidth; 47 }, 48 availHeight: function(frame){ 49 if(!frame || frame === this.html) 50 return window.innerHeight; 51 else 52 return frame.clientHeight; 53 }, 54 meta: { 55 "width": "device-width" 56 }, 57 adaptationType: cc.sys.browserType 58 }; 59 60 if(window.navigator.userAgent.indexOf("OS 8_1_") > -1) //this mistake like MIUI, so use of MIUI treatment method 61 cc.__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_MIUI; 62 63 if(cc.sys.os === cc.sys.OS_IOS) // All browsers are WebView 64 cc.__BrowserGetter.adaptationType = cc.sys.BROWSER_TYPE_SAFARI; 65 66 switch(cc.__BrowserGetter.adaptationType){ 67 case cc.sys.BROWSER_TYPE_SAFARI: 68 cc.__BrowserGetter.meta["minimal-ui"] = "true"; 69 cc.__BrowserGetter.availWidth = function(frame){ 70 return frame.clientWidth; 71 }; 72 cc.__BrowserGetter.availHeight = function(frame){ 73 return frame.clientHeight; 74 }; 75 break; 76 case cc.sys.BROWSER_TYPE_CHROME: 77 cc.__BrowserGetter.__defineGetter__("target-densitydpi", function(){ 78 return cc.view._targetDensityDPI; 79 }); 80 case cc.sys.BROWSER_TYPE_SOUGOU: 81 case cc.sys.BROWSER_TYPE_UC: 82 cc.__BrowserGetter.availWidth = function(frame){ 83 return frame.clientWidth; 84 }; 85 cc.__BrowserGetter.availHeight = function(frame){ 86 return frame.clientHeight; 87 }; 88 break; 89 case cc.sys.BROWSER_TYPE_MIUI: 90 cc.__BrowserGetter.init = function(view){ 91 if(view.__resizeWithBrowserSize) return; 92 var resize = function(){ 93 view.setDesignResolutionSize( 94 view._designResolutionSize.width, 95 view._designResolutionSize.height, 96 view._resolutionPolicy 97 ); 98 window.removeEventListener("resize", resize, false); 99 }; 100 window.addEventListener("resize", resize, false); 101 }; 102 break; 103 } 104 105 /** 106 * cc.view is the singleton object which represents the game window.<br/> 107 * It's main task include: <br/> 108 * - Apply the design resolution policy<br/> 109 * - Provide interaction with the window, like resize event on web, retina display support, etc...<br/> 110 * - Manage the game view port which can be different with the window<br/> 111 * - Manage the content scale and translation<br/> 112 * <br/> 113 * Since the cc.view is a singleton, you don't need to call any constructor or create functions,<br/> 114 * the standard way to use it is by calling:<br/> 115 * - cc.view.methodName(); <br/> 116 * @class 117 * @name cc.view 118 * @extend cc.Class 119 */ 120 cc.EGLView = cc.Class.extend(/** @lends cc.view# */{ 121 _delegate: null, 122 // Size of parent node that contains cc.container and cc._canvas 123 _frameSize: null, 124 // resolution size, it is the size appropriate for the app resources. 125 _designResolutionSize: null, 126 _originalDesignResolutionSize: null, 127 // Viewport is the container's rect related to content's coordinates in pixel 128 _viewPortRect: null, 129 // The visible rect in content's coordinate in point 130 _visibleRect: null, 131 _retinaEnabled: false, 132 _autoFullScreen: true, 133 // The device's pixel ratio (for retina displays) 134 _devicePixelRatio: 1, 135 // the view name 136 _viewName: "", 137 // Custom callback for resize event 138 _resizeCallback: null, 139 _scaleX: 1, 140 _originalScaleX: 1, 141 _scaleY: 1, 142 _originalScaleY: 1, 143 _indexBitsUsed: 0, 144 _maxTouches: 5, 145 _resolutionPolicy: null, 146 _rpExactFit: null, 147 _rpShowAll: null, 148 _rpNoBorder: null, 149 _rpFixedHeight: null, 150 _rpFixedWidth: null, 151 _initialized: false, 152 153 _captured: false, 154 _wnd: null, 155 _hDC: null, 156 _hRC: null, 157 _supportTouch: false, 158 _contentTranslateLeftTop: null, 159 160 // Parent node that contains cc.container and cc._canvas 161 _frame: null, 162 _frameZoomFactor: 1.0, 163 __resizeWithBrowserSize: false, 164 _isAdjustViewPort: true, 165 _targetDensityDPI: null, 166 167 /** 168 * Constructor of cc.EGLView 169 */ 170 ctor: function () { 171 var _t = this, d = document, _strategyer = cc.ContainerStrategy, _strategy = cc.ContentStrategy; 172 173 cc.__BrowserGetter.init(this); 174 175 _t._frame = (cc.container.parentNode === d.body) ? d.documentElement : cc.container.parentNode; 176 _t._frameSize = cc.size(0, 0); 177 _t._initFrameSize(); 178 179 var w = cc._canvas.width, h = cc._canvas.height; 180 _t._designResolutionSize = cc.size(w, h); 181 _t._originalDesignResolutionSize = cc.size(w, h); 182 _t._viewPortRect = cc.rect(0, 0, w, h); 183 _t._visibleRect = cc.rect(0, 0, w, h); 184 _t._contentTranslateLeftTop = {left: 0, top: 0}; 185 _t._viewName = "Cocos2dHTML5"; 186 187 var sys = cc.sys; 188 _t.enableRetina(sys.os === sys.OS_IOS || sys.os === sys.OS_OSX); 189 cc.visibleRect && cc.visibleRect.init(_t._visibleRect); 190 191 // Setup system default resolution policies 192 _t._rpExactFit = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.EXACT_FIT); 193 _t._rpShowAll = new cc.ResolutionPolicy(_strategyer.PROPORTION_TO_FRAME, _strategy.SHOW_ALL); 194 _t._rpNoBorder = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.NO_BORDER); 195 _t._rpFixedHeight = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_HEIGHT); 196 _t._rpFixedWidth = new cc.ResolutionPolicy(_strategyer.EQUAL_TO_FRAME, _strategy.FIXED_WIDTH); 197 198 _t._hDC = cc._canvas; 199 _t._hRC = cc._renderContext; 200 _t._targetDensityDPI = cc.DENSITYDPI_HIGH; 201 }, 202 203 // Resize helper functions 204 _resizeEvent: function () { 205 var view; 206 if(this.setDesignResolutionSize){ 207 view = this; 208 }else{ 209 view = cc.view; 210 } 211 212 // Check frame size changed or not 213 var prevFrameW = view._frameSize.width, prevFrameH = view._frameSize.height; 214 view._initFrameSize(); 215 if (view._frameSize.width === prevFrameW && view._frameSize.height === prevFrameH) 216 return; 217 218 // Frame size changed, do resize works 219 if (view._resizeCallback) { 220 view._resizeCallback.call(); 221 } 222 var width = view._originalDesignResolutionSize.width; 223 var height = view._originalDesignResolutionSize.height; 224 if (width > 0) 225 view.setDesignResolutionSize(width, height, view._resolutionPolicy); 226 }, 227 228 /** 229 * <p> 230 * Sets view's target-densitydpi for android mobile browser. it can be set to: <br/> 231 * 1. cc.DENSITYDPI_DEVICE, value is "device-dpi" <br/> 232 * 2. cc.DENSITYDPI_HIGH, value is "high-dpi" (default value) <br/> 233 * 3. cc.DENSITYDPI_MEDIUM, value is "medium-dpi" (browser's default value) <br/> 234 * 4. cc.DENSITYDPI_LOW, value is "low-dpi" <br/> 235 * 5. Custom value, e.g: "480" <br/> 236 * </p> 237 * @param {String} densityDPI 238 */ 239 setTargetDensityDPI: function(densityDPI){ 240 this._targetDensityDPI = densityDPI; 241 this._adjustViewportMeta(); 242 }, 243 244 /** 245 * Returns the current target-densitydpi value of cc.view. 246 * @returns {String} 247 */ 248 getTargetDensityDPI: function(){ 249 return this._targetDensityDPI; 250 }, 251 252 /** 253 * Sets whether resize canvas automatically when browser's size changed.<br/> 254 * Useful only on web. 255 * @param {Boolean} enabled Whether enable automatic resize with browser's resize event 256 */ 257 resizeWithBrowserSize: function (enabled) { 258 if (enabled) { 259 //enable 260 if (!this.__resizeWithBrowserSize) { 261 this.__resizeWithBrowserSize = true; 262 window.addEventListener('resize', this._resizeEvent); 263 window.addEventListener('orientationchange', this._resizeEvent); 264 } 265 } else { 266 //disable 267 if (this.__resizeWithBrowserSize) { 268 this.__resizeWithBrowserSize = false; 269 window.removeEventListener('resize', this._resizeEvent); 270 window.removeEventListener('orientationchange', this._resizeEvent); 271 } 272 } 273 }, 274 275 /** 276 * Sets the callback function for cc.view's resize action,<br/> 277 * this callback will be invoked before applying resolution policy, <br/> 278 * so you can do any additional modifications within the callback.<br/> 279 * Useful only on web. 280 * @param {Function|null} callback The callback function 281 */ 282 setResizeCallback: function (callback) { 283 if (cc.isFunction(callback) || callback == null) { 284 this._resizeCallback = callback; 285 } 286 }, 287 288 _initFrameSize: function () { 289 var locFrameSize = this._frameSize; 290 locFrameSize.width = cc.__BrowserGetter.availWidth(this._frame); 291 locFrameSize.height = cc.__BrowserGetter.availHeight(this._frame); 292 }, 293 294 // hack 295 _adjustSizeKeepCanvasSize: function () { 296 var designWidth = this._originalDesignResolutionSize.width; 297 var designHeight = this._originalDesignResolutionSize.height; 298 if (designWidth > 0) 299 this.setDesignResolutionSize(designWidth, designHeight, this._resolutionPolicy); 300 }, 301 302 _setViewportMeta: function (metas, overwrite) { 303 var vp = document.getElementById("cocosMetaElement"); 304 if(vp && overwrite){ 305 document.head.removeChild(vp); 306 } 307 308 var elems = document.getElementsByName("viewport"), 309 currentVP = elems ? elems[0] : null, 310 content, key, pattern; 311 312 content = currentVP ? currentVP.content : ""; 313 vp = vp || document.createElement("meta"); 314 vp.id = "cocosMetaElement"; 315 vp.name = "viewport"; 316 vp.content = ""; 317 318 for (key in metas) { 319 if (content.indexOf(key) == -1) { 320 content += "," + key + "=" + metas[key]; 321 } 322 else if (overwrite) { 323 pattern = new RegExp(key+"\s*=\s*[^,]+"); 324 content.replace(pattern, key + "=" + metas[key]); 325 } 326 } 327 if(/^,/.test(content)) 328 content = content.substr(1); 329 330 vp.content = content; 331 // For adopting certain android devices which don't support second viewport 332 if (currentVP) 333 currentVP.content = content; 334 335 document.head.appendChild(vp); 336 }, 337 338 _adjustViewportMeta: function () { 339 if (this._isAdjustViewPort) { 340 this._setViewportMeta(cc.__BrowserGetter.meta, false); 341 } 342 }, 343 344 // RenderTexture hacker 345 _setScaleXYForRenderTexture: function () { 346 //hack for RenderTexture on canvas mode when adapting multiple resolution resources 347 var scaleFactor = cc.contentScaleFactor(); 348 this._scaleX = scaleFactor; 349 this._scaleY = scaleFactor; 350 }, 351 352 // Other helper functions 353 _resetScale: function () { 354 this._scaleX = this._originalScaleX; 355 this._scaleY = this._originalScaleY; 356 }, 357 358 // Useless, just make sure the compatibility temporarily, should be removed 359 _adjustSizeToBrowser: function () { 360 }, 361 362 initialize: function () { 363 this._initialized = true; 364 }, 365 366 /** 367 * Sets whether the engine modify the "viewport" meta in your web page.<br/> 368 * It's enabled by default, we strongly suggest you not to disable it.<br/> 369 * And even when it's enabled, you can still set your own "viewport" meta, it won't be overridden<br/> 370 * Only useful on web 371 * @param {Boolean} enabled Enable automatic modification to "viewport" meta 372 */ 373 adjustViewPort: function (enabled) { 374 this._isAdjustViewPort = enabled; 375 }, 376 377 /** 378 * Retina support is enabled by default for Apple device but disabled for other devices,<br/> 379 * it takes effect only when you called setDesignResolutionPolicy<br/> 380 * Only useful on web 381 * @param {Boolean} enabled Enable or disable retina display 382 */ 383 enableRetina: function(enabled) { 384 this._retinaEnabled = enabled ? true : false; 385 }, 386 387 /** 388 * Check whether retina display is enabled.<br/> 389 * Only useful on web 390 * @return {Boolean} 391 */ 392 isRetinaEnabled: function() { 393 return this._retinaEnabled; 394 }, 395 396 /** 397 * If enabled, the application will try automatically to enter full screen mode on mobile devices<br/> 398 * You can pass true as parameter to enable it and disable it by passing false.<br/> 399 * Only useful on web 400 * @param {Boolean} enabled Enable or disable auto full screen on mobile devices 401 */ 402 enableAutoFullScreen: function(enabled) { 403 this._autoFullScreen = enabled ? true : false; 404 }, 405 406 /** 407 * Check whether auto full screen is enabled.<br/> 408 * Only useful on web 409 * @return {Boolean} Auto full screen enabled or not 410 */ 411 isAutoFullScreenEnabled: function() { 412 return this._autoFullScreen; 413 }, 414 415 /** 416 * Force destroying EGL view, subclass must implement this method. 417 */ 418 end: function () { 419 }, 420 421 /** 422 * Get whether render system is ready(no matter opengl or canvas),<br/> 423 * this name is for the compatibility with cocos2d-x, subclass must implement this method. 424 * @return {Boolean} 425 */ 426 isOpenGLReady: function () { 427 return (this._hDC !== null && this._hRC !== null); 428 }, 429 430 /* 431 * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop. 432 * @param {Number} zoomFactor 433 */ 434 setFrameZoomFactor: function (zoomFactor) { 435 this._frameZoomFactor = zoomFactor; 436 this.centerWindow(); 437 cc.director.setProjection(cc.director.getProjection()); 438 }, 439 440 /** 441 * Exchanges the front and back buffers, subclass must implement this method. 442 */ 443 swapBuffers: function () { 444 }, 445 446 /** 447 * Open or close IME keyboard , subclass must implement this method. 448 * @param {Boolean} isOpen 449 */ 450 setIMEKeyboardState: function (isOpen) { 451 }, 452 453 /** 454 * Sets the resolution translate on EGLView 455 * @param {Number} offsetLeft 456 * @param {Number} offsetTop 457 */ 458 setContentTranslateLeftTop: function (offsetLeft, offsetTop) { 459 this._contentTranslateLeftTop = {left: offsetLeft, top: offsetTop}; 460 }, 461 462 /** 463 * Returns the resolution translate on EGLView 464 * @return {cc.Size|Object} 465 */ 466 getContentTranslateLeftTop: function () { 467 return this._contentTranslateLeftTop; 468 }, 469 470 /** 471 * Returns the canvas size of the view.<br/> 472 * On native platforms, it returns the screen size since the view is a fullscreen view.<br/> 473 * On web, it returns the size of the canvas element. 474 * @return {cc.Size} 475 */ 476 getCanvasSize: function () { 477 return cc.size(cc._canvas.width, cc._canvas.height); 478 }, 479 480 /** 481 * Returns the frame size of the view.<br/> 482 * On native platforms, it returns the screen size since the view is a fullscreen view.<br/> 483 * On web, it returns the size of the canvas's outer DOM element. 484 * @return {cc.Size} 485 */ 486 getFrameSize: function () { 487 return cc.size(this._frameSize.width, this._frameSize.height); 488 }, 489 490 /** 491 * On native, it sets the frame size of view.<br/> 492 * On web, it sets the size of the canvas's outer DOM element. 493 * @param {Number} width 494 * @param {Number} height 495 */ 496 setFrameSize: function (width, height) { 497 this._frameSize.width = width; 498 this._frameSize.height = height; 499 this._frame.style.width = width + "px"; 500 this._frame.style.height = height + "px"; 501 //this.centerWindow(); 502 this._resizeEvent(); 503 cc.director.setProjection(cc.director.getProjection()); 504 }, 505 506 /** 507 * Empty function 508 */ 509 centerWindow: function () { 510 }, 511 512 /** 513 * Returns the visible area size of the view port. 514 * @return {cc.Size} 515 */ 516 getVisibleSize: function () { 517 return cc.size(this._visibleRect.width,this._visibleRect.height); 518 }, 519 520 /** 521 * Returns the visible area size of the view port. 522 * @return {cc.Size} 523 */ 524 getVisibleSizeInPixel: function () { 525 return cc.size( this._visibleRect.width * this._scaleX, 526 this._visibleRect.height * this._scaleY ); 527 }, 528 529 /** 530 * Returns the visible origin of the view port. 531 * @return {cc.Point} 532 */ 533 getVisibleOrigin: function () { 534 return cc.p(this._visibleRect.x,this._visibleRect.y); 535 }, 536 537 /** 538 * Returns the visible origin of the view port. 539 * @return {cc.Point} 540 */ 541 getVisibleOriginInPixel: function () { 542 return cc.p(this._visibleRect.x * this._scaleX, 543 this._visibleRect.y * this._scaleY); 544 }, 545 546 /** 547 * Returns whether developer can set content's scale factor. 548 * @return {Boolean} 549 */ 550 canSetContentScaleFactor: function () { 551 return true; 552 }, 553 554 /** 555 * Returns the current resolution policy 556 * @see cc.ResolutionPolicy 557 * @return {cc.ResolutionPolicy} 558 */ 559 getResolutionPolicy: function () { 560 return this._resolutionPolicy; 561 }, 562 563 /** 564 * Sets the current resolution policy 565 * @see cc.ResolutionPolicy 566 * @param {cc.ResolutionPolicy|Number} resolutionPolicy 567 */ 568 setResolutionPolicy: function (resolutionPolicy) { 569 var _t = this; 570 if (resolutionPolicy instanceof cc.ResolutionPolicy) { 571 _t._resolutionPolicy = resolutionPolicy; 572 } 573 // Ensure compatibility with JSB 574 else { 575 var _locPolicy = cc.ResolutionPolicy; 576 if(resolutionPolicy === _locPolicy.EXACT_FIT) 577 _t._resolutionPolicy = _t._rpExactFit; 578 if(resolutionPolicy === _locPolicy.SHOW_ALL) 579 _t._resolutionPolicy = _t._rpShowAll; 580 if(resolutionPolicy === _locPolicy.NO_BORDER) 581 _t._resolutionPolicy = _t._rpNoBorder; 582 if(resolutionPolicy === _locPolicy.FIXED_HEIGHT) 583 _t._resolutionPolicy = _t._rpFixedHeight; 584 if(resolutionPolicy === _locPolicy.FIXED_WIDTH) 585 _t._resolutionPolicy = _t._rpFixedWidth; 586 } 587 }, 588 589 /** 590 * Sets the resolution policy with designed view size in points.<br/> 591 * The resolution policy include: <br/> 592 * [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.<br/> 593 * [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.<br/> 594 * [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.<br/> 595 * [4] ResolutionFixedHeight Scale the content's height to screen's height and proportionally scale its width<br/> 596 * [5] ResolutionFixedWidth Scale the content's width to screen's width and proportionally scale its height<br/> 597 * [cc.ResolutionPolicy] [Web only feature] Custom resolution policy, constructed by cc.ResolutionPolicy<br/> 598 * @param {Number} width Design resolution width. 599 * @param {Number} height Design resolution height. 600 * @param {cc.ResolutionPolicy|Number} resolutionPolicy The resolution policy desired 601 */ 602 setDesignResolutionSize: function (width, height, resolutionPolicy) { 603 // Defensive code 604 if( !(width > 0 || height > 0) ){ 605 cc.log(cc._LogInfos.EGLView_setDesignResolutionSize); 606 return; 607 } 608 609 this.setResolutionPolicy(resolutionPolicy); 610 var policy = this._resolutionPolicy; 611 if (!policy){ 612 cc.log(cc._LogInfos.EGLView_setDesignResolutionSize_2); 613 return; 614 } 615 policy.preApply(this); 616 617 // Reinit frame size 618 if(cc.sys.isMobile) 619 this._adjustViewportMeta(); 620 621 this._initFrameSize(); 622 623 this._originalDesignResolutionSize.width = this._designResolutionSize.width = width; 624 this._originalDesignResolutionSize.height = this._designResolutionSize.height = height; 625 626 var result = policy.apply(this, this._designResolutionSize); 627 628 if(result.scale && result.scale.length === 2){ 629 this._scaleX = result.scale[0]; 630 this._scaleY = result.scale[1]; 631 } 632 633 if(result.viewport){ 634 var vp = this._viewPortRect, 635 vb = this._visibleRect, 636 rv = result.viewport; 637 638 vp.x = rv.x; 639 vp.y = rv.y; 640 vp.width = rv.width; 641 vp.height = rv.height; 642 643 vb.x = -vp.x / this._scaleX; 644 vb.y = -vp.y / this._scaleY; 645 vb.width = cc._canvas.width / this._scaleX; 646 vb.height = cc._canvas.height / this._scaleY; 647 cc._renderContext.setOffset && cc._renderContext.setOffset(vp.x, -vp.y) 648 } 649 650 // reset director's member variables to fit visible rect 651 var director = cc.director; 652 director._winSizeInPoints.width = this._designResolutionSize.width; 653 director._winSizeInPoints.height = this._designResolutionSize.height; 654 policy.postApply(this); 655 cc.winSize.width = director._winSizeInPoints.width; 656 cc.winSize.height = director._winSizeInPoints.height; 657 658 if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) { 659 // reset director's member variables to fit visible rect 660 director.setGLDefaultValues(); 661 } 662 663 this._originalScaleX = this._scaleX; 664 this._originalScaleY = this._scaleY; 665 // For editbox 666 if (cc.DOM) 667 cc.DOM._resetEGLViewDiv(); 668 cc.visibleRect && cc.visibleRect.init(this._visibleRect); 669 }, 670 671 /** 672 * Returns the designed size for the view. 673 * Default resolution size is the same as 'getFrameSize'. 674 * @return {cc.Size} 675 */ 676 getDesignResolutionSize: function () { 677 return cc.size(this._designResolutionSize.width, this._designResolutionSize.height); 678 }, 679 680 /** 681 * Sets the document body to desired pixel resolution and fit the game content to it. 682 * This function is very useful for adaptation in mobile browsers. 683 * In some HD android devices, the resolution is very high, but its browser performance may not be very good. 684 * In this case, enabling retina display is very costy and not suggested, and if retina is disabled, the image may be blurry. 685 * But this API can be helpful to set a desired pixel resolution which is in between. 686 * This API will do the following: 687 * 1. Set viewport's width to the desired width in pixel 688 * 2. Set body width to the exact pixel resolution 689 * 3. The resolution policy will be reset with designed view size in points. 690 * @param {Number} width Design resolution width. 691 * @param {Number} height Design resolution height. 692 * @param {cc.ResolutionPolicy|Number} resolutionPolicy The resolution policy desired 693 */ 694 setRealPixelResolution: function (width, height, resolutionPolicy) { 695 // Set viewport's width 696 this._setViewportMeta({"width": width, "target-densitydpi": cc.DENSITYDPI_DEVICE}, true); 697 698 // Set body width to the exact pixel resolution 699 document.body.style.width = width + "px"; 700 document.body.style.left = "0px"; 701 document.body.style.top = "0px"; 702 703 // Reset the resolution size and policy 704 this.setDesignResolutionSize(width, height, resolutionPolicy); 705 }, 706 707 /** 708 * Sets view port rectangle with points. 709 * @param {Number} x 710 * @param {Number} y 711 * @param {Number} w width 712 * @param {Number} h height 713 */ 714 setViewPortInPoints: function (x, y, w, h) { 715 var locFrameZoomFactor = this._frameZoomFactor, locScaleX = this._scaleX, locScaleY = this._scaleY; 716 cc._renderContext.viewport((x * locScaleX * locFrameZoomFactor + this._viewPortRect.x * locFrameZoomFactor), 717 (y * locScaleY * locFrameZoomFactor + this._viewPortRect.y * locFrameZoomFactor), 718 (w * locScaleX * locFrameZoomFactor), 719 (h * locScaleY * locFrameZoomFactor)); 720 }, 721 722 /** 723 * Sets Scissor rectangle with points. 724 * @param {Number} x 725 * @param {Number} y 726 * @param {Number} w 727 * @param {Number} h 728 */ 729 setScissorInPoints: function (x, y, w, h) { 730 var locFrameZoomFactor = this._frameZoomFactor, locScaleX = this._scaleX, locScaleY = this._scaleY; 731 cc._renderContext.scissor((x * locScaleX * locFrameZoomFactor + this._viewPortRect.x * locFrameZoomFactor), 732 (y * locScaleY * locFrameZoomFactor + this._viewPortRect.y * locFrameZoomFactor), 733 (w * locScaleX * locFrameZoomFactor), 734 (h * locScaleY * locFrameZoomFactor)); 735 }, 736 737 /** 738 * Returns whether GL_SCISSOR_TEST is enable 739 * @return {Boolean} 740 */ 741 isScissorEnabled: function () { 742 var gl = cc._renderContext; 743 return gl.isEnabled(gl.SCISSOR_TEST); 744 }, 745 746 /** 747 * Returns the current scissor rectangle 748 * @return {cc.Rect} 749 */ 750 getScissorRect: function () { 751 var gl = cc._renderContext, scaleX = this._scaleX, scaleY = this._scaleY; 752 var boxArr = gl.getParameter(gl.SCISSOR_BOX); 753 return cc.rect((boxArr[0] - this._viewPortRect.x) / scaleX, (boxArr[1] - this._viewPortRect.y) / scaleY, 754 boxArr[2] / scaleX, boxArr[3] / scaleY); 755 }, 756 757 /** 758 * Sets the name of the view 759 * @param {String} viewName 760 */ 761 setViewName: function (viewName) { 762 if (viewName != null && viewName.length > 0) { 763 this._viewName = viewName; 764 } 765 }, 766 767 /** 768 * Returns the name of the view 769 * @return {String} 770 */ 771 getViewName: function () { 772 return this._viewName; 773 }, 774 775 /** 776 * Returns the view port rectangle. 777 * @return {cc.Rect} 778 */ 779 getViewPortRect: function () { 780 return this._viewPortRect; 781 }, 782 783 /** 784 * Returns scale factor of the horizontal direction (X axis). 785 * @return {Number} 786 */ 787 getScaleX: function () { 788 return this._scaleX; 789 }, 790 791 /** 792 * Returns scale factor of the vertical direction (Y axis). 793 * @return {Number} 794 */ 795 getScaleY: function () { 796 return this._scaleY; 797 }, 798 799 /** 800 * Returns device pixel ratio for retina display. 801 * @return {Number} 802 */ 803 getDevicePixelRatio: function() { 804 return this._devicePixelRatio; 805 }, 806 807 /** 808 * Returns the real location in view for a translation based on a related position 809 * @param {Number} tx The X axis translation 810 * @param {Number} ty The Y axis translation 811 * @param {Object} relatedPos The related position object including "left", "top", "width", "height" informations 812 * @return {cc.Point} 813 */ 814 convertToLocationInView: function (tx, ty, relatedPos) { 815 return {x: this._devicePixelRatio * (tx - relatedPos.left), y: this._devicePixelRatio * (relatedPos.top + relatedPos.height - ty)}; 816 }, 817 818 _convertMouseToLocationInView: function(point, relatedPos) { 819 var locViewPortRect = this._viewPortRect, _t = this; 820 point.x = ((_t._devicePixelRatio * (point.x - relatedPos.left)) - locViewPortRect.x) / _t._scaleX; 821 point.y = (_t._devicePixelRatio * (relatedPos.top + relatedPos.height - point.y) - locViewPortRect.y) / _t._scaleY; 822 }, 823 824 _convertTouchesWithScale: function(touches){ 825 var locViewPortRect = this._viewPortRect, locScaleX = this._scaleX, locScaleY = this._scaleY, selTouch, selPoint, selPrePoint; 826 for( var i = 0; i < touches.length; i ++){ 827 selTouch = touches[i]; 828 selPoint = selTouch._point; 829 selPrePoint = selTouch._prevPoint; 830 selTouch._setPoint((selPoint.x - locViewPortRect.x) / locScaleX, 831 (selPoint.y - locViewPortRect.y) / locScaleY); 832 selTouch._setPrevPoint((selPrePoint.x - locViewPortRect.x) / locScaleX, 833 (selPrePoint.y - locViewPortRect.y) / locScaleY); 834 } 835 } 836 }); 837 838 /** 839 * @function 840 * @return {cc.EGLView} 841 * @private 842 */ 843 cc.EGLView._getInstance = function () { 844 if (!this._instance) { 845 this._instance = this._instance || new cc.EGLView(); 846 this._instance.initialize(); 847 } 848 return this._instance; 849 }; 850 851 /** 852 * <p>cc.ContainerStrategy class is the root strategy class of container's scale strategy, 853 * it controls the behavior of how to scale the cc.container and cc._canvas object</p> 854 * 855 * @class 856 * @extends cc.Class 857 */ 858 cc.ContainerStrategy = cc.Class.extend(/** @lends cc.ContainerStrategy# */{ 859 /** 860 * Manipulation before appling the strategy 861 * @param {cc.view} The target view 862 */ 863 preApply: function (view) { 864 }, 865 866 /** 867 * Function to apply this strategy 868 * @param {cc.view} view 869 * @param {cc.Size} designedResolution 870 */ 871 apply: function (view, designedResolution) { 872 }, 873 874 /** 875 * Manipulation after applying the strategy 876 * @param {cc.view} view The target view 877 */ 878 postApply: function (view) { 879 880 }, 881 882 _setupContainer: function (view, w, h) { 883 var frame = view._frame; 884 if (cc.view._autoFullScreen && cc.sys.isMobile && frame === document.documentElement) { 885 // Automatically full screen when user touches on mobile version 886 cc.screen.autoFullScreen(frame); 887 } 888 889 var locCanvasElement = cc._canvas, locContainer = cc.container; 890 // Setup container 891 locContainer.style.width = locCanvasElement.style.width = w + "px"; 892 locContainer.style.height = locCanvasElement.style.height = h + "px"; 893 // Setup pixel ratio for retina display 894 var devicePixelRatio = view._devicePixelRatio = 1; 895 if (view.isRetinaEnabled()) 896 devicePixelRatio = view._devicePixelRatio = window.devicePixelRatio || 1; 897 // Setup canvas 898 locCanvasElement.width = w * devicePixelRatio; 899 locCanvasElement.height = h * devicePixelRatio; 900 cc._renderContext.resetCache && cc._renderContext.resetCache(); 901 902 var body = document.body, style; 903 if (body && (style = body.style)) { 904 style.paddingTop = style.paddingTop || "0px"; 905 style.paddingRight = style.paddingRight || "0px"; 906 style.paddingBottom = style.paddingBottom || "0px"; 907 style.paddingLeft = style.paddingLeft || "0px"; 908 style.borderTop = style.borderTop || "0px"; 909 style.borderRight = style.borderRight || "0px"; 910 style.borderBottom = style.borderBottom || "0px"; 911 style.borderLeft = style.borderLeft || "0px"; 912 style.marginTop = style.marginTop || "0px"; 913 style.marginRight = style.marginRight || "0px"; 914 style.marginBottom = style.marginBottom || "0px"; 915 style.marginLeft = style.marginLeft || "0px"; 916 } 917 }, 918 919 _fixContainer: function () { 920 // Add container to document body 921 document.body.insertBefore(cc.container, document.body.firstChild); 922 // Set body's width height to window's size, and forbid overflow, so that game will be centered 923 var bs = document.body.style; 924 bs.width = window.innerWidth + "px"; 925 bs.height = window.innerHeight + "px"; 926 bs.overflow = "hidden"; 927 // Body size solution doesn't work on all mobile browser so this is the aleternative: fixed container 928 var contStyle = cc.container.style; 929 contStyle.position = "fixed"; 930 contStyle.left = contStyle.top = "0px"; 931 // Reposition body 932 document.body.scrollTop = 0; 933 } 934 }); 935 936 /** 937 * <p>cc.ContentStrategy class is the root strategy class of content's scale strategy, 938 * it controls the behavior of how to scale the scene and setup the viewport for the game</p> 939 * 940 * @class 941 * @extends cc.Class 942 */ 943 cc.ContentStrategy = cc.Class.extend(/** @lends cc.ContentStrategy# */{ 944 945 _result: { 946 scale: [1, 1], 947 viewport: null 948 }, 949 950 _buildResult: function (containerW, containerH, contentW, contentH, scaleX, scaleY) { 951 // Makes content fit better the canvas 952 Math.abs(containerW - contentW) < 2 && (contentW = containerW); 953 Math.abs(containerH - contentH) < 2 && (contentH = containerH); 954 955 var viewport = cc.rect(Math.round((containerW - contentW) / 2), 956 Math.round((containerH - contentH) / 2), 957 contentW, contentH); 958 959 // Translate the content 960 if (cc._renderType === cc.game.RENDER_TYPE_CANVAS){ 961 //TODO: modify something for setTransform 962 //cc._renderContext.translate(viewport.x, viewport.y + contentH); 963 } 964 965 this._result.scale = [scaleX, scaleY]; 966 this._result.viewport = viewport; 967 return this._result; 968 }, 969 970 /** 971 * Manipulation before applying the strategy 972 * @param {cc.view} view The target view 973 */ 974 preApply: function (view) { 975 }, 976 977 /** 978 * Function to apply this strategy 979 * The return value is {scale: [scaleX, scaleY], viewport: {cc.Rect}}, 980 * The target view can then apply these value to itself, it's preferred not to modify directly its private variables 981 * @param {cc.view} view 982 * @param {cc.Size} designedResolution 983 * @return {object} scaleAndViewportRect 984 */ 985 apply: function (view, designedResolution) { 986 return {"scale": [1, 1]}; 987 }, 988 989 /** 990 * Manipulation after applying the strategy 991 * @param {cc.view} view The target view 992 */ 993 postApply: function (view) { 994 } 995 }); 996 997 (function () { 998 999 // Container scale strategys 1000 /** 1001 * @class 1002 * @extends cc.ContainerStrategy 1003 */ 1004 var EqualToFrame = cc.ContainerStrategy.extend({ 1005 apply: function (view) { 1006 this._setupContainer(view, view._frameSize.width, view._frameSize.height); 1007 } 1008 }); 1009 1010 /** 1011 * @class 1012 * @extends cc.ContainerStrategy 1013 */ 1014 var ProportionalToFrame = cc.ContainerStrategy.extend({ 1015 apply: function (view, designedResolution) { 1016 var frameW = view._frameSize.width, frameH = view._frameSize.height, containerStyle = cc.container.style, 1017 designW = designedResolution.width, designH = designedResolution.height, 1018 scaleX = frameW / designW, scaleY = frameH / designH, 1019 containerW, containerH; 1020 1021 scaleX < scaleY ? (containerW = frameW, containerH = designH * scaleX) : (containerW = designW * scaleY, containerH = frameH); 1022 1023 // Adjust container size with integer value 1024 var offx = Math.round((frameW - containerW) / 2); 1025 var offy = Math.round((frameH - containerH) / 2); 1026 containerW = frameW - 2 * offx; 1027 containerH = frameH - 2 * offy; 1028 1029 this._setupContainer(view, containerW, containerH); 1030 // Setup container's margin 1031 containerStyle.marginLeft = offx + "px"; 1032 containerStyle.marginRight = offx + "px"; 1033 containerStyle.marginTop = offy + "px"; 1034 containerStyle.marginBottom = offy + "px"; 1035 } 1036 }); 1037 1038 /** 1039 * @class 1040 * @extends EqualToFrame 1041 */ 1042 var EqualToWindow = EqualToFrame.extend({ 1043 preApply: function (view) { 1044 this._super(view); 1045 view._frame = document.documentElement; 1046 }, 1047 1048 apply: function (view) { 1049 this._super(view); 1050 this._fixContainer(); 1051 } 1052 }); 1053 1054 /** 1055 * @class 1056 * @extends ProportionalToFrame 1057 */ 1058 var ProportionalToWindow = ProportionalToFrame.extend({ 1059 preApply: function (view) { 1060 this._super(view); 1061 view._frame = document.documentElement; 1062 }, 1063 1064 apply: function (view, designedResolution) { 1065 this._super(view, designedResolution); 1066 this._fixContainer(); 1067 } 1068 }); 1069 1070 /** 1071 * @class 1072 * @extends cc.ContainerStrategy 1073 */ 1074 var OriginalContainer = cc.ContainerStrategy.extend({ 1075 apply: function (view) { 1076 this._setupContainer(view, cc._canvas.width, cc._canvas.height); 1077 } 1078 }); 1079 1080 // #NOT STABLE on Android# Alias: Strategy that makes the container's size equals to the window's size 1081 // cc.ContainerStrategy.EQUAL_TO_WINDOW = new EqualToWindow(); 1082 // #NOT STABLE on Android# Alias: Strategy that scale proportionally the container's size to window's size 1083 // cc.ContainerStrategy.PROPORTION_TO_WINDOW = new ProportionalToWindow(); 1084 // Alias: Strategy that makes the container's size equals to the frame's size 1085 cc.ContainerStrategy.EQUAL_TO_FRAME = new EqualToFrame(); 1086 // Alias: Strategy that scale proportionally the container's size to frame's size 1087 cc.ContainerStrategy.PROPORTION_TO_FRAME = new ProportionalToFrame(); 1088 // Alias: Strategy that keeps the original container's size 1089 cc.ContainerStrategy.ORIGINAL_CONTAINER = new OriginalContainer(); 1090 1091 // Content scale strategys 1092 var ExactFit = cc.ContentStrategy.extend({ 1093 apply: function (view, designedResolution) { 1094 var containerW = cc._canvas.width, containerH = cc._canvas.height, 1095 scaleX = containerW / designedResolution.width, scaleY = containerH / designedResolution.height; 1096 1097 return this._buildResult(containerW, containerH, containerW, containerH, scaleX, scaleY); 1098 } 1099 }); 1100 1101 var ShowAll = cc.ContentStrategy.extend({ 1102 apply: function (view, designedResolution) { 1103 var containerW = cc._canvas.width, containerH = cc._canvas.height, 1104 designW = designedResolution.width, designH = designedResolution.height, 1105 scaleX = containerW / designW, scaleY = containerH / designH, scale = 0, 1106 contentW, contentH; 1107 1108 scaleX < scaleY ? (scale = scaleX, contentW = containerW, contentH = designH * scale) 1109 : (scale = scaleY, contentW = designW * scale, contentH = containerH); 1110 1111 return this._buildResult(containerW, containerH, contentW, contentH, scale, scale); 1112 } 1113 }); 1114 1115 var NoBorder = cc.ContentStrategy.extend({ 1116 apply: function (view, designedResolution) { 1117 var containerW = cc._canvas.width, containerH = cc._canvas.height, 1118 designW = designedResolution.width, designH = designedResolution.height, 1119 scaleX = containerW / designW, scaleY = containerH / designH, scale, 1120 contentW, contentH; 1121 1122 scaleX < scaleY ? (scale = scaleY, contentW = designW * scale, contentH = containerH) 1123 : (scale = scaleX, contentW = containerW, contentH = designH * scale); 1124 1125 return this._buildResult(containerW, containerH, contentW, contentH, scale, scale); 1126 } 1127 }); 1128 1129 var FixedHeight = cc.ContentStrategy.extend({ 1130 apply: function (view, designedResolution) { 1131 var containerW = cc._canvas.width, containerH = cc._canvas.height, 1132 designH = designedResolution.height, scale = containerH / designH, 1133 contentW = containerW, contentH = containerH; 1134 1135 return this._buildResult(containerW, containerH, contentW, contentH, scale, scale); 1136 }, 1137 1138 postApply: function (view) { 1139 cc.director._winSizeInPoints = view.getVisibleSize(); 1140 } 1141 }); 1142 1143 var FixedWidth = cc.ContentStrategy.extend({ 1144 apply: function (view, designedResolution) { 1145 var containerW = cc._canvas.width, containerH = cc._canvas.height, 1146 designW = designedResolution.width, scale = containerW / designW, 1147 contentW = containerW, contentH = containerH; 1148 1149 return this._buildResult(containerW, containerH, contentW, contentH, scale, scale); 1150 }, 1151 1152 postApply: function (view) { 1153 cc.director._winSizeInPoints = view.getVisibleSize(); 1154 } 1155 }); 1156 1157 // Alias: Strategy to scale the content's size to container's size, non proportional 1158 cc.ContentStrategy.EXACT_FIT = new ExactFit(); 1159 // Alias: Strategy to scale the content's size proportionally to maximum size and keeps the whole content area to be visible 1160 cc.ContentStrategy.SHOW_ALL = new ShowAll(); 1161 // Alias: Strategy to scale the content's size proportionally to fill the whole container area 1162 cc.ContentStrategy.NO_BORDER = new NoBorder(); 1163 // Alias: Strategy to scale the content's height to container's height and proportionally scale its width 1164 cc.ContentStrategy.FIXED_HEIGHT = new FixedHeight(); 1165 // Alias: Strategy to scale the content's width to container's width and proportionally scale its height 1166 cc.ContentStrategy.FIXED_WIDTH = new FixedWidth(); 1167 1168 })(); 1169 1170 /** 1171 * <p>cc.ResolutionPolicy class is the root strategy class of scale strategy, 1172 * its main task is to maintain the compatibility with Cocos2d-x</p> 1173 * 1174 * @class 1175 * @extends cc.Class 1176 * @param {cc.ContainerStrategy} containerStg The container strategy 1177 * @param {cc.ContentStrategy} contentStg The content strategy 1178 */ 1179 cc.ResolutionPolicy = cc.Class.extend(/** @lends cc.ResolutionPolicy# */{ 1180 _containerStrategy: null, 1181 _contentStrategy: null, 1182 1183 /** 1184 * Constructor of cc.ResolutionPolicy 1185 * @param {cc.ContainerStrategy} containerStg 1186 * @param {cc.ContentStrategy} contentStg 1187 */ 1188 ctor: function (containerStg, contentStg) { 1189 this.setContainerStrategy(containerStg); 1190 this.setContentStrategy(contentStg); 1191 }, 1192 1193 /** 1194 * Manipulation before applying the resolution policy 1195 * @param {cc.view} view The target view 1196 */ 1197 preApply: function (view) { 1198 this._containerStrategy.preApply(view); 1199 this._contentStrategy.preApply(view); 1200 }, 1201 1202 /** 1203 * Function to apply this resolution policy 1204 * The return value is {scale: [scaleX, scaleY], viewport: {cc.Rect}}, 1205 * The target view can then apply these value to itself, it's preferred not to modify directly its private variables 1206 * @param {cc.view} view The target view 1207 * @param {cc.Size} designedResolution The user defined design resolution 1208 * @return {object} An object contains the scale X/Y values and the viewport rect 1209 */ 1210 apply: function (view, designedResolution) { 1211 this._containerStrategy.apply(view, designedResolution); 1212 return this._contentStrategy.apply(view, designedResolution); 1213 }, 1214 1215 /** 1216 * Manipulation after appyling the strategy 1217 * @param {cc.view} view The target view 1218 */ 1219 postApply: function (view) { 1220 this._containerStrategy.postApply(view); 1221 this._contentStrategy.postApply(view); 1222 }, 1223 1224 /** 1225 * Setup the container's scale strategy 1226 * @param {cc.ContainerStrategy} containerStg 1227 */ 1228 setContainerStrategy: function (containerStg) { 1229 if (containerStg instanceof cc.ContainerStrategy) 1230 this._containerStrategy = containerStg; 1231 }, 1232 1233 /** 1234 * Setup the content's scale strategy 1235 * @param {cc.ContentStrategy} contentStg 1236 */ 1237 setContentStrategy: function (contentStg) { 1238 if (contentStg instanceof cc.ContentStrategy) 1239 this._contentStrategy = contentStg; 1240 } 1241 }); 1242 1243 /** 1244 * @memberOf cc.ResolutionPolicy# 1245 * @name EXACT_FIT 1246 * @constant 1247 * @type Number 1248 * @static 1249 * The entire application is visible in the specified area without trying to preserve the original aspect ratio.<br/> 1250 * Distortion can occur, and the application may appear stretched or compressed. 1251 */ 1252 cc.ResolutionPolicy.EXACT_FIT = 0; 1253 1254 /** 1255 * @memberOf cc.ResolutionPolicy# 1256 * @name NO_BORDER 1257 * @constant 1258 * @type Number 1259 * @static 1260 * The entire application fills the specified area, without distortion but possibly with some cropping,<br/> 1261 * while maintaining the original aspect ratio of the application. 1262 */ 1263 cc.ResolutionPolicy.NO_BORDER = 1; 1264 1265 /** 1266 * @memberOf cc.ResolutionPolicy# 1267 * @name SHOW_ALL 1268 * @constant 1269 * @type Number 1270 * @static 1271 * The entire application is visible in the specified area without distortion while maintaining the original<br/> 1272 * aspect ratio of the application. Borders can appear on two sides of the application. 1273 */ 1274 cc.ResolutionPolicy.SHOW_ALL = 2; 1275 1276 /** 1277 * @memberOf cc.ResolutionPolicy# 1278 * @name FIXED_HEIGHT 1279 * @constant 1280 * @type Number 1281 * @static 1282 * The application takes the height of the design resolution size and modifies the width of the internal<br/> 1283 * canvas so that it fits the aspect ratio of the device<br/> 1284 * no distortion will occur however you must make sure your application works on different<br/> 1285 * aspect ratios 1286 */ 1287 cc.ResolutionPolicy.FIXED_HEIGHT = 3; 1288 1289 /** 1290 * @memberOf cc.ResolutionPolicy# 1291 * @name FIXED_WIDTH 1292 * @constant 1293 * @type Number 1294 * @static 1295 * The application takes the width of the design resolution size and modifies the height of the internal<br/> 1296 * canvas so that it fits the aspect ratio of the device<br/> 1297 * no distortion will occur however you must make sure your application works on different<br/> 1298 * aspect ratios 1299 */ 1300 cc.ResolutionPolicy.FIXED_WIDTH = 4; 1301 1302 /** 1303 * @memberOf cc.ResolutionPolicy# 1304 * @name UNKNOWN 1305 * @constant 1306 * @type Number 1307 * @static 1308 * Unknow policy 1309 */ 1310 cc.ResolutionPolicy.UNKNOWN = 5; 1311