Search code examples
javaandroidfilelibgdxassets

Java libgdx android - My own asset file is not loading


I'm new in libgdx and I'm trying to do some tutorials. I have problem with loading my own .png file.

Standard project contains libgdx.png file and it works. When I run it on desktop or android it works fine. Images display well.

The same code, just another file (also png). Works fine on desktop version, but it cannot run on android.

I really dont understand what happens, because files (libgdx.png and my.png) are in the same folder and first one works on android but the second one doesnt...

public class AwesomeGame implements ApplicationListener {
SpriteBatch batch;
Texture man;
Texture abc;
Vector2 position;

@Override
public void create() {
    batch = new SpriteBatch();
    man = new Texture(Gdx.files.internal("my.png"));
    position = new Vector2(50,50);
}

@Override
public void dispose() {
}

@Override
public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    if(Gdx.input.isKeyPressed(Input.Keys.W)){
        position.y+=1f;
    }
    if(Gdx.input.isKeyPressed(Input.Keys.S)){
        position.y-=1f;
    }
    if(Gdx.input.isKeyPressed(Input.Keys.D)){
        position.x+=1f;
    }
    if(Gdx.input.isKeyPressed(Input.Keys.A)){
        position.x-=1f;
    }

    if(Gdx.input.getAccelerometerX()!=0){
        position.x-=Gdx.input.getAccelerometerX();
    }
    if(Gdx.input.getAccelerometerY()!=0){
        position.y+=Gdx.input.getAccelerometerY();
    }

    batch.setColor(position.x,position.y,10,10);
    batch.begin();
    batch.draw(man, position.y, position.x);
    batch.end();
}

Can someone explain me that ? ;(


Solution

  • omg, I got it.

    Texture width and height must be a power of 2.

    but if I set

    cfg.useGL20 = true;
    

    everything works without power of 2.