Cocos Creator 生命周期回调(官方文档摘录)
发布时间:2020-12-14 17:15:49  所属栏目:百科  来源:网络整理 
            导读:Cocos Creator 为组件脚本提供了生命周期的回调函数。用户通过定义特定的函数回调在特定的时期编写相关 脚本。目前提供给用户的声明周期回调函数有: onLoad start update lateUpdate onDestroy onEnable onDisable onLoad 组件脚本的初始化阶段 ,我们提供
                
                
                
            | Cocos Creator 为组件脚本提供了生命周期的回调函数。用户通过定义特定的函数回调在特定的时期编写相关 脚本。目前提供给用户的声明周期回调函数有: 
 onLoad组件脚本的初始化阶段,我们提供了 cc.Class({
  extends: cc.Component,properties: {
    bulletSprite: cc.SpriteFrame,gun: cc.Node,},onLoad: function () {
    this._bulletRect = this.bulletSprite.getRect();
    this.gun = cc.find('hand/weapon',this.node);
  },});startupdate回调中。this.node.setPosition( 0.0,40.0 * dt );
  }
});lateUpdateupdate会在所有动画更新前执行,但如果我们要在动画更新之后才进行一些额外操作,或者希望在所有组件的enabled属性从false变为true时,会激活onEnable回调。倘若节点第一次被 创建且enabled为true,则会在onLoad之后,start之前被调用。onDisabletrue变为destroy(),会在该帧结束被统一回收,此时会调用onDestroy回调。 | 
