Libgdx Can't Load Text Written in Overlap2D - java

I am attempting to create a game in libgdx using the tool overlap2d, and everything works fine except one key thing: every time I add text to the scene, I get an error stating that it can't find the corresponding font file. I have the file, I've made sure it's spelled right, and I've tried running this with it in my assets folder and just about every other folder in my project, but it just won't work. What do I need to do or where do I need to put this for libgdx to be able to find my font?
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: File not found: freetypefonts\Calibri.ttf (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.length(FileHandle.java:602)
at com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.<init>(FreeTypeFontGenerator.java:90)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadFont(ResourceManager.java:319)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadFonts(ResourceManager.java:312)
at com.uwsoft.editor.renderer.resources.ResourceManager.loadAssets(ResourceManager.java:205)
at com.uwsoft.editor.renderer.resources.ResourceManager.initAllResources(ResourceManager.java:100)
at com.uwsoft.editor.renderer.SceneLoader.<init>(SceneLoader.java:63)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:21)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:146)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:123)

Try opening the project in editor again, and pressing export again, the ttf file probably did not get exported first time around.

Related

new File() works but getResource()/getResourceAsStream() throws null exception

In the context of a school project i'm currently working on a little game in eclipse which I want to convert into an executable JAR when I'm done. Since I'm working with the .drawImage() method on my label I need to use BufferedImage or Image. To import my pictures into my project I've created a folder called "rsc" and set it as a resource folder, them put the images in there.
Now, when I use
BufferedImage bg1 = ImageIO.read(new File("rsc/BlackWhiteSpace.jpg"));
Everything works fine. But I obviously can't use that when exporting the project because that will change the paths and the method will no longer be able to find the images even though they are clearly included in the JAR (I've checked)
The resolution I found on the Internet is to use .getResource() or .getResourceAsStream()
I've tried tons of different variations. Here a few examples:
ImageIO.read(getClass().getResource("rsc/BlackWhiteSpace.jpg"))
ImageIO.read(Var.class.getResourceAsStream("rsc/BlackWhiteSpace.jpg"))
ImageIO.read(Var.class.getResource("rsc/BlackWhiteSpace.jpg"))
And also different path variations such as:
"/rsc/BlackWhiteSpace.jpg"
"rsc/BlackWhiteSpace.jpg"
"/BlackWhiteSpace.jpg"
"BlackWhiteSpace.jpg"
Etc.
I've also thought of case sensitivity and those examples aren't the only variations I've tried.
Now why is java still giving me:
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
???
What am I doing wrong? This project is being graded so I really wanna be able to run it without eclipse, please help!
Edit:
[enter image description here][1]
[1]: https://i.stack.imgur.com/tIlz4.png
https://pastebin.com/s7Yxtw6Y

JavaFX + SpringBoot, cant load css

i need a help understanding what is happening in my project, anyways i have javafx with springboot:
i have folder structure like this :
So i want to access from my java/controller folder, and i need my css file that is under resources folder, in css folder.
I tried every possible way, to load my css and nothing seems to work except :
Directly loading css through fxml (which i wish to evade)
using this code also works, but only in IDE, if i create JAR it does not work anymore :
File f = new File("src/main/resources/css/main.css");
paneRoot.getStylesheets().add("file:///" + f.getAbsolutePath().replace("\\", "/"));
When i do check of f.exists() i get true, so path is ok, but when i use this :
paneRoot.getStylesheets().add(getClass().getResource("src/main/resources/css/main.css").toExternalForm());
or
paneRoot.getStylesheets().add("src/main/resources/css/main.css");
it does not work,in first code line, where i use .toExternalForm(), program crashes reporting nullPointer.
Now i honestly do not know what is issues here, i tried with 2 different IDE-s, i tried clearing cashe, rebulding and cleaning application, but every time same issue.
If i need to provide further code, i will i just need to understand this.

X3D files won't load with a URL

I'm making a Xj3D Test class in Java and it's meant to display X3D and X3DV files. It does work with some test files. But when it comes to the X3D files that I've been given, they don't get displayed and I get an error saying:
Exception in thread "main" org.web3d.x3d.sai.InvalidURLException: Unable to load any URLS
at org.web3d.vrml.scripting.external.sai.SAIBrowser.createX3DFromURL(SAIBrowser.java:846)
at xj3dtest.Xj3DTest.<init>(Xj3DTest.java:50)
at xj3dtest.Xj3DTest.main(Xj3DTest.java:56)
I've done some research and I've seen that I might need to use the createX3DFromStream method instead of the createX3DFromURL method that I currently have in my Java code. I realise that it's the URL within the X3D and X3DV files that's causeing the problem and I need to get rid of the error as it's prohibiting me from continuing the project. The line in my Java code that's causing the problem is: X3DScene scene = browser.createX3DFromURL(new String[] {"hafodty_cirlce_1.x3dv"});. I have the X3DV file hafodty_circle.x3dv saved within my NetbeansProject folder for the project.
EDIT
The way that I got the Browser element was by the following line.
Browser browser = x3dComponent.getBrowser();

Tiled Map Editor exporting Libgdx

I have a problem with exporting Tiled map file.
I create map and , suggest a tutorial, I exporting tmx file and import it in Eclipse project assets.
In the code I did this:
tiledMap = new TmxMapLoader().load("map.tmx");
tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap);
My problem is that when I execute it I get this :
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Couldn't load file: tileset 2/grass-tiles-2-small.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:130)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:100)
at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:96)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:116)
at com.badlogic.gdx.maps.tiled.TmxMapLoader.load(TmxMapLoader.java:101)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:43)
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: tileset 2/grass-tiles-2-small.png (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.files.FileHandle.readBytes(FileHandle.java:220)
at com.badlogic.gdx.graphics.Pixmap.<init>(Pixmap.java:137)
What do I for fix it?
As I see in libGdx wiki , there is two option to load tmx files. Make sure your files under the assets folder. You can see in libGdx Wiki how to load tmx files. Also there is similar question in here.
Tiled is referencing its tileset image source in the .tmx file. So the tileset grass-tiles-2-small.png you used is not embedded and has to be loaded, too. Fortunately this is done automatically by resolving the image dependencies for you.
So additionally to map.tmx you have to make sure that all used image files are reachable by copying them to your assets folder. It has to look like this: assets/tileset 2/grass-tiles-2-small.png. Refresh your Eclipse project after doing so, just in case it didn't notice.
If you already did that, another source of the problem could be the whitespace in your directory name. Try to rename tileset 2 to tileset_2 and create a new .tmx file.
It simply failed to load you texture grass-tiles-2-small.png. I usually open up the TMX/XML file and set the filenames for the tilesheets to just the filenames manually without a path.
Example:
<tileset firstgid="1" name="grass" tilewidth="32" tileheight="32">
<image source="grass-tiles-2-small.png" width="256" height="256"/>
</tileset>
You should put the textures in the same folder within your project as the map.tmx resides preferably Android/assets/../.. and use the Gdx.files.internal to load your map. internal just returns a regular file handle.
tiledMap = new TmxMapLoader().load(Gdx.files.internal("yourmap.tmx"));
The TMX just looks in the same folder for the right textures to use since we didn't specify a path in the tmx/xml.
Thoughts:
I really hate the LibGDX default TmxLoader. It would work for really simple things but you have no way of sorting depth when sprites overlap since the only way to draw is to draw a complete layer at once. If you need a overlap on a player you need to be able to draw tile by tile/object by object. I wrote my own XML parser for Tiled maps and it surprised me how simple it was. I have a pretty complicated map and it just took me about 30 lines of code to load everything into an array ready to draw it within LibGDX.

How to use JavaCv's cvSaveImage in android

I have created an app using javaCv and
I'm trying to save an image in android using
cvSaveImage("/storage/sdcard0/watermarked/test.jpg", yCrCb);
cvSaveImage("/storage/extSdCard/test.jpg",yCrCb);
where yCrCb is an IplImage.
There is no exception error and the program runs smoothly but the files are not saved into the path as mentioned above.
I would like to ask what might be the possible problems ? is it the naming convention of the file name ?
If it helps, I have a java application counterpart of this app and the java version works fine when i use the line
cvSaveImage("C:\\testing123.jpg", yCrCb);
Hi I have used same thing for storing the image.
For getting the path to sdcard, I have used the Environment.getExternalStorageDirectory().toString();
append the folder name to this path where you want to store the image
try this and also make sure that you have written permission in the xml file.

Categories

Resources