-
I created a project and used animation. In my opinion, the code is normal but it fails when running the app.
-
File images: https://i.imgur.com/DOu0lpw_d.jpg?maxwidth=640&shape=thumb&fidelity=medium
-
Code:
Texture texture2;
SpriteBatch batch;
float e=0;
Animation ani;
TextureRegion[] tr;
TextureRegion[][] tr2;
int index,i,j;@Override
public void create()
{
try{
texture2 = new Texture(Gdx.files.internal(“logo.png”));}
catch(Exception ex){}
batch = new SpriteBatch();
tr=new TextureRegion[2];
tr2=TextureRegion.split(texture2,94,18);
ani=new Animation(1f/4f,tr);
index=0;
for(i=0;i<2;i++){
for(j=0;j<2;j++){
tr[index++]=tr2[j][i];
}
}
}@Override
public void render()
{
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
e+=Gdx.graphics.getDeltaTime();
batch.begin();
batch.draw(ani.getKeyFrame(e),0,0);
/batch.draw(texture, Gdx.graphics.getWidth() / 4, 0,
Gdx.graphics.getWidth() / 2, Gdx.graphics.getWidth() / 2);/
batch.end();
} -
Log info:
FATAL EXCEPTION: GLThread 2510
Process: com.mycompany.mygame4, PID: 21018
java.lang.IllegalArgumentException: texture cannot be null.
at com.badlogic.gdx.graphics.g2d.TextureRegion.(TextureRegion.java:37)
at com.badlogic.gdx.graphics.g2d.TextureRegion.split(TextureRegion.java:276)
at com.mycompany.mygame4.MyGdxGame.create(MyGdxGame.java:25)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1555)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
The project is faulty 'texture can be null'
Try to check if the file is .png
, not .jpg
And check too if the file is in the root of /assets/
folder.
I think is texture2
, nor texture!