달력

4

« 2025/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

'Screen'에 해당되는 글 1

  1. 2013.02.09 [libGDX] 화면 이동 - Screen, Game
2013. 2. 9. 13:11

[libGDX] 화면 이동 - Screen, Game 카테고리 없음2013. 2. 9. 13:11

<Game, Screen>


처음 예제를 실행시키고 난 다음, 

간단한 메뉴구성을 하고 싶은데 뭘 해야될지 몰라서 한참을 멍때리고 있었다. 

화면을 터치하면 다음 메뉴로 이동하는 걸 해 보고 싶었을 뿐인데, 뭘 해야 되는거지? 

Android 용어로 번역하면 intent를 사용하여 다음 Activity로 이동하고 싶다고.. 


처음 만들어 지는 프로젝트는 ApplicationListener 로 시작하는데

어디가면 Screen 이란걸 쓰고 어디가면 Game을 쓰고.. 

아 헤깔려.. 

그렇게 헤메다가 아래에서 답을 찾았다. 


http://code.google.com/p/libgdx-users/wiki/ScreenAndGameClasses



Game = Application 으로 이해하면 되고

Screen = Activity 로 이해하면 일단 진도 나가는데는 문제 없지 싶다. 

ApplicationListener 는 하나의 화면에서 단순히 테스트 용으로 사용하는 interface고...




<Game>

하나의 게임 전체를 관리하는 클래스로 

Game class 에 모든 Screen을 등록하고, 각 Screen 에서 호출하여 사용 가능하도록 한다.


 public class MyGdxGame extends Game {


    SplashScreen splashScreen;    

    MainMenuScreen mainMenuScreen;


    @Override

    public void create() {

        splashScreen = new SplashScreen(this);

        mainMenuScreen = new MainMenuScreen(this);


        this.setScreen(splashScreen);

    }

}




<Screen>

하나의 화면을 구성하는 단위로 

다른 화면으로 이동하기 위해서 game 의 setScreen 을 사용한다. 


 public class SplashScreen implements Screen {


    MyGdxGame game;

    

    public SplashScreen(MyGdxGame game){

        this.game = game;

    }


    @Override

    public void render(float delta) {

        Gdx.gl.glClearColor(0, 0, 1, 1);

        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


        if(Gdx.input.isTouched()){

            game.setScreen(game.mainMenuScreen);

        }    

    }

}




에구.. 

화면하나 이동하는데 등골이 다 쑤시넹.. 

이제 본격적으로 로직 시작인가? 



<결과 화면>







:
Posted by 피카프