cc.mySence = {
//主场景
hall:null,
//加载界面主场景
homeSence:null,
//返回场景队列
gobackList:[],
//当前场景
currentScene:null,
//加载Prefab场景
loadScene:function (url) {
if (cc.myApi.currentScene) {
cc.myApi.currentScene.destroy();
}
cc.loader.loadRes(url, cc.Prefab, function (err, prefab) {
if (err !== null) {
cc.error(err);
return
}
var node = cc.instantiate(prefab);
var base = { file : url };
node.attr(base);
node.parent = cc.director.getScene();;
node.setPosition(0,0);
cc.myApi.currentScene = node;
cc.myApi.gobackList.push(url);
});
},
//返回上一个Prefab场景
backSence:function () {
var last = cc.myApi.gobackList.pop();
cc.myApi.loadScene(cc.myApi.gobackList.pop());
},
//创建Prefab
showModal: function (url, cb) {
cc.loader.loadRes(url, cc.Prefab, function (err, prefab) {
if (err !== null) {
cc.error(err);
return
}
let windowSize = cc.winSize;
var scene = cc.director.getScene();
var node = cc.instantiate(prefab);
var base = { file : url };
node.attr(base);
node.parent = scene;
node.setPosition(windowSize.width/2,windowSize.height/2);
if (!!cb) {
cb(node);
}
});
},
//删除Prefab
close: function (file) {
var scene = cc.director.getScene();
var children = scene.children;
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child.file !== null && child.file === file) {
//child.parent = null;
child.destroy();
return;
}
}
cc.error("close prefab failed:" + file);
},
}
网友评论