SOLVED!!! Seems the image wasnt in a proportionate size, eg, 64x64, 128x128
Made a basic Hello World and this compiled all good, but when I try and get a basic graphic to display, all that shows is blackness. basically following a tutorial word for word and it still seems to be doing this. Any ideas anyone?
package com.me.mygdxgame;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class MyGdxGame implements ApplicationListener {
SpriteBatch batch;
BitmapFont font;
Texture mario;
@Override
public void create() {
mario = new Texture(Gdx.files.internal("mario.jpeg"));
batch = new SpriteBatch();
font = new BitmapFont();
font.setColor(Color.CYAN);
}
@Override
public void dispose() {
batch.dispose();
font.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(mario, 200, 200);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
Just realised there was an error code coming up. file name is definitely correct.
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: data/mario.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:142)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:112)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:104)
at com.me.mygdxgame.MyGdxGame.create(MyGdxGame.java:30)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data/mario.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:133)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:563)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:218)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
... 8 more
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data/mario.png (Internal)
It can't find the image "mario.png" in the data folder. Make sure you have the image in the android asset folder (Android Project -> Assets -> Data -> mario.png) .
You may want to look into how to read stack-traces (Big long error report thing) it will save you lots of time in the future.
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: data/mario.png (Internal)
He couldn't find mario.png. I recommend, if you don't use an Assets folder, to create another source folder containing all of your resources. After that, you can call Gdx.input.classpath(String classpath)
to load a file from the actual exported .jar, without having to hardcode the paths.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.