标签:
1 package com.mygdx.drawimage; 2 3 import com.badlogic.gdx.ApplicationListener; 4 import com.badlogic.gdx.Gdx; 5 import com.badlogic.gdx.graphics.GL20; 6 import com.badlogic.gdx.graphics.g2d.BitmapFont; 7 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 8 /** 9 * 显示与绘制汉字 10 * @author Jack(乐智) 11 * @blog dtblog.cn 12 * @qq 984137183 13 */ 14 public class UseFont implements ApplicationListener { 15 16 //精灵批 17 private SpriteBatch batch; 18 //字体 19 private BitmapFont font; 20 21 @Override 22 public void create() { 23 font=new BitmapFont(Gdx.files.internal("data/test.fnt"),Gdx.files.internal("data/test.png"),false);//加载字体文件和字体图片 24 font.setColor(0.5f,0.4f,0.6f,1);//设置颜色 25 batch=new SpriteBatch(); 26 } 27 28 @Override 29 public void resize(int width, int height) { 30 // TODO Auto-generated method stub 31 32 } 33 34 @Override 35 public void render() { 36 Gdx.gl.glClearColor(1, 1, 1, 1); 37 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 38 batch.begin(); 39 font.draw(batch, "我大你大呢", 200, 160);//绘制字体 40 font.draw(batch, "我大\n你大呢", 200, 360);//绘制字体,使用转义字符换行 41 batch.end(); 42 } 43 44 @Override 45 public void pause() { 46 // TODO Auto-generated method stub 47 48 } 49 50 @Override 51 public void resume() { 52 // TODO Auto-generated method stub 53 54 } 55 56 @Override 57 public void dispose() { 58 // TODO Auto-generated method stub 59 60 } 61 62 }
【开源java游戏框架libgdx专题】-08-中文显示与绘制
标签:
原文地址:http://www.cnblogs.com/AIThink/p/5929039.html