Cocos Creator 常用接口

不是很熟悉Cocos Creator引擎的接口,每次写都要来回来去的查,记下常用的,留着以后看。

//删除所有子节点
node.removeAllChildren(...);

//查找结点
cc.find("ConstantNode").getComponent("Network");

//获取子节点
node.getChildByName(...);

//获取组件
node.getComponent(cc.Label)

//初始化预制件
cc.instantiate(...);

//随机数
Math.random();

//过多长时间执行一次
this.scheduleOnce(function(){
    ...
},5);

//动态加载远程图片
loadImg: function(container,url){
    cc.loader.load(url, function (err, texture) {
        var sprite  = new cc.SpriteFrame(texture);
        container.spriteFrame = sprite;
    });
}

//引入常量类
var Common = require('Common');

//外部引用
module.exports = {
    USER_INFO : 1,//请求用户信息(头像与昵称)
    ...
};

//设为常驻结点
cc.game.addPersistRootNode(this.node);

//切换场景
cc.director.loadScene("...");

//获取场景名称
cc.director.getScene().getName();

//动态添加按钮监听事件
self.wx_btn.node.on(cc.Node.EventType.TOUCH_START, function (event) {
    console.log("TOUCH_START")
});

猜你喜欢

转载自blog.csdn.net/qq_27124771/article/details/81221809