zoukankan      html  css  js  c++  java
  • libgdx学习记录2——文字显示BitmapFont

    libgdx对中文支持不是太好,主要通过Hireo和ttf字库两种方式实现。本文简单介绍最基本的bitmapfont的用法。

     代码如下:

     1 package com.fxb.newtest;
     2 
     3 import com.badlogic.gdx.ApplicationAdapter;
     4 import com.badlogic.gdx.Gdx;
     5 import com.badlogic.gdx.graphics.GL10;
     6 import com.badlogic.gdx.graphics.g2d.BitmapFont;
     7 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
     8 
     9 public class Lib001_Font extends ApplicationAdapter{
    10 
    11     BitmapFont font;
    12     SpriteBatch batch;
    13     
    14     @Override
    15     public void create() {
    16         // TODO Auto-generated method stub
    17         batch = new SpriteBatch();
    18         font = new BitmapFont( Gdx.files.internal( "font/test.fnt" ), Gdx.files.internal( "font/test.png" ), false );
    19     }
    20 
    21     @Override
    22     public void render() {
    23         // TODO Auto-generated method stub
    24         Gdx.gl.glClearColor( 1, 1, 1, 1 );
    25         Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT );
    26         
    27         batch.begin();
    28         font.draw( batch, "5月20号,天空晴朗,蓝天里飘着白云", 10, 100 );
    29         font.drawMultiLine( batch, "5月20号
    天空晴朗
    蓝天里飘着白云", 10, 250 );
    30         batch.end();
    31     }
    32 
    33     @Override
    34     public void dispose() {
    35         // TODO Auto-generated method stub
    36         font.dispose();
    37         batch.dispose();
    38         super.dispose();
    39     }
    40 
    41 }

    运行效果如下:

  • 相关阅读:
    牛客练习赛9
    Good Bye 2017
    Wannafly挑战赛6
    TOJ1840: Jack Straws 判断两线段相交+并查集
    Codeforces Round #452 (Div. 2)
    TOJ4505: KOSARE
    Codeforces Round #451 (Div. 2)
    牛客练习赛8
    TOJ4168: Same Digits
    TOJ4483: Common Digit Pairs
  • 原文地址:https://www.cnblogs.com/MiniHouse/p/3739558.html
Copyright © 2011-2022 走看看