CCVisibleRect.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /****************************************************************************
  2. Copyright (c) 2011-2012 cocos2d-x.org
  3. Copyright (c) 2013-2014 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. /**
  22. * cc.visibleRect is a singleton object which defines the actual visible rect of the current view,
  23. * it should represent the same rect as cc.view.getViewportRect()
  24. *
  25. * @property {cc.Point} topLeft - Top left coordinate of the screen related to the game scene
  26. * @property {cc.Point} topRight - Top right coordinate of the screen related to the game scene
  27. * @property {cc.Point} top - Top center coordinate of the screen related to the game scene
  28. * @property {cc.Point} bottomLeft - Bottom left coordinate of the screen related to the game scene
  29. * @property {cc.Point} bottomRight - Bottom right coordinate of the screen related to the game scene
  30. * @property {cc.Point} bottom - Bottom center coordinate of the screen related to the game scene
  31. * @property {cc.Point} center - Center coordinate of the screen related to the game scene
  32. * @property {cc.Point} left - Left center coordinate of the screen related to the game scene
  33. * @property {cc.Point} right - Right center coordinate of the screen related to the game scene
  34. * @property {Number} width - Width of the screen
  35. * @property {Number} height - Height of the screen
  36. *
  37. * @class
  38. * @name cc.visibleRect
  39. */
  40. cc.visibleRect = {
  41. topLeft:cc.p(0,0),
  42. topRight:cc.p(0,0),
  43. top:cc.p(0,0),
  44. bottomLeft:cc.p(0,0),
  45. bottomRight:cc.p(0,0),
  46. bottom:cc.p(0,0),
  47. center:cc.p(0,0),
  48. left:cc.p(0,0),
  49. right:cc.p(0,0),
  50. width:0,
  51. height:0,
  52. /**
  53. * initialize
  54. * @param {cc.Rect} visibleRect
  55. */
  56. init:function(visibleRect){
  57. var w = this.width = visibleRect.width;
  58. var h = this.height = visibleRect.height;
  59. var l = visibleRect.x,
  60. b = visibleRect.y,
  61. t = b + h,
  62. r = l + w;
  63. //top
  64. this.topLeft.x = l;
  65. this.topLeft.y = t;
  66. this.topRight.x = r;
  67. this.topRight.y = t;
  68. this.top.x = l + w/2;
  69. this.top.y = t;
  70. //bottom
  71. this.bottomLeft.x = l;
  72. this.bottomLeft.y = b;
  73. this.bottomRight.x = r;
  74. this.bottomRight.y = b;
  75. this.bottom.x = l + w/2;
  76. this.bottom.y = b;
  77. //center
  78. this.center.x = l + w/2;
  79. this.center.y = b + h/2;
  80. //left
  81. this.left.x = l;
  82. this.left.y = b + h/2;
  83. //right
  84. this.right.x = r;
  85. this.right.y = b + h/2;
  86. }
  87. };