Gdx.files是libgdx的文件模块,主要提供以下5大功能。
1、读取文件
2、写文件
3、复制文件
4、移动文件
5、列出文件和目录
而获取操作文件的FileHandle有4种方法。
1、Classpath
路径相对于classpath,文件通常为只读。
2、Internal
内部文件路径相对于程序根目录或者android 的assets文件夹。
3、External
外部文件路径是相对于SD卡根目录。
4、Absolute
assets文件夹本身就是存储资源的文件夹,而且相比resource文件夹,它其中的资源不会生成R中的ID,用来放图片很是合适。
package com.hyl.libgdx.a;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class BGame implements ApplicationListener{
//绘图的
private SpriteBatch batch;
//纹理
private Texture texture;
//区域
private TextureRegion region;
//精灵
private Sprite sprite;
@Override
public void create() {
batch=new SpriteBatch();
texture=new Texture(Gdx.files.internal("my.jpg"));
//region=new TextureRegion(texture, 30,80, 200,200);
sprite=new Sprite(texture, 80, 80, 400, 300);
//位置
sprite.setPosition(10, 10);
//旋转
sprite.setRotation(15);
//sprite.setColor(0.4f,)
}
@Override
public void dispose() {
}
@Override
public void pause() {
}
@Override
public void render() {
//清屏
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
//batch.draw(region,20,20);
sprite.draw(batch);
batch.end();
}
@Override
public void resize(int arg0, int arg1) {
}
@Override
public void resume() {
}
}