Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-06 01:34:23
Oh my goodness! I can't believe I did that... Clearly not enough coffee!
Well it WORKS now! Thanks a lot to everyone who took the time to help out an Eclipse newbie like me! Cheesy
...Now I can resume actually coding the thing..
2  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-06 01:20:53
This is starting to come together, thanks guys, it's good to see what it's supposed to look like haha! I was getting quite confused...
In any case, I remade the images folder from scratch and made sure it wasn't in the build path or anything, just a plain folder. I put laid it out the you have yours there Ra4king. Good news! It now runs in Eclipse!
Bad news... it still won't run as an executable jar...

Here's what it looks like now:

3  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 23:41:23
At this point, I'm not even sure what exactly a class loader is, I just read that if I do it this kind of way it's better  persecutioncomplex.
I certainly appreciate all the time you guys are putting into helping me out, I've done what I think you guys were telling me to do, it looks like this now:



However, it's not even running in Eclipse anymore... Sad
So let me get this straight, the src folder is treated as the root directory right? So surely putting the images folder in src folder would mean that the path, "/images/myfile.png" would work right? ...Cause it's not. I really think the problem is WHERE I'm putting my images folder, I simply just don't know the correct place for it.
This is such a rediculous error for me to be stuck on...
4  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 16:31:55
I used that code you suggested, it worked in Eclipse, but after exporting is an executable Jar, still didn't work.
I seriously think something is wrong with my folders or something. Am I correct in assuming that the images folder should be a source folder in the Java Build Path in properties? Because I've tried that too, and it broke it again Sad
I'm definately doing SOMETHING wrong though, since I've looked through tons of videos today and they just breezed through it...

EDIT: Here's a picture of my little project list that might shed some light on the subject. I'm not sure that images folder is in the right place, I've moved it around a fair bit though....

5  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 16:09:30
Well I opened the project properties, went to build path, went to the source tab, added the folder and this is what happened...
Some deal about enabling nesting? Does this mean my folders are whack?

6  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:55:22
That's starting to sound like the solution to my problem!
See I only just switched over to Eclipse yesterday, I've been trying to learn it as best I can, yet a little thing like this seems to have slipped under my radar.
So the properties where I assign this as a resource folder, is that the properties from the project menu? Or is it the properties from right clicking on the folder itself? Also, whereabouts in properties? Is it build path or linked resources or something I've missed entirely?

Sorry to waste time on such a small little problem!!
7  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:43:59
Sorry! That didn't work either, I tried that code with "images/", "/images/" and "../images/", still no good.
I'll go ahead and paste in the class I'm using to hold my sprites, minus the getters.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
public class Sprites 
{
   public BufferedImage[] sprites = new BufferedImage[4];
   private int tileSize = 32;
   
   public Sprites()
   {
      try
      {
         //Block tileset
        BufferedImage blockTileset =
               ImageIO.read(this.getClass().getResource("images/tiles.png"));
         
         sprites[0] =
               ImageIO.read(this.getClass().getResource("images/dude.png"));
         sprites[1] =
               ImageIO.read(this.getClass().getResource("images/enemy.png"));
         
         //Loop through block tileset
        for (int i1 = 0; i1 < 1; i1++)
         {
            for (int i2 = 0; i2 < 2; i2++)
            {
               sprites[i2 + 2] = blockTileset.getSubimage(i2 * tileSize,
                     i1 * tileSize, tileSize, tileSize);
            }
         }
      }
      catch (Exception e)
      {
         System.out.println(e.getMessage());
      }
   }


If you're wondering about the nested for loops, I'm leaving those in for when my sprite sheet exceeds two sprites haha!

I still think it's probably to do with where I've put the images. The images folder is in the same directory as all my code, surely that would be ok?
8  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:32:21
I've tried that before Sad I'm afraid it doesn't work. Eclipse doesn't even find the images when I do it like that. The Jar still falls over too.
9  Game Development / Newbie & Debugging Questions / Re: I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:23:01
Sure thingy! It's a really small, simple project.

I opened the Jar in 7zip and got the following:

platformer >  images           >    All my images
               |  All my code 
       
META-INF > manifest.mf

I hope that's readable enough! Smiley
10  Game Development / Newbie & Debugging Questions / I have no idea how to get my images to work in a Jar! on: 2012-01-05 15:11:49
(I've attempted to put the tl;dr stuff in bold)
Hey everyone, I'm totally new here and relatively new to Java, I was hoping I could get some help regarding a practice game I'm making.
I did a few searches, I didn't find anything like this, but I also wasn't going to spend my entire evening tunneling through forum searches XD

Anyway, my game was working fine when I ran it in Eclipse, but I wanted to be able to show it to my buddies, I exported it as an executable Jar and ran it.
Nothing ran at all. So I looked into it and apparently my images aren't loading up properly when I run the Jar.

Why is it that Eclipse can find my images and run the thing fine and when I export it nothing works?
I'm assuming it's to do with where I placed my files. I HAVE NO IDEA WHERE TO PUT THEM! But I do want them in an images folder at the very least.
I've currently got them in "src/platformer/images"
Platformer is my package name/folder and has all my code in there.


The code I'm using to load the images up has changed a few times, but what I'm currently using is:

BufferedImage blockTileset = ImageIO.read(this.getClass().getResource("images/tiles.png"));

Now I'm not entirely sure what I'm doing there, I just read from Kev Glass' tutorials that it's a good idea to do it that way.
Can anyone lend some insight into this? Do I need to move my images folder somewhere? Do I need to add a slash or something to my file path? I've spent all day on this annoying problem and haven't got anywhere! I know it's a simple, stupid problem, but please bear with me!

Thanks in advance Smiley

P.S. You may need to dumb down your answers a little bit, I'm not a full on programmer yet! So many things I've looked up today where people had problems that were solved thusly, 'Simply do this! *insert a whole mess of uncommented code with poorly named variables*' 'Wow thanks for solving my problem! Cheesy'. Then you have me sitting here, thinking in angry scribbles and reaching for another coffee...
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (34 views)
2013-05-17 21:29:12

alaslipknot (42 views)
2013-05-16 21:24:48

gouessej (72 views)
2013-05-16 00:53:38

gouessej (71 views)
2013-05-16 00:17:58

theagentd (79 views)
2013-05-15 15:01:13

theagentd (74 views)
2013-05-15 15:00:54

StreetDoggy (116 views)
2013-05-14 15:56:26

kutucuk (139 views)
2013-05-12 17:10:36

kutucuk (140 views)
2013-05-12 15:36:09

UnluckyDevil (148 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.132 seconds with 21 queries.