cocos2d-html5 Layer 和 Scene 创建模式

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);
    }
});

舞台 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();

}

posted @   porter_代码工作者  阅读(552)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示