添加一个介绍常驻节点使用的demo

This commit is contained in:
leo
2018-07-17 18:54:09 +08:00
parent b7799a0c42
commit 8b68c7c6a4
25 changed files with 21856 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
cc.Class({
extends: cc.Component,
properties: {
label: {
default: null,
type: cc.Label
},
// defaults, set visually when attaching this script to the Canvas
text: 'Hello, World!'
},
// use this for initialization
onLoad: function () {
this.label.string = this.text;
},
/**
*
*/
onBtn: function () {
cc.director.loadScene('Test');
},
// called every frame
update: function (dt) {
},
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "280c3aec-6492-4a9d-9f51-a9b00b570b4a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@@ -0,0 +1,31 @@
cc.Class({
extends: cc.Component,
properties: {
nodeCocos: cc.Node
},
onLoad() {
this.setPersistRootNode(this.nodeCocos);
},
/**
* 设置为常驻节点
* @param {*} node
*/
setPersistRootNode(node) {
cc.game.addPersistRootNode(node)
},
/**
* 取消常驻根节点,但是不会马上消失。只是将节点还原为可在场景切换时销毁的节点
* @param {*} node
*/
removePersistRootNode(node) {
if (cc.game.isPersistRootNode(node)) {
cc.game.removePersistRootNode(node);
}
},
});

View File

@@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "ebd10890-99b4-4a0e-9616-f15ce918df2a",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}