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         ccs.ComRender.prototype.init.call(this);
 44     },
 45 
 46     /**
 47      * The callback calls when a render component enter stage.
 48      */
 49     onEnter: function () {
 50         if (this._owner)
 51             this._owner.addChild(this._render);
 52     },
 53 
 54     /**
 55      * The callback calls when a render component exit stage.
 56      */
 57     onExit: function () {
 58         if (this._owner) {
 59             this._owner.removeChild(this._render, true);
 60             this._render = null;
 61         }
 62     },
 63 
 64     /**
 65      * Returns a render node
 66      * @returns {cc.Node}
 67      */
 68     getNode: function () {
 69         return this._render;
 70     },
 71 
 72     /**
 73      * Sets a render node to component.
 74      * @param {cc.Node} node
 75      */
 76     setNode: function (node) {
 77         this._render = node;
 78     }
 79 });
 80 
 81 /**
 82  * allocates and initializes a ComRender.
 83  * @deprecated since v3.0, please use new construction instead.
 84  * @return {ccs.ComRender}
 85  * @example
 86  * // example
 87  * var com = ccs.ComRender.create();
 88  */
 89 ccs.ComRender.create = function (node, comName) {
 90     return new ccs.ComRender(node, comName);
 91 };
 92