어떻게 CocosCreator 에서 상주 노드 를 이용 하여 그래 픽 관 리 를 합 니까?
일반 게임 은 모두 그래 픽 관리 가 있다.예 를 들 어
불 러 오 는 장면 은 cc.director.loadScene 을 사용 합 니 다.scene 의 용기 node 는 director 의 nodeActivator 인 것 같 습 니 다.

지금 은 scene 의 용기 나 cocos 의 꼭대기 용 기 를 고려 하지 않 는 다 면.두 가지 도면 관리 방법 을 생각해 보 겠 습 니 다.
하나,오직 하나의 scene
전체 게임 의 한 scene 은 바로 게임 입구 의 scene 입 니 다.이 scene 에 scene Layer 등 그림 층 의 node 를 놓 습 니 다.이 입구 scene 은 egret 과 laya 의 stage 에 해당 합 니 다.
그 다음 에 모든 장면 scene 과 탄 상자 모듈 은 프 리 패 브 를 만 들 고 매번 에 addChild 를 입구 scene 의 해당 그림 층 에 표시 하면 됩 니 다.

2.상주 노드 사용
예 를 들 어 나 는 장면 1,sceneLayer 등 그림 층 을 설치한다.표시 하기 편 하도록 나 는 각 그림 층 에 단색 을 넣 었 다.

상주 노드 는 반드시 루트 노드 아래,즉 canvas 와 동급 이 어야 한다.3 개의 그림 층 을 상주 노드 로 설정 합 니 다.
onLoad(){
cc.game.addPersistRootNode(cc.find("sceneLayer"));
cc.game.addPersistRootNode(cc.find("panelLayer"));
cc.game.addPersistRootNode(cc.find("tipLayer"));
}
그리고 장면 을 전환 하면 새로운 장면 에서 sceneLayer 등 그림 을 표시 하고 가 져 올 수 있 습 니 다.
onLoad(){
console.log(cc.find("sceneLayer")); // sceneLayer cc.Node
}
상주 노드 를 이용 하여 우 리 는 입구 장면 에 sceneLayer 등 그림 층 을 배치 할 수 있다.인용 을 그림 관리 클래스 로 저장 합 니 다.3.최고의 실천
그래 픽 관리 클래스
export default class LayerManager extends cc.Component {
private static instance:LayerManager;
public static ins():LayerManager{
if(this.instance == null){
this.instance = new LayerManager();
}
return this.instance;
}
public panelLayer:cc.Node;
public tipLayer:cc.Node;
}
입구 필드 에 상주 노드 layer 를 설정 하고, 인용 을 그림 관리 클래스 로 저장 합 니 다.나중에 사용 할 수 있 도록.
@ccclass
export default class Helloworld extends cc.Component {
onLoad(){
cc.game.addPersistRootNode(cc.find("sceneLayer"));
cc.game.addPersistRootNode(cc.find("panelLayer"));
cc.game.addPersistRootNode(cc.find("tipLayer"));
LayerManager.ins().panelLayer = cc.find("panelLayer");
LayerManager.ins().tipLayer = cc.find("tipLayer");
}
}
이상 은 CocosCreator 에서 상주 노드 를 이용 하여 도면 관 리 를 하 는 방법 에 대한 상세 한 내용 입 니 다.CocosCreator 상주 노드 에 대해 도면 관 리 를 하 는 자 료 는 저희 의 다른 관련 글 을 주목 해 주 십시오!