'cocos2d for android 예제분석/SceneTest.java 분석'에 해당되는 글 1건

  1. 2011.10.03 [예제분석] SceneTest.java (cocos2d 안드로이드강좌)


0.SceneTest에 나오는 내용들

1.scene 전환 방법
2.scene 전환 액션  


 
1. 예제 분석 목적
==> scene 전환방법의 기본을 알고 scene action의 원리를 알아본다.



2.전체적 개요

전체 3개의 scene을 구성하면 각 scene당 Layer1 ,Layer2, Layer3 이 할당된다.
Layer1_Scene에서 Layer2_Scene로 전환될때는 push를 사용하고 이때 화면전환은
단순장면 전환 및 scene_action전환을 이용한다. 
Layer2_Scene에서 Layer1_Scene로 전환은 push의 반대 개념은 pop를 이용한다.


Layer2_Scene에서 Layer3_Scene로 전환 될때는 replace를 사용하고 이때 화면전환은
단순장면 전환 및 scene_action전환을 이용한다.
Layer3_Scene에서 pop를 이용하면 Layer1_Scene로 이동한다. 

 

3-1. Layer1 클래스  분석

public Layer1() {

            CCMenuItemFont item1 = CCMenuItemFont.item("Test pushScene", this,                                                                                                          "onPushScene");

            CCMenuItemFont item2 = CCMenuItemFont.item("Test pushScene w/transition",                                                                                    this, "onPushSceneTran");

            CCMenuItemFont item3 = CCMenuItemFont.item("Quit", this, "onQuit");


            CCMenu menu = CCMenu.menu(item1, item2, item3);

            menu.alignItemsVertically();


            addChild(menu);

        }

        public void onPushScene(Object sender) {

            CCScene scene = CCScene.node();

            scene.addChild(new Layer2(), 0);

            CCDirector.sharedDirector().pushScene(scene);

        }

        public void onPushSceneTran(Object sender) {

            CCScene scene = CCScene.node();

            scene.addChild(new Layer2(), 0);

            CCDirector.sharedDirector().pushScene(
                                                 CCSlideInTTransition.transition(1, scene));

        }

        public void onQuit(Object sender) {

            CCDirector.sharedDirector().popScene();

        }


==>MenuItem으로 3가지 메뉴를 만들고 클릭 되었을때 실행될 콜백을 각각 지정한다.
     push에서 봤다 시피 Scene을 담는 통의 구조는 스택으로 구성되어 있다.

     CCDirector.sharedDirector().runWithScene(scene);
     코드를 사용하여 디렉터에서 기본적으로 화면에 보여줄 scene을 전달한후에는
     
     CCDirector.sharedDirector().pushScene(scene);
     CCDirector.sharedDirector().popScene();
     CCDirector.sharedDirector().replaceScene(scene);
     이용해서 장면전화을 한다. 
     
     replaceScene 는 별거 없는것이 . pop 한 후에 push 한것  뿐이다.  보다 쓰기 쉽게만들어
     놓은 api 뿐이니 별 고민 할 필요 없다. 몰라도 된다 걍 남들이 쓰면 이런게 있다 정도로만 
     알아 두자 .
     Scene 라고 별거 없다 그냥 layer 라고 생각하면 된다. 다만 디렉터에서 관리하는
     Layer일 뿐이다.

     디렉터에서 관리하는 Layer는 Scene이다.  

==>Scene_Action 장면전환 효과가 있는 Scene 라고 하나의 패키지로 나와있는데 
     이것은 어이없는게도 CCNode+Action 일뿐이다. 
     이전 까지는 CCNode와 CCAction을 따로 선언하여 하나로 합쳐서 액션을
     사용했지만. 장면전환효과가 있는 Scene라고 거창한 이름을 붙여놓은것은
    CCScene에 기본 액션을 디폴트로 집어 놓았을뿐이다. 별거없다. 내부 함수들을
    살펴보면 알겟지만 더이상 없다. 이런 기본적인 것들을 알아 보았으니
    우리도 이와 비슷한것을 수십가지를 만들어 낼수 있다. 
    action에 action을 추가해서 CCSecne를 상속한 클래스에 박아 넣기만 하면
    되니까 말이다.  



나머지 Layer2와 Layer3도 별다른 차이점이 없다 여기서 설명한 내용이 전부 일뿐이다.
그런데 어떻게 글을쓰다 보니까 반말이 되었네요^^;;
글 수정하기도 ~~ 좀 그러니 ㅎㅎㅎ 이번만 양해 해주세요 

추가로 이상하다거나 헷갈리는 부분이 있으면  댓글로 ^^


Posted by 수다쟁이증후군 :