标签:
1 package com.mygdx.textureatlas; 2 3 import com.badlogic.gdx.ApplicationAdapter; 4 import com.badlogic.gdx.Gdx; 5 import com.badlogic.gdx.graphics.GL20; 6 import com.badlogic.gdx.graphics.g2d.Sprite; 7 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 8 import com.badlogic.gdx.graphics.g2d.TextureAtlas; 9 /** 10 * 使用图片资源 11 * @author Jack(乐智) 12 * @blog dtblog.cn 13 * @qq 984137183 14 */ 15 public class MainGame extends ApplicationAdapter{ 16 //声明精灵画笔 17 private SpriteBatch batch; 18 //声明图集变量 19 private TextureAtlas atlas; 20 //声明精灵 21 private Sprite sprite; 22 23 @Override 24 public void create() { 25 //初始化精灵画笔 26 batch=new SpriteBatch(); 27 //初始化图集对象 28 atlas=new TextureAtlas("packer/MyFirst.pack"); 29 //获取test02图片,赋值给精灵 30 sprite=atlas.createSprite("test02"); 31 32 } 33 34 @Override 35 public void render() { 36 //设置白色屏幕背景 37 Gdx.gl.glClearColor(1, 1, 1, 1); 38 //清屏 39 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 40 //开始绘制 41 batch.begin(); 42 //绘制精灵 43 sprite.draw(batch); 44 batch.end(); 45 //结束绘制 46 } 47 48 }
测试类代码:
1 package com.mygdx.game.textureatlas; 2 3 import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 4 import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 5 import com.mygdx.textureatlas.MainGame; 6 7 public class Test { 8 9 public static void main(String[] args) { 10 LwjglApplicationConfiguration config=new LwjglApplicationConfiguration(); 11 new LwjglApplication(new MainGame(),config); 12 } 13 14 }
【开源java游戏框架libgdx专题】-12-开发工具-图片合成
标签:
原文地址:http://www.cnblogs.com/AIThink/p/5931574.html