Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 7:35 pm

All times are UTC




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Fri Apr 13, 2012 3:09 pm 
Offline
Regular

Joined: Thu Sep 22, 2011 4:39 pm
Posts: 165
Location: Belgium
ha ! got it working !

how i've done it:
1/ no need to sign anything
2/ start tweaking the demo from the jlwgl applet loader (its in the full build)

Because i don't want 2 specific implementations (versions one for dpt and one for applet)
you can add a switch to know which mode you need to load

Config switch if applet or not:
Config.getInstance().loadOptions(
gc instanceof AppletGameContainer.Container ?
((AppletGameContainer.Container) gc).getApplet() : null);

if isn't an applet i search for the user profile directory to persist (serialize my objects)
related to UAC / administrator rights on your system,

if it is an applet i can't serialize objects because this is out of the sandbox security
BUT !
what you can do is, serialize your objects Base64Endoded to a cookie ! :)
et voila it runs !


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 7:21 pm 
Offline
Game Developer
User avatar

Joined: Sun Nov 12, 2006 8:40 pm
Posts: 574
Shnagenburg wrote:
So to read resources (images, sound) I can put them in a jar, but to write resources I need to use one of those methods above? I've packed up my images in my game.jar, but they still don't seem to want to load. I am using this method:

Code:
System.out.println("trying to get file...");
      Image image = null;
      try {
         image = new Image("/images/backgrounds/bg1.png");
      } catch (SlickException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      System.out.println("got image? " + image.getWidth() );


Where images/backgrounds/bg1.png is included in my jar file. It throws an access denied exception. I really appreciate all the help so far, I feel like we're really close.


get rid of the leading forward slash. So should be something like:

Code:
image = new Image("images/backgrounds/bg1.png");


Top
 Profile  
 
PostPosted: Fri Apr 13, 2012 9:42 pm 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
So I had actually tried both with and without the /, but neither worked. I actually finally read the file by moving images into my src directory. So before it was ProjectFolder -> bin, lib, src, images. Moving the images inside of the src let me read the images with
Code:
image = new Image("images/backgrounds/bg1.png");

But unfortunately my little directory recursion method isn't working, it cannot create the file object from my directory (throws access denied, but it will through that if the directory doesn't exist as well). I guess the problem is that Eclipse's applet viewer is looking at the project folder, where as the applet loader I have no idea.

In Eclipse, this works:
Code:
File folder = new File("src/images");


My guess is that src/ needs to be fixed for it to work as applet. There is probably some combination of .getClass() / .getCodeBase() / .getSource() or something that will let me look at all the files in the directory, so I'll be experimenting with that.

Edit: For some reason, the AppGameContainer doesn't seem to have .getCodeBase(); The API says it does. Any idea why or how to get the code base?


Top
 Profile  
 
PostPosted: Sat Apr 14, 2012 10:21 am 
Offline
Regular
User avatar

Joined: Wed Apr 27, 2011 3:29 pm
Posts: 194
Location: United State of California
If you're accessing files that are supposed to be located in your project jar, I believe its improper to make a File object to point to it. Instead, you could get a URL:
Code:
getClass().getResource("test/test.png"))

or an input stream:
Code:
getClass().getResourceAsStream("test/test.png"))


Note that new Image() automatically uses getResourceAsStream() to get the picture file.

_________________
Current Testing Machine:
Windows 7 x64, 4GB RAM DDR3, 3.3ghz AMD Athlon II X3 455, AMD Radeon HD 6800 series.


Top
 Profile  
 
PostPosted: Fri Apr 27, 2012 1:51 am 
Offline

Joined: Mon Apr 09, 2012 6:04 pm
Posts: 20
Well I finally got access to the resources, so technically the game will function on a webpage. The problem now is that I want a list of all the resources so I don't have to manually type in every path for every resource. Is there a way to list all the resources in the directory?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group