1 /**************************************************************************** 2 Copyright (c) 2011-2012 cocos2d-x.org 3 Copyright (c) 2013-2014 Chukong Technologies Inc. 4 5 http://www.cocos2d-x.org 6 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 * cc.visibleRect is a singleton object which defines the actual visible rect of the current view, 29 * it should represent the same rect as cc.view.getViewportRect() 30 * 31 * @property {cc.Point} topLeft - Top left coordinate of the screen related to the game scene 32 * @property {cc.Point} topRight - Top right coordinate of the screen related to the game scene 33 * @property {cc.Point} top - Top center coordinate of the screen related to the game scene 34 * @property {cc.Point} bottomLeft - Bottom left coordinate of the screen related to the game scene 35 * @property {cc.Point} bottomRight - Bottom right coordinate of the screen related to the game scene 36 * @property {cc.Point} bottom - Bottom center coordinate of the screen related to the game scene 37 * @property {cc.Point} center - Center coordinate of the screen related to the game scene 38 * @property {cc.Point} left - Left center coordinate of the screen related to the game scene 39 * @property {cc.Point} right - Right center coordinate of the screen related to the game scene 40 * @property {Number} width - Width of the screen 41 * @property {Number} height - Height of the screen 42 * 43 * @class 44 * @name cc.visibleRect 45 */ 46 cc.visibleRect = { 47 topLeft:cc.p(0,0), 48 topRight:cc.p(0,0), 49 top:cc.p(0,0), 50 bottomLeft:cc.p(0,0), 51 bottomRight:cc.p(0,0), 52 bottom:cc.p(0,0), 53 center:cc.p(0,0), 54 left:cc.p(0,0), 55 right:cc.p(0,0), 56 width:0, 57 height:0, 58 59 /** 60 * initialize 61 * @param {cc.Rect} visibleRect 62 */ 63 init:function(visibleRect){ 64 65 var w = this.width = visibleRect.width; 66 var h = this.height = visibleRect.height; 67 var l = visibleRect.x, 68 b = visibleRect.y, 69 t = b + h, 70 r = l + w; 71 72 //top 73 this.topLeft.x = l; 74 this.topLeft.y = t; 75 this.topRight.x = r; 76 this.topRight.y = t; 77 this.top.x = l + w/2; 78 this.top.y = t; 79 80 //bottom 81 this.bottomLeft.x = l; 82 this.bottomLeft.y = b; 83 this.bottomRight.x = r; 84 this.bottomRight.y = b; 85 this.bottom.x = l + w/2; 86 this.bottom.y = b; 87 88 //center 89 this.center.x = l + w/2; 90 this.center.y = b + h/2; 91 92 //left 93 this.left.x = l; 94 this.left.y = b + h/2; 95 96 //right 97 this.right.x = r; 98 this.right.y = b + h/2; 99 } 100 };