I am following a java tiled game tutorial using libGDX and I met the following errors :
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: gaming creation/herbe16.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:108)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:119)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:104)
at com.poussins.screens.Play.show(Play.java:35)
at com.badlogic.gdx.Game.setScreen(Game.java:62)
at com.poussins.Poussins.create(Poussins.java:11)
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: gaming creation/herbe16.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)
... 12 more
here is the code i'm using in the Play class :
package com.poussins.screens;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
public class Play implements Screen{
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
private OrthographicCamera camera;
#Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setView(camera);
renderer.render();
}
#Override
public void resize(int width, int height) {
camera.viewportWidth = width;
camera.viewportHeight = height;
camera.update();
}
#Override
public void show() {
map = new TmxMapLoader().load("maps/map-Herbe-Goudron.tmx");
renderer = new OrthogonalTiledMapRenderer(map);
camera = new OrthographicCamera();
}
#Override
public void hide() {
dispose();
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
map.dispose();
renderer.dispose();
}
}
In order to put the .tmx map into the Eclipse project, I just made a Copy (from the folder where the .tmx map is) and a paste in the Eclipse project named "Poussins-Desktop / assets / maps". I used the same actions (copy paste) to give the .png tiles to the same Eclipse project named "Poussins-Desktop / assets / maps" (can see it in the screenshots).
In the code, I am not sure with this following line :
map = new TmxMapLoader().load("maps/map-Herbe-Goudron.tmx");
because I don't know if the path to the .tmx is good, but it seem to respect what was said in the tutorial ...
In fact, in the error, it is saying that the file herbe16.png cannot be loaded. but this file is a tile from the whole .tmx map.
I am working on UBUNTU 13.10 system, Eclipse 3.8.1
I hope someone will help me and I thank you in advance for paying attention to my problem.
Okay, I don't know if this will help you..
I was just declaring the path for my files not minding caps letters (I'm using windows7).
Now, when I tested the code as a java application on my desktop it was going smoothly but when I tried launching it on an emulator or an android device it would crash.
Turns out that the emulator and device both need the exact path with capital letters.
This may have already been solved or the OP may have given up on it, but I came across this error too on the same tutorial. I solved the issue in my case. It may be possible that the OP was using a .png of a different bit depth (as was in my case). The .png that caused the error was 64 bit depth (you can check by right clicking on the .png -> PROPERTIES -> DETAILS). Using a .png of a bit depth of 32 allowed the loading to work perfectly fine. I used photoshop to create my .png tileset, and when creating the new file, set it to 8 bit (next to the color mode).
Related
Background/Prerequisites
I am trying to follow a game tutorial(to create flappy bird). In the
Episode - 2 it creates an empty window and I get an error.
I tried following this tutorial series to create a game using java - eclipse - lwjgl.
https://www.youtube.com/watch?v=1pUYjxeDNEs&list=PLlrATfBNZ98e5KBKGcL7ARy3DjstzI2TV&index=1&ab_channel=TheCherno
Flappy Bird - Episode 1
I have installed java jdk 17.0.6 (in the tutorial it installs an older version which I thought it won't be a problem, let me know if this could be the cause), eclipse 2022 and lwjgl - 2.9.1.
I have copied the code from Episode 2 (seen below):
https://www.youtube.com/watch?v=PlMqfsOOD3U&list=PLlrATfBNZ98e5KBKGcL7ARy3DjstzI2TV&index=2&ab_channel=TheCherno
Flappy Bird - Episode 2
which tries to create an empty window.
package com.chris.flappy;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Main implements Runnable{
private int width = 1280;
private int height = 720;
private String title = "Flappy";
private boolean running = false;
private Thread thread;
public void start(){
running = true;
thread = new Thread(this,"Display");
thread.start();
}
public void run() {
try {
Display.setDisplayMode(new DisplayMode(width,height));
Display.setTitle(title);
Display.create();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(running) {
if(Display.isCloseRequested()) running = false;
}
Display.destroy();
}
public static void main(String args[]) {
new Main().start();
}
}
I have included in the module path the lwjgl.jar file and changed the native library location as shown in the video to the corresponding folder with the dlls, but with the difference that in the video (probably because it was an older version) it didn't have the separation of module path and class path.
Screenshot_1
I have the following workspace folders set.
Screenshot_2
Screenshot_3
Error
I am gettting the following error.
Error: Unable to initialize main class com.chris.flappy.Main
Caused by: java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Screenshot_4
What have I tried from the mentioned solutions?
I have tried using an older version of java (1.8) and still it doesn't work
In this article solution they mentioned about moving jars to classpath, I tried drag and dropping them from module path as well as placing them but it seems to not work.
Does anyone know how can I fix this?
Thank you.
Comment section
comment_screenshot1
comment_screenshot2
I'm currently practising and coding a simple menu that can switch to the main game by the press of a button.
The main game is in 3D using all the features that libGDX uses to create a 3D environment. The menu is built using a Stage. I built the Menu and Render/FirstPerson classes separately to ensure they work by themselves and sure enough they did.
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.mygdx.game.FPSSystem;
import com.mygdx.game.RenderingSystem;
public class MainCoreLoop extends ApplicationAdapter {
public MenuSystem menuSystem;
public RenderingSystem renderingSystem;
public FPSSystem fpsSystem;
public boolean isGameOn;
#Override
public void create () {
renderingSystem = new RenderingSystem();
fpsSystem = new FPSSystem();
menuSystem = new MenuSystem();
renderingSystem.create();
fpsSystem.create();
menuSystem.create();
}
#Override
public void render () {
isGameOn = true;
if (MenuSystem.isMenuClosed == true) {
isGameOn = true;
}
else if(isGameOn == false) {
Gdx.gl.glClearColor(0, 255, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
menuSystem.render();
}
if(isGameOn == true) {
Gdx.gl.glClearColor(255, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT|GL20.GL_DEPTH_BUFFER_BIT);
fpsSystem.render();
renderingSystem.render();
}
}
#Override
public void dispose() {
menuSystem.dispose();
fpsSystem.dispose();
renderingSystem.dispose();
}
}
I have a RenderingSystem class that handles rendering, a FirstPersonSystem class that initialises another class, FPSCameraController class, that controls the logic and the input, which the code borrows from the FirstPersonCameraController class that comes with libGDX.
So I could test these classes together, I used a boolean named isGameOn that works well enough. After a little while of testing and refactoring, I managed to get everything to work EXCEPT the input. A 3D box renders perfectly after pressing 'New Game' but the input does not work. If I change the boolean to true, it will render the box but still with no input.
The code seems to work independently but trying to bring them together is a bit trickier to me.
I'm thinking that this might be a code order problem, but I'm quite stumped. I am new to libGDX, and I have only really been working in Java seriously for a little while, off and on in the past, so my fundamentals of code may be stopping me from figuring this out.
The rest of the code is on github Here
Any help\insight\insults would be much appreciated. Thanks!
I answered one problem about using Game and Screen classes in LibGdx to make switching better which is likely to help in your circumstances.
The Game/Screen tutorial which that snippet comes uses Gdx.input. methods for mouse, keyboard and touch events.
The rest should be fairly straightforward from there.
I'm using Libgdx and AssetManager to load assets into memory. First I thought that something is wrong with my project so I made a new clean one, and the problem persists.
The Sound is not playing even if I use "IsLoaded" method and is not playing the first time (if you jump really quick into the game). The sound is small , like 40KB, and this happens only on Android (works on Desktop/iOS). The device I'm testing on Android is HTC One M7 with Lolipop. Here is the code of a clean project.
package com.mygdx.game;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.Audio;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Sound;
public class MyGdxGame extends ScreenAdapter {
private AssetManager assetManager;
#Override
public void show() {
super.show();
assetManager = new AssetManager();
assetManager.load("sound/jump.mp3", Sound.class);
}
Sound jump;
boolean isLoaded;
#Override
public void render(float delta) {
super.render(delta);
if(isLoaded) return;
assetManager.update();
if(assetManager.isLoaded("sound/jump.mp3", Sound.class)) {
assetManager.finishLoading();
jump = assetManager.get("sound/jump.mp3", Sound.class);
isLoaded = true;
System.err.println("LOADED");
jump.play();
}
}
}
In LOGCAT I'm getting "soundpool sample 1 not ready" error.
Any ideas?
NOTE: The sound is playing as normal if I give it a little time (If I don't press "play" right away).
The question is why does Libgdx thinks that the sound is loaded into memory even if its not.
Have you tried using .ogg instead?
On my libgdx projects i always used .ogg, since its license -free and well, it never gave me issues!
You should also be careful with the different Sound imports. I remember that you can sometimes import directly .ogg .mp3 classes from libgdx and that causes issues.
Also, i think the problem is that, even if the audio file was loaded, the assetmanager is still loading other resources.. so its busy doing another task.
I would either :
a) Play that sound without the assetmanager, since its just for the loading, right?
b) (This needs to be checked) But Maybe use a different assetmanager for that audio? Unsure how much resource would it waste by having 2 assetmanagers..
But, i would try that. Change to .ogg first, be sure the audio starts at exactly 0:00 and update to the last libgdx version.
I'm experiencing the same issue. I am using libgdx version 1.9.2. So far, I tried:
changing mp3 to ogg
using different asset manager for sounds
and it didn't help.
I replaced Sound object with Music object and it did help. But I'm not sure if this is the right approach, because I have a lot of short sounds in my app.
I know this is an old thread but I just ran into this same problem and I solved it like this..
private Sound sound;
private float soundVolume;
public void playSound(String path, float volume) {
sound = assetManager.get(path, Sound.class);
soundVolume = volume;
}
#Override
public void render () {
super.render();
// Because of some weird Android bug
if (sound != null) {
sound.play(soundVolume);
sound = null;
}
}
This is in my main game class and I can call the playSound() method from any other class.
It's probably caused by Gdx.audio.newSound() method is loading the sound by asynchronously instead asserting sound loading process to processor. I solved this by adding a "delay" to the playing sound process only for the first playing. That solved my problem.
private static void soundBugFixer(Sound sfx, float volume)
{
Timer x = new Timer();
x.scheduleTask(new Timer.Task() {
#Override
public void run() {
sfx.play(volume);
}
}, 0.1f );
}
public static void remove(float volume) {
if(sfxRemove == null)
{
sfxRemove = Gdx.audio.newSound(Gdx.files.internal("sfx/sfx_remove.wav"));
soundBugFixer(sfxRemove, volume);
}
else
{
sfxRemove.play(volume);
}
}
I have been trying to export a standalone application for Mac using the "Export Application" function in Processing. The simple application, which involves updating a float value on the screen that corresponds to the y-axis position of a hand detected by a Leap Motion, works perfectly well within Processing. However, once I export the application and try to run it, the app opens for a brief second and quickly closes. I have exported applications from Processing successfully before, but not one that uses the Leap SDK. I am using the LeapMotion library for Processing to access the Leap SDK: https://github.com/heuermh/leap-motion-processing. Here is my code:
import processing.core.*;
import com.leapmotion.leap.processing.*;
import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Listener;
public class Test extends PApplet {
Controller controller;
MyListener listener;
float position = 0.0f;
class MyListener extends Listener {
public void onFrame(Controller controller) {
if (!controller.frame().hands().isEmpty()) {
position = controller.frame().hands().leftmost().palmPosition().get(1);
}
}
}
public void setup() {
size(600,600);
controller = new Controller();
listener = new MyListener();
controller.addListener(listener);
}
public void draw() {
background(0);
textAlign(CENTER,CENTER);
textSize(50);
text(position, 300,300);
}
public static void main(String args[]) {
PApplet.main("Test");
}
}
When I export the application, the contents of the application are as follows:
Info.plist
Java
-core.jar
-gluegen-rt-natives-macosx-universal.jar
-gluegen-rt.jar
-jogl-all-natives-macosx-universal.jar
-jogl-all.jar
-LeapJava.jar
-LeapMotion.jar
-libLeap.dylib
-libLeapJava.dylib
-Test.jar
MacOS
-Test
Plugins
-jdk1.7.0_45.jdk
Resources
-en.lproj
-sketch.icns
PkgInfo
Any help would be greatly appreciated!
P.S. I've already tried bundling the program into a runnable JAR file.
I'm following this tutorial on libgdx and I've hit a bit of a snag. I just finished the 'loading the assets' section. When I tried to run it, instead of getting the rain sound and a pink background, like the tutorial claims, I get errors up the wazoo. Here's my Drop.java:
package com.badlogic.drop;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
public class Drop implements ApplicationListener {
Texture dropImage;
Texture bucketImage;
Sound dropSound;
Music rainMusic;
#Override
public void create() {
// load the images for the droplet and the bucket, 64x64 pixels each
dropImage = new Texture(Gdx.files.internal("droplet.png"));
bucketImage = new Texture(Gdx.files.internal("bucket.png"));
// load the drop sound effect and the rain background "music"
dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
// start the playback of the background music immediately
rainMusic.setLooping(true);
rainMusic.play();
}
#Override
public void dispose() {
}
#Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}
#Override
public void resize(int width, int height) {
}
#Override
public void pause() {
}
#Override
public void resume() {
}
}
and here are my errors. (Ones I think are important are bolded)
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: droplet.PNG
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:113)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: droplet.PNG
at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:140)
at com.badlogic.gdx.graphics.glutils.FileTextureData.prepare(FileTextureData.java:64)
at com.badlogic.gdx.graphics.Texture.load(Texture.java:175)
at com.badlogic.gdx.graphics.Texture.create(Texture.java:159)
at com.badlogic.gdx.graphics.Texture.(Texture.java:133)
at com.badlogic.gdx.graphics.Texture.(Texture.java:122)
at com.badlogic.drop.Drop.create(Drop.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:127)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: droplet.PNG (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:127)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:580)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:215)
at com.badlogic.gdx.graphics.Pixmap.(Pixmap.java:137)
... 8 more
The weird thing is, I have all of the pngs and music files in my assets/data folders. They're all there, but the code isn't seeing them. Any idea what's causing this?
when you are using
Gdx.files.internal <- This only gets you to the assets folder. You have to direct it into any sub-directories you are wanting files from also.
and your files are in assets/data use
Gdx.files.internal("data/droplet.png")
Be sure to change all your other references also to the correct location.