var myLayer = cc.Layer.extend({ init:function() {//2 界面 var bRet = false; if (this._super()) { bRet = true; } return bRet; }, ctor:function(can){//1 初始全局 new Object(can); this._super(); }, onEnter:function(){//3 将要进入 this._super(); }, onExit:function(){//1000 释放 } }); myLayer.create = function() { var layer = new myLayer(); if (layer && layer.init()) { return layer; } return null; } //Scene var mydScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new myLayer(); layer.init(); this.addChild(layer); } });
舞台 Layer 各种用法:-----最好能分析Layer的源码...
1.一般语句
var Helloworld = cc.Layer.extend({
if(this._super()){ return true; }
return false;
}); ----很少用
2两种创建对象
1)var pLayer = new MyLayer();
pLayer.init();----不执行ctor构造方法,手工触发init方法。
2)
var layer = MyLayer().create();
3.自动调用执行方法------>重写父类里面的方法,并调用this._super();
ctor: init: onEnter: onExit:
ctor: init: onEnter: 创建简单的 UI界面
onExit: 释放一些资源
如:
init : function () {
this._super();
}