커스텀폰트를 사용해서 디바이스 자체의 기본폰트보다 좀더 깔쌈하게 출력해 보장.

먼저 ttf파일을 준비해야 한다..

 

인터넷에서 "ttf free"로 검색하면 무료로 사용할 수 있는 폰트가 많당~

여러군데 찾아보다 일본에 이런 사이트

 

 

 

 

대충 라이센스규약에 대해 읽어보니 프리로 사용가능했다. 그래서 여기서 몇가지 다운로드 받아 봤당..

 

다운로드 후 이클립스를 열고 해당프로젝트의 assets폴더에 font라는 이름으로 새로운 폴더를 생성하고 그 안에 다운받은 ttf파일을 집어 넣는다.

이렇게 하면 일단 ttf파일의 준비는 끝난 것이다.

 

자 그리고 이제 본격적으로 MainActivity를 편집하도록 하자.

 

MainActivity.java를 열고

// ===========================================================
// Fields
// ===========================================================

private Font mFont; //표준 폰트를 저장하는 필드

//다운받은 ttf파일들...하나일 수도 있고 여러개일수도 있으니..

private Font mIpagFont; 

private Font mIpagpFont;

         ------

이렇게 필드에 변수를 추가해 준다.

 

그리고

onCreateResources() 안에 ttf파일을 등록한다.

@Override
protected void onCreateResources() {

//표준 폰트를 준비

mFont = FontFactory.create(this.getFontManager(), this.getTextureManager(), 256, 256, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);

mFont.load();

 

//새로 다운 받은 ttf파일을 준비

final ITexture customFontTexture1 = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);

    mIpagFont = FontFactory.createFromAsset(this.getFontManager(), customFontTexture1, this.getAssets(), "font/ipag.ttf", 32, true, android.graphics.Color.BLACK);
    mIpagFont.load();

    final ITexture customFontTexture2 = new BitmapTextureAtlas(this.getTextureManager(), 256, 256, TextureOptions.BILINEAR);
    mIpagpFont = FontFactory.createFromAsset(this.getFontManager(), customFontTexture2, this.getAssets(), "font/ipagp.ttf", 32, true, android.graphics.Color.BLACK);
    mIpagpFont.load();

 

위와 같이 ITexture클래스를 준비하고 Font변수에 ttf파일을 등록하고 Font를 로드하면 된다.

 

다음으로 onCreateScene()안에 아래와 같이 작성하고 설정한다.

@Override
protected Scene onCreateScene() {

 final Scene scene = new Scene();

 scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));

 

//문자표시

final Text text = new Text( 10, 10, this.mFont, "표준폰트",new TextOptions(HorizontalAlign.RIGHT),getVertexBufferObjectManager()); 

            scene.attachChild(text);

 

//다운받은 커스텀폰트로 문자를 표시

final Text customText1 = new Text( 10, 100, this.mIpagFont,"다운받은 새로운 폰트",new TextOptions

                             scene.attachChild(customText1);

                       scene.attachChild(customText1);

     //다운받은 ttf갯수가 더 된다면 위와 같이 추가..

return scene;

}

 

 

 

 

 

 

 

 

 

 

 

 

Posted by BeansLove
,