android遊戲開發框架libgdx的使用—使用TexturePacker工具

package com.me.mygdxgame;


import com.badlogic.gdx.ApplicationListener;

import com.badlogic.gdx.Gdx;

import com.badlogic.gdx.graphics.GL10;

import com.badlogic.gdx.graphics.g2d.TextureAtlas;

import com.badlogic.gdx.scenes.scene2d.Stage;

import com.badlogic.gdx.scenes.scene2d.ui.Image;


public class MyGdxGame implements ApplicationListener{

Stage stage;


@Override

public void create() {

stage= new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);

TextureAtlas atlas= new TextureAtlas(Gdx.files.internal("data/pack")); // 根據pack文件獲取所有圖片

Image image1= new Image(atlas.findRegion("14")); // 獲取名爲14的圖片,並創建一個Image對象

image1.scale(0.02f, 0.02f);

image1.setPosition(200, 50);

Image image2= new Image(atlas.findRegion("6"));

image1.setPosition(40, 40);

image1.scale(0.5f, 0.5f);

stage.addActor(image1);

stage.addActor(image2);

}


@Override

public void dispose() {

stage.dispose();

}


@Override

public void pause() {

// TODO Auto-generated method stub


}


@Override

public void render() {

Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

stage.act(Gdx.graphics.getDeltaTime());

stage.draw();

}


@Override

public void resize( int width, int height) {

// TODO Auto-generated method stub


}


@Override

public void resume() {

// TODO Auto-generated method stub


} 001443137.png



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章