1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 
 25 /**
 26  * Base class for ccs.ComRender
 27  * @class
 28  * @extends ccs.Component
 29  */
 30 ccs.ComRender = ccs.Component.extend(/** @lends ccs.ComRender# */{
 31     _render: null,
 32     ctor: function (node, comName) {
 33         cc.Component.prototype.ctor.call(this);
 34         this._render = node;
 35         this._name = comName;
 36     },
 37 
 38     onEnter: function () {
 39         if (this._owner != null) {
 40             this._owner.addChild(this._render);
 41         }
 42     },
 43 
 44     onExit: function () {
 45         this._render = null;
 46     },
 47 
 48     /**
 49      * Node getter
 50      * @returns {cc.Node}
 51      */
 52     getNode: function () {
 53         return this._render;
 54     },
 55 
 56     /**
 57      * Node setter
 58      * @param {cc.Node} node
 59      */
 60     setNode: function (node) {
 61         this._render = node;
 62     }
 63 });
 64 /**
 65  * allocates and initializes a ComRender.
 66  * @constructs
 67  * @return {ccs.ComRender}
 68  * @example
 69  * // example
 70  * var com = ccs.ComRender.create();
 71  */
 72 ccs.ComRender.create = function (node, comName) {
 73     var com = new ccs.ComRender(node, comName);
 74     if (com && com.init()) {
 75         return com;
 76     }
 77     return null;
 78 };
 79