I got error with rendering sprite in Eclipse libGDX - java

I'm trying to make basic game in Eclipse libGDX. I have Problem with rendering sprite. I do everything like it shoud be, but I still get this Error:
LwjglGraphics: created OpenGL 3.2+ core profile (GLES 3.0) context.
This is experimental! Exception in thread "LWJGL Application"
com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: BG.png
at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:148) at
com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.Texture.(Texture.java:100) at
com.badlogic.gdx.graphics.Texture.(Texture.java:92) at
com.zebrabandit.egghead.Assets.Load(Assets.java:13) at
com.zebrabandit.egghead.GameScreen.(GameScreen.java:24) at
com.zebrabandit.egghead.EggHead.create(EggHead.java:10) at
com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at
com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found:
BG.png (Internal) at
com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136) at
com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222) at
com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:145) ... 8 more
And here is my CODE:
public static Texture backgroundT;
public static Sprite backgroundS;
...
backgroundT = new Texture(Gdx.files.internal("BG.png"));
backgroundT.setFilter(TextureFilter.Linear, TextureFilter.Linear);
backgroundS = new Sprite(backgroundT);
backgroundS.flip(false, true);
...
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1F, 1F, 1F, 1F);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
//rendering code :D
batch.draw(Assets.backgroundS, 0, 0);
batch.end();
}

I assume you have initialized your project with the setup application Tool
(gdx-setup.jar).
Then it's possible you are experiencing the working directory setup problem.
That's what the error says(Couldn't load file)
In IDEA IDE I have to edit configuration so the working directory points to folder in project: android\assets
File not found question was answered here
For further reference please check the video Mario Zechner has recorder to ease work the Eclipse users:
Running and Debugging in Eclipse

Couldn't load file: BG.png at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:148) at ...
I think your problem is you are trying to load a file, that is not there. Are you absolutely sure that there is a file in that location Gdx.files.internal("BG.png").
Also you will have many problems if you are trying to load assets with uppercase characters in their names on android. So if your file is there, try renaming it to all lowercase characters.

Related

What is the way to draw custom images on MCP 1.16.5?

I was trying to draw a background for my main menu. This process can be simply done in Minecraft 1.8 by placing the image inside mc's assets folder and binding the resource using its path. However, after moving to MCP 1.16.5, this method can't be done the same way anymore. I tried researching articles but found nothing useful.
This is my code, it's put in the render() method
minecraft.getTextureManager().bindTexture(new ResourceLocation("mindblown", "mindblown/background.png"));
blit(matrixStack, 0, 0, 0, 0, width, height);
I also put my background.png file in the following directory
src/main/resources/minecraft/assets/mindblown
Upon executing the code, MC threw this FileNotFoundException
java.io.FileNotFoundException: mindblown:mindblown/background.png
at net.minecraft.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:69) ~[classes/:?]
at net.minecraft.client.renderer.texture.SimpleTexture$TextureData.getTextureData(SimpleTexture.java:112) ~[classes/:?]
at net.minecraft.client.renderer.texture.SimpleTexture.getTextureData(SimpleTexture.java:84) ~[classes/:?]
at net.minecraft.client.renderer.texture.SimpleTexture.loadTexture(SimpleTexture.java:34) ~[classes/:?]
at net.minecraft.client.renderer.texture.TextureManager.func_230183_b_(TextureManager.java:134) [classes/:?]
at net.minecraft.client.renderer.texture.TextureManager.loadTexture(TextureManager.java:95) [classes/:?]
at net.minecraft.client.renderer.texture.TextureManager.bindTextureRaw(TextureManager.java:77) [classes/:?]
at net.minecraft.client.renderer.texture.TextureManager.bindTexture(TextureManager.java:61) [classes/:?]
at mindblown.gui.main.Main.render(Main.java:20) [classes/:?]
at net.minecraft.client.gui.ResourceLoadProgressGui.render(ResourceLoadProgressGui.java:82) [classes/:?]
at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:746) [classes/:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1047) [classes/:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:564) [classes/:?]
at net.minecraft.client.main.Main.main(Main.java:215) [classes/:?]
at mcp.client.Start.main(Start.java:17) [classes/:?]
Nothing showed up but a yellow and black picture after I try to use blit(), meaning the texture wasn't bound correctly.
Screenshot
Noticing there is nothing else but 4 folders, including my mindblown folder, I think I might have put the image in the incorrect directory. However, I am unable to find any file that is used in MC code. For example:
From RealmsMainScreen.java - line 55
private static final ResourceLocation field_237542_p_ = new ResourceLocation("realms", "textures/gui/realms/expired_icon.png");
This is later bound in line 1120, and drawn successfully without throwing any error.
this.minecraft.getTextureManager().bindTexture(field_237542_p_);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
AbstractGui.blit(p_237614_1_, p_237614_2_, p_237614_3_, 0.0F, 0.0F, 10, 28, 10, 28);
Now, the weird thing is, I tried to search for expired_icon.png in src and it returned nothing, meaning the texture must have been stored inside a compressed file (which I assume Windows doesn't scan its contents). My questions is: Where do I put my image to make Minecraft recognize it?
I appreciate any help or information
put it into src/main/resources/assets/minecraft

Couldn't load file: assets/libgdx128.png

I'm building a game in LibGDX and have began adding visual aspects of the game such as the logo. Considering that I've been using the default libgdxXXX.png files as placeholders for my logo, and that I'm replacing them with my logo, I didn't feel it had any more purpose in my program. I decide to delete it; but it decide to not compile and come up with this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: assets/libgdx128.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:148)
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:196)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:142)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: assets/libgdx128.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:145)
... 3 more
Somehow, when I return the files from the Trash (I use Linux), it works again! I have checked my code and found nothing I wrote referred to those files. When I deleted the files 1 by 1, the error changes from libgdx128.png to libgdx64.png to libgdx32.png to libgdx16.png respectively. I have changed all the references from libgdx128.png to my logo.png in my code; yet when I try to delete the libgdx logo and run my program, it fails to compile! Any ideas?
I found out my problem. I forgot all about this code at DesktopLauncher.java:
for (int size : new int[] { 128, 64, 32, 16 }) {
configuration.addIcon("assets/libgdx" + size + ".png", FileType.Internal);
}
I did not know it was referencing to the files I have deleted. The configuration.addIcon(); was the code setting the program icon - similar to how a favicon works. I will be adding my own icon now that I know what the code does.
Hope this helps anyone else confused about the error.

LibGDX can't access internal image resources

I clearly stored my "background.png" in the assets folder under android.
I also checked that it was there in Finder.
I am working with Android Studio.
However, upon trying to access the image:
public Background() {
textureRegion = new TextureRegion(new Texture("background.png"));
textureRegionBounds1 = new Rectangle(0 - Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT);
textureRegionBounds2 = new Rectangle(Constants.APP_WIDTH / 2, 0, Constants.APP_WIDTH, Constants.APP_HEIGHT);
}
I get this error:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: background.png
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:140)
at com.badlogic.gdx.graphics.TextureData$Factory.loadFromFile(TextureData.java:98)
at com.badlogic.gdx.graphics.GLTexture.createTextureData(GLTexture.java:185)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:103)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:95)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:91)
at com.com.waylonhuang.game.actors.Background.<init>(Background.java:21)
at com.com.waylonhuang.game.stages.GameStage.setUpBackground(GameStage.java:66)
at com.com.waylonhuang.game.stages.GameStage.setUpWorld(GameStage.java:59)
at com.com.waylonhuang.game.stages.GameStage.<init>(GameStage.java:51)
at com.mygdx.game.GameScreen.<init>(GameScreen.java:16)
at com.mygdx.game.DrifterGame.create(DrifterGame.java:11)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:137)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: background.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:222)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
... 13 more......
What am I missing?
EDIT
Also, my current path for the Desktop launcher for the Working Directory is : AndroidStudioProjects/libGDXGame
However, upon changing it to: AndroidStudioProjects/libGDXGame/android/assets
I get a new error like such:
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.com.waylonhuang.game.stages.GameStage.draw(GameStage.java:134)
at com.mygdx.game.GameScreen.render(GameScreen.java:25)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:208)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
try using this:
textureRegion = new TextureRegion(new Texture(
Gdx.files.internal("background.png")));
if it does not work review, case sensitive, of the file name.
Edit: look that is a copy of the file, not a link, once he happened to someone so wrong
You shouldn't load assets in a constructor directly because Gdx.files is null. Either load the assets outside of the constructor or use the AssetsManager.

LibGDX Error on start with dual-display setup

The game works on Windows with fullHD. with a 2 Monitor setup on Linux I am running in the following problem:
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't set display mode 3200x1080, fullscreen: true
at com.badlogic.gdx.backends.lwjgl.LwjglGraphics.setupDisplay(LwjglGraphics.java:150)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:131)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Details about the 2 displays: First FullHD, second 1280x1024
I get the width an hight with the following lines (cfg is the configuration variable)
cfg.width = Toolkit.getDefaultToolkit().getScreenSize().width;
cfg.height = Toolkit.getDefaultToolkit().getScreenSize().height;
Any help appriciated. If you need more info, please let me know :D
Is there a way to get the width, height only for the primary display?
Yours,
Florian

java.lang.RuntimeException: Resource not found?

I can't understand why I'm getting this error: java.lang.RuntimeException: Resource not found I'm trying to make a simple 2d game using Slick and LWJGL libraries, I followed this guide http://www.youtube.com/playlist?list=PLaNw_AbDFccGkU5gnFYquQ0PNQPmmD-Q7 and I managed to make even some more by myself.
The thing is that I am receiving this error even though the image does exist in the specified location. The game runs completely fine and suddenly quits with the error I already mentioned.
The error:
Wed Nov 27 14:43:46 PST 2013 ERROR:Resource not found:
/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png
java.lang.RuntimeException: Resource not found:
/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png
at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69)
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:273)
at org.newdawn.slick.Image.<init>(Image.java:270)
at org.newdawn.slick.Image.<init>(Image.java:244)
at org.newdawn.slick.Image.<init>(Image.java:232)
at org.newdawn.slick.Image.<init>(Image.java:198)
at tomtam.game.object.BlockGreen.render(BlockGreen.java:18)
at tomtam.game.main.World.render(World.java:447)
at tomtam.game.state.PlayState.render(PlayState.java:76)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:207)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:703)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at tomtam.game.main.Main.main(Main.java:36)
Wed Nov 27 14:43:46 PST 2013 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:706)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:456)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:361)
at tomtam.game.main.Main.main(Main.java:36)
So the error points to this part of the code (image):
public void render(GameContainer gc, Graphics g) throws SlickException
{
super.render(gc, g);
image = new Image("/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png");
}
I am not a skilled programmer, but I guess that this error is because the image is getting rendered nonstop, even if it's location or other information haven't changed. That may produce some lag spikes, right..? So, I tried to change it to:
try
{
image = new Image("/home/tomtam/workspace/Game/gfx/world/object/blockgreen.png");
}
catch (RuntimeException npe)
{
}
I know that it's a bad thing to do it like this, however, this way I am not receiving any errors and everything works fine for some time. After some time some images starts blinking and the more I wait, the less time they are showing up until finally disappearing.
The code is kinda long, but I can post it, just ask. Any help will be appreciated.
Usually a "java.lang.RuntimeException: Resource not found" occurs when your resources (images now) are not in your CLASSPATH and generally it is a classpath issue.
This may also help you.

Categories

Resources