?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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); } }); |
Stage layer Various usage:-----Best can analyze the source of the layer ...
1. General statements
var Helloworld = cc. Layer.extend ({
if (This._super ()) {return true;}
return false;
}); ----seldom used
22 Types of object creation
1) var pLayer = new Mylayer ();
Player.init ();----do not perform the ctor construction method and manually trigger the Init method.
2)
var layer = Mylayer (). Create ();
3. Automatic call execution method------> Rewrite the method inside the parent class, and call This._super ();
Ctor:init:onEnter:onExit:
Ctor:init:onEnter: creating a simple UI interface
OnExit: Releasing some resources
Such as:
Init:function () {
This._super ();
}