COCOS2D-HTML5 Layer and Scene creation mode

Source: Internet
Author: User

?
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 ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.