android游戏开发框架libgdx的使用—使用TexturePacker工具

本文介绍了一个使用LibGDX框架开发的游戏示例项目。该示例展示了如何加载资源包并利用Scene2D模块显示图像,包括图像的缩放和平移操作。通过此示例,读者可以了解到如何在LibGDX中实现基本的图像处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值