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  Permission is hereby granted, free of charge, to any person obtaining a copy
  8  of this software and associated documentation files (the "Software"), to deal
  9  in the Software without restriction, including without limitation the rights
 10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  copies of the Software, and to permit persons to whom the Software is
 12  furnished to do so, subject to the following conditions:
 13 
 14  The above copyright notice and this permission notice shall be included in
 15  all copies or substantial portions of the Software.
 16 
 17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  THE SOFTWARE.
 24  ****************************************************************************/
 25 
 26 /**
 27  * The render component for Cocostudio.
 28  * @class
 29  * @extends ccs.Component
 30  */
 31 ccs.ComRender = ccs.Component.extend(/** @lends ccs.ComRender# */{
 32     _render: null,
 33     /**
 34      * Construction of ccs.ComRender
 35      * @param {cc.Node} node
 36      * @param {String} comName
 37      */
 38     ctor: function (node, comName) {
 39         cc.Component.prototype.ctor.call(this);
 40         this._render = node;
 41         this._name = comName;
 42         this.isRenderer = true;
 43     },
 44 
 45     /**
 46      * The callback calls when a render component enter stage.
 47      */
 48     onEnter: function () {
 49         if (this._owner)
 50             this._owner.addChild(this._render);
 51     },
 52 
 53     /**
 54      * The callback calls when a render component exit stage.
 55      */
 56     onExit: function () {
 57         if (this._owner) {
 58             this._owner.removeChild(this._render, true);
 59             this._render = null;
 60         }
 61     },
 62 
 63     /**
 64      * Returns a render node
 65      * @returns {cc.Node}
 66      */
 67     getNode: function () {
 68         return this._render;
 69     },
 70 
 71     /**
 72      * Sets a render node to component.
 73      * @param {cc.Node} node
 74      */
 75     setNode: function (node) {
 76         this._render = node;
 77     }
 78 });
 79 
 80 /**
 81  * allocates and initializes a ComRender.
 82  * @deprecated since v3.0, please use new construction instead.
 83  * @return {ccs.ComRender}
 84  * @example
 85  * // example
 86  * var com = ccs.ComRender.create();
 87  */
 88 ccs.ComRender.create = function (node, comName) {
 89     var com = new ccs.ComRender(node, comName);
 90     if (com && com.init())
 91         return com;
 92     return null;
 93 };
 94