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 base class of component in CocoStudio 28 * @class 29 * @extends cc.Class 30 */ 31 cc.Component = cc.Class.extend(/** @lends cc.Component# */{ 32 _owner: null, 33 _name: "", 34 _enabled: true, 35 36 /** 37 * Construction of cc.Component 38 */ 39 ctor:function(){ 40 this._owner = null; 41 this._name = ""; 42 this._enabled = true; 43 }, 44 45 /** 46 * Initializes a cc.Component. 47 * @returns {boolean} 48 */ 49 init:function(){ 50 return true; 51 }, 52 53 /** 54 * The callback when a component enter stage. 55 */ 56 onEnter:function(){ 57 }, 58 59 /** 60 * The callback when a component exit stage. 61 */ 62 onExit:function(){ 63 }, 64 65 /** 66 * The callback per every frame if it schedules update. 67 * @param delta 68 */ 69 update:function(delta){ 70 }, 71 72 /** 73 * Serialize a component object. 74 * @param reader 75 */ 76 serialize:function( reader){ 77 }, 78 79 /** 80 * Returns component whether is enabled. 81 * @returns {boolean} 82 */ 83 isEnabled:function(){ 84 return this._enabled; 85 }, 86 87 /** 88 * Sets component whether is enabled. 89 * @param enable 90 */ 91 setEnabled:function(enable){ 92 this._enabled = enable; 93 }, 94 95 /** 96 * Returns the name of cc.Component. 97 * @returns {string} 98 */ 99 getName:function(){ 100 return this._name; 101 } , 102 103 /** 104 * Sets the name to cc.Component. 105 * @param {String} name 106 */ 107 setName:function(name){ 108 this._name = name; 109 } , 110 111 /** 112 * Sets the owner to cc.Component. 113 * @param owner 114 */ 115 setOwner:function(owner){ 116 this._owner = owner; 117 }, 118 119 /** 120 * Returns the owner of cc.Component. 121 * @returns {*} 122 */ 123 getOwner:function(){ 124 return this._owner; 125 } 126 }); 127 128 /** 129 * Allocates and initializes a component. 130 * @deprecated since v3.0, please use new construction instead. 131 * @return {cc.Component} 132 */ 133 cc.Component.create = function(){ 134 return new cc.Component(); 135 }; 136 137