Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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] 2 3 ... 31
1  Discussions / Business and Project Discussions / Re: [PAID] Searching for a programming instructor. on: 2014-04-16 01:55:53
He just states that there's a Tile Class somewhere, but I have no idea what's in it? Probably an Abstract class that has thins like "GrassTile", "SandTile" etc that extends it; However I don't really have the slightest idea. This is why I'm willing to pay someone to help me get started.
That's a reasonable question for the Newbie area.

How about starting with this as a preliminary answer: define your Tile class with one property, an instance variable that holds the TerrainType housed in that area, and the related getters/setters.

TerrainType can also be a single class. It could hold a reference to the graphic that needs to be drawn. You make as many of them as are needed so that you have one of each type of terrain in your world. Then, reuse them as you assign them to the Tile class.

Then, make a 2D array of these Tiles, and implement the translation algorithms that the article employs to map X,Y mouse locations to the internal representation.

The render method for the world would inspect the array of Tile, get each TerrainType for that Tile, and employ the translation algorithm to determine where to draw.

Will that get you rolling? Further questions can be posted at the Newbie forum. If you want to mail me a check, though, I'll be happy to provide a name and address.  Wink

I can certainly relate to the sentiment of wanting to have someone to just explain things, I must admit. Have been tempted to ask for tutoring services more than a couple times myself.
2  Discussions / General Discussions / Re: What genre/artists do you listen to while coding? on: 2014-04-16 01:26:25
Quote
chiptune
Does that mean you are using generative composition, a score synthesized on the fly? Or a midi-driven piece that uses wave-table based synthesis?
I'm slowly working towards being able to do this with FM synthesis (but could combine wavetable synthesis). Would be really cool to get some (what I call) "Ligeti" textures (orchestrally dense but used in an ambient way, creating suspenseful textures rather than discernible melodies/harmonies) that could be manipulated via an API. Or "Steve Reich" influenced (thinking "Music for 18 musicians" sort of layerings) controllable via an API.
3  Discussions / General Discussions / Re: What genre/artists do you listen to while coding? on: 2014-04-15 04:57:10
Just watched my first "Resident Evil" picture ever--(from library: "Extinction"). Had to check out Milla's website after that. Did you know she was a musician? There are quite a few links of her demo songs/cuts.

http://www.millaj.com/music/index.shtml

I've only listened to two so far since my computer is partitioned such that the web-viewing side does not have audio (please don't ask). One cut seemed influenced by Sade, the other a bit more in the direction of Bjork. She's pretty good, though maybe hasn't developed as clear a sound/identity as either of these other two. The production quality is good.

And it's Milla Jojovich.  Kiss
4  Game Development / Newbie & Debugging Questions / Re: creating an array of images and setting a timer on: 2014-04-07 02:29:59
Disclaimers...
I did not test this. I don't mean to say that one should do animation this way. I'll let others talk about what is best.

However, for grins, I thought it would still be interesting to see an implementation that does what was requested.

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  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
import java.awt.Graphics;
import java.awt.Image;
import java.util.Timer;
import java.util.TimerTask;

public class SimpleAnimationWithTimer
{

   Image[] images = new Image[2];
   Timer timer = new Timer();
   TimerTask task;
   public volatile int stage;
   
   SimpleAnimationWithTimer()
   {
      task = new SimpleAnimationTask();
   }
   
   public void draw(Graphics g, int xLoc, int yLoc)
   {
      g.drawImage(images[stage], xLoc, yLoc, null);
   }
   
   public void loadImages(String[] imagePaths)
   {
      // to be written
  }
   
   public void startWalkAnimation()
   {
      timer.schedule(task, 0, 500);  // two steps per second
  }
   
   public void stopWalkAnimation()
   {
      timer.cancel();
   }
   
   class SimpleAnimationTask extends TimerTask
   {
      @Override
      public void run()
      {
         stage ++;
         stage %= 2; // mod div by two keeps it in range 0, 1
     }
   }
}


Once the class has been initialized and loaded with the two images, to animate it, you would call the startWalkAnimation() method. The timer local to that object would then flip the state at whatever rate you specify. (I put in 2 changes per second == typical marching tempo.)

The code controlling the main screen would display your pair of images by passing its Graphic object to the draw() method. These draw() calls would be made 60 times per second or at whatever animation rate you are using. For clarity's sake, I put the management of the position of the animation external to its class. Usually if something moves around on the display, you'd put the xLoc & yLoc and movement coding within the object as well, instead of passing the location via the draw() method as done here.

Having a personal Timer is not needed, though. You could also determine the state by a function that is called at the time of display, such as either a calculation based on the current time, or on a count of elapsed frames.

The main issue is how the thread overhead compares to the cost of a method that has to be consulted on a per frame basis. I can see that there might be some appeal to having the code that performs the flip only run a couple times in a given second vs checking whether to flip or not on every frame. Maybe this isn't a terrible way to do the task.

Some folks might object to using the util timer, due to having to misplaced fears about multi-threading. But the very simple and confined usage here shouldn't cause any problems. The actions are background, not part of the rendering process. The use of the volatile keyword helps keep the threads properly aligned.
5  Game Development / Newbie & Debugging Questions / Re: Having trouble with ArrayList on: 2014-04-07 01:07:16
All statements must be in a method body.

Statements can also exist in a static initializer block. However, for that to work in the OP's case, player1 would have to be static, too. The following compiles.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
import java.util.ArrayList;

public class StaticTest
{
   static Player player1 = new Player();
   public static ArrayList<Entity> entities = new ArrayList <Entity>();

   static {
      entities.add(player1);
   }
}

class Player extends Entity
{}

class Entity
{}


But most likely, yes, the right answer is probably to wrap the .add() in a method or constructor.
6  Discussions / Miscellaneous Topics / Re: new computer purchase advice on: 2014-04-04 00:11:31
I'm okay if there are "hijacks" off the topic, as long as it generally stays pertinent to issues concerning purchasing a new computer with an eye towards supporting an Android development environment.

I may just get a Tablet as a first step, as suggested (thanks again for making me aware that this could work!), and and take it from there. It might be possible to push back the purchase of a new computer yet a few more months (with the hope we become a true dual-income family again in the meantime).

Meanwhile, I can switch over to my Ubuntu partition (I am dual-booting anyway) for all Internet access, drop the use of XP in that regard. Pain in the butt, but frugal.
7  Game Development / Newbie & Debugging Questions / Re: Books to read. on: 2014-04-01 07:55:34
I'd strongly recommend checking the many game tutorials on this site! The only Java game programming books I know are 10-years old. There's LOTS of good info in them, but its hard to know, if you are new, what is obsolete or not.

In terms of advancing your general Java skills, my first recommendation is "Java Programming" by Sarang, published by Oracle Press. "Core Java" (Horstmann) used to be my favorite, and it is good, too. But also, the Java Tutorials online are a tremendous resource.
http://docs.oracle.com/javase/tutorial/

You didn't mention having learned about Interfaces yet, or making use of Listeners. I think these are pretty integral to writing well-structured Java. Also, with animation and the need for background or concurrent operations (like playing audio or loading resources) you'll need to understand more about threads. All the things I mention in this paragraph are well covered in the Sarang book I first cited.

I also recommend getting a good book or two on good OOP style (for example, hitting topics of design patterns and of coding practices that emphasize making code readable and easily revisable). What you can learn in a few hours of reading can save you countless hours of later frustration. There are quite a few good books available. I like the author Martin Fowler, for one.
8  Discussions / Miscellaneous Topics / Re: new computer purchase advice on: 2014-04-01 07:21:28
This has been hugely helpful!

I have a couple games and an audio tool that could possibly work as Android apps, maybe even iPad apps. Also am hoping to make a version of the audio tool for iPhone or Android phone, so musicians can run them at rehearsals (for warming up). Most already have a phone of some sort.

Some follow-up questions and replies:

@trollwarrior1
Comment about developers not using an emulator makes sense. I should probably just have an Android tablet of some form to use for running/testing the programs. When I originally Libgdx for use on Eclipse, the instructions included an emulator add-on. But when I tried to run it, loading anything more than a simple program could take as much as 10 minutes or more. It was quite unworkable. I assumed the problem was my old PC, but your suggestion implies its better to just have another working setup and avoid the emulator. (Recommendations?)

@prince  
I have the option to go for either Windows 7 or 8. When you recommended Win7 64-bit, was that over Win 8? I'm told the "System 2" package has NVidia graphics as part of the cpu card. Option exists to upgrade with a higher quality gpu at a later time. (As well as RAM and even replacing the i3 with i5 or i7.)

@gibbo3771
Sounds like great suggestions. I just wish I didn't have to factor in my learning curve.

@Longarmx
Cool resource! I did not know about the recommended power supply calculator. It looks like the system has 125 Watts buffer.

@BurntPizza
More great resources/links! Thank you.

@Riven
SSD sounds fantastic. I did not know these had become a reality in the market place. (Shows how little I pay attention to hardware.) My projects are on a smaller scale, overall, so it will be hard to justify at this time.

***

Based on this feedback, I think I can get some reasonable programming done with their "System 2," with the plan of upgrading on an as-needed basis. Will consult again about best video cards and the like, down the road, as family finances improve (knock on wood) and/or I actually start making some money via selling apps. And hopefully, I won't be going 10 years without upgrading again. We got sort of whip lashed by the recession, took me and my wife by surprise in terms of how long it is lasting.
9  Discussions / Miscellaneous Topics / new computer purchase advice on: 2014-03-31 09:28:49
Would the "system 2" at this site be a reasonable computer for libgdx dev?

http://gcsystem.com/systems.html

I'm on a tight budget, but need an upgrade pretty badly. I like working with the folks at this store--they've been very good about service and warranty over the years.

The computer I currently have:
Pentium 4, 3.2 GHz, 3GB RAM, definitely wasn't up to Android emulation via Eclipse plugins.

From the site:

    ASUS H61M-F
    On-Board W/Audio/VGA/DVI / USB3.0
    4GB DDR3/1333-RAM(UP to 16GB)
    500GB/16M S-ATA3 Hard Drive
    Dual Layer Rewritable DVD/CD
    Mini Tower Case w/350W Power Supply (In-Win Z589BL+)
    USB Keyboard & Mouse(Logitech)
    Windows Win 7-home 64bit OEM or Win-8 64 bit (Upgrade to Pro+$85)
    Upgrade to: P8Q77-M CSM w/HDMI/USB3/RAID +$80

    i3-3240 3.4G/3M cache LGA1155 CPU

But a couple upgrade options are available on the CPU.
10  Games Center / WIP games, tools & toy projects / Re: audio dsp on: 2014-03-22 00:16:12
Are you suggesting that eventually using all those delicious CPU cores for fancy real-time audio processing will never really work and we'll be stuck in single-threaded land forever?  persecutioncomplex

I've read the "Time Waits for Nothing" article and wondered the same thing. It is difficult for me to understand how having one thread do the work of two is more performant than having the two threads that work in parallel but just occasionally have to synchronize.

One thought is that a modern cpu/compiler can more efficiently figure out what, in a single thread, can be handled via a dual process, than when that same work is in two threads that have to interact at certain points. But I don't know if that is a sufficient explanation.

What I've done in response to reading this article is the following:
(1) made a study of functional programming and made an attempt to use things like immutables when possible (I'm thinking of the EventSystem I wrote, where the constituent "AudioCommands" and frame times of AudioEvents are final);
(2) in some instances, programmed out some flexibility that would have required synchronizing or making use of a synchronized collection (e.g., my mixer can only have tracks added or taken away when it is not running);
(3) but also making use of synchronized collections when interacting with the main audio thread: e.g., the collection that holds the Event schedule is a ConcurrentSkipListSet which allows me to add to it without danger of throwing a ConcurrentModificationException);
(4) making use of volatile variables for all "instruction" or "settings" changes to the various effects and synths;
(5) optimized for speed of execution of all code in the main audio loop.

Now, a volatile variable, or a ConcurrentSkipListSet will also block. But the overhead or amount of blocking is going to always be less than the use of Synchronized? I don't know if that is necessarily true.

It is very easy in this business (as with many things in life) to glom onto a principle and overuse it. I wish I had a better understanding of synchronizing and parallel computing, but despite reading "Java Concurrency in Practice" I feel like there is a lot that I am taking on faith.

One thing I'm interested in trying with the audio mixer: fork/join for the separate tracks. But in truth, so little is done in a given frame, that the overhead is probably not justified. This might be a solid argument, though, for having the audio mixer increment by a buffer's amount of frames rather than by single frames.
11  Discussions / General Discussions / Re: Programmer jokes on: 2014-03-18 01:09:57

Busted!
Yes, that was where I first got the programmer/loaf of bread joke. The networking protocol jokes were from reddit, which in turn seems to have been the source for the tickld 20-jokes post.
http://www.reddit.com/r/AskReddit/comments/1h1cyg/whats_the_most_intellectual_joke_you_know/
12  Games Center / WIP games, tools & toy projects / Re: audio dsp on: 2014-03-17 17:16:14
The idea I intended to try next was to build the 'band-limited" square/sawtooth tables from sine waves. The tables are small enough, and it is a one-time event, so the speed of the computation isn't that critical, is it? Or am I off base, conceptually?
13  Discussions / General Discussions / Re: Programmer jokes on: 2014-03-17 02:43:52
A programmer's wife tells him: "Run to the store and get a loaf of bread. If they have eggs, get a dozen."

The programmer comes back with 12 loaves of bread.
14  Discussions / General Discussions / Programmer jokes on: 2014-03-17 02:36:08
I'd tell you a UDP joke, but you might not get it.

********

I prefer IP jokes; its all in the delivery.

********

I could tell you a joke about TCP, but I'd have to keep repeating it until you got it.

15  Games Center / WIP games, tools & toy projects / Re: audio dsp on: 2014-03-16 23:06:27
Wow! I just discovered this thread. Great work! This is something I am passionately interested in myself. I have also been making audio tools, but haven't tackled filters or reverberation yet. I'm pleased to have found this thread and be able to follow along. I probably won't have a lot to contribute, since my background is more as a musician and am couple steps behind on the java and audio engineering expertise.

I'm hot on a project that functions as a "tanpura" but also an intonation-training tool for classical musicians. When it is "done" (i.e., commercially released),  I'm planning on continuing to expand the event-system tools developed for it to support ideas I have for algorithmic composition, generative/dynamic scores for java games.

I haven't opened my audio library yet either, but various "toys" have been posted along the way.

A theremin: http://www.java-gaming.org/topics/java-theremin/24646/view.html -- the biggest challenge was getting the unit to be responsive to the mouse/ui thread. I do plan to redo the wavetable synth sources to eliminate the aliasing (on a long queue of tasks to get to).

A "peaceful brook" demoing a wind-chime using an fm-bell synthesizer, and a continuous clip-slicing playback tool:
http://www.java-gaming.org/topics/what-music-do-you-listen-to-while-you-code/27824/msg/275109/view.html#msg275109 The use of Perlin noise for the randomization on the windchime was silly and inefficient. I have a better version of what I'm calling a "SoundField" tool now for managing background sounds with randomized timing elements.

Am looking forward to further exchange of ideas.

Am curious, what size buffer are you using in passing audio from one unit to the other? I'm simply using a single frame which is a significant inefficiency, but allows for considerably simpler coding. I do use buffering for actual file i/o (e.g., wav playback and SourceDataLine output). But the inner mixing loop and effects processing mostly occurs on a per-frame basis. It works.

Also curious, have you been able to get these tools to work on Android or iOS? I own neither and haven't tried this yet on my own audio library, but the output is just a single, never-ending stream (SourceDataLine) which seems like it should be possible on both system.

Are you using any native code or any libraries other than javax.sound?

My FM synth can either create play in real time or be used to generate DSP data samples required for the upcoming score segments. I'm thinking it might be useful to be able to have the option, allowing one to dynamically optimize according to whether the bottleneck is processing or RAM. Just as much visual/graphic data can be generated at level-transitions, the same could be done with the sound design and musical score.
16  Game Development / Newbie & Debugging Questions / Re: Time to multithread? on: 2014-03-16 06:22:58
Lock-free multi-threaded programming is a different kind of hard, though...

Cas Smiley

But fascinating and kind of fun. I recommend perusing principles of "Functional Programming" for ideas.
17  Discussions / General Discussions / Re: Ever forget how your own code works? on: 2014-03-12 20:55:38
I'm reminded of the adage "a place for everything and everything in its place," a phrase was written by and for grumpy adults who are losing their working memory edge, yes? (I include myself.)

Still, writing easy-to-read-and-understand code pays off big in $$ if you consider that time is money. Depending on the project, more time is spent in maintenance and revision or upgrading than in writing original code. So, it is a skill very much worth developing and much appreciated in a well-run workplace, even if you, personally, have eidetic memory and can currently hold it all in your head.

A similar thing often happens in art & composing, where folks can wonder "how in the world did I do that" and have doubts on being able to rise to the same level again. Then again, there are those that get a process worked out into a formula, and are very productive if not always the most inspired.

I find I get the most forgetful (both housekeys and code) when I am deeply involved in learning new tech or a creative project. I think there must be competition for brain cells or neural connections, that this is a natural aspect of "neural plasticity."

I've read that lots of comments are a yellow flag. If comments are needed, the code isn't self-documenting or the logic is too tricky by half and will leave one vulnerable to overlooks.
18  Discussions / Business and Project Discussions / Re: Looking to create a small dev team on: 2014-02-25 05:06:01
I'm interested in exploring this further.

If it works out, I would be contributing my sound library as well as sound effects and music (I am also a composer). I know it's not usual for the musician to also be a coder. I'm interested, in particular, in game designs where the sound/music elements are "dynamic" rather than the usual SF/X and background.
19  Game Development / Game Play & Game Design / Re: Rougelike fun on: 2014-02-21 02:10:09
I'm interested in hearing more about "rougelike fun".
Am blushing at the possibilities!  Shocked
20  Game Development / Newbie & Debugging Questions / Re: Effecient way to use z-index for 2d games on: 2014-02-21 02:01:53
Roughly how many items are being sorted?

For most situations, I vote with princec's recommendation. But if items are being handled concurrently, you can consider keeping them in a ConcurrentSkipListSet. To do so, you'll have to make a Comparator that uses the Z data.

Quote
This implementation provides expected average log(n) time cost for the contains, add, and remove operations and their variants.
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentSkipListSet.html

I'm using this to store "AudioEvent" objects (custom code I'm writing for my audio library) which can be generated from MIDI data or via game state events. So the list has to allow concurrent access since the audio processing is happening in its own thread and I don't want to create any blocks via synchronization.
21  Game Development / Newbie & Debugging Questions / Re: Trying to set up a class hierarchy on: 2014-02-16 23:09:03
Possibility: have the Player constructor provide either a default place-holder value or null for each Entity attribute that you wish to specify later.

1  
2  
3  
4  
5  
6  
public Player(SpriteBatch spriteBatch, World world, float WORLD_TO_BOX, 
    float BOX_TO_WORLD)
{
    super (null, spriteBatch, world, null, null, null, WORLD_TO_BOX, BOX_TO_WORLD);
    // additional code
}
22  Discussions / Miscellaneous Topics / Re: What is your typing speed? on: 2014-02-12 19:41:36
2nd attempt: 72 wpm with two errors.
It is very much like playing a game.

EDIT: 4th attempt 75 wpm with 0 errors.

I did once have a job as a secretary/word processor. But I must say I'm impressed with the folks who got better than 100wpm! Are you using the Dvorak keyboard?
23  Discussions / General Discussions / Re: Java and Algebra. on: 2014-02-11 21:44:08
but I still get tripped up on some things.
We all do!

Quote
I can't see myself doing anything else when I am older...
It's a big and quickly changing world. There are many possibilities, most of which are not apparent yet. Self-limiting statements like these always throw warning flags for me. Maybe that wasn't your intention.

Trig is definitely helpful for figuring out how to place, draw or move things even for simple games. And algebra is helpful for trig. But algebra is also a pretty wide-ranging subject.

I think if you plan to rely on using 'game engines' for coding, you can probably avoid a lot of math. But you will be limited by the bounds of the engines.

If you want to code without engines, or create an engine or component of an engine, you are going to have to know enough math to at least pick and implement the right "recipes" on an as-needed basis.

If you are in school at the moment and having troubles, it could be a result of difficulty working with a particular teacher or text. A teacher with another style might present the material in a way that works better for you.

Also, math is not something you can learn by only giving it surface or split attention. It is more like a muscle that grows in capability with use. It requires some patience, a willingness to take some time with each step. I think this is probably the case because one is creating new neuronal connections (similar to creating or strengthening muscle mass?). These connections make it easier to "visualize" steps. But those connections and resulting mental skills won't grow unless you actually use them.
24  Discussions / General Discussions / Re: New feature: coding experience on: 2014-02-05 21:15:58
Nice! I often include a line about my knowledge level, as a disclaimer, anyway. I try to just answer questions when I can and not get on people's cases for not "searching" and such, having recently been in the same position myself (without models even for how to search for things, there had to be a first time to learn that this was even possible and effective).

I think the best way to deal with someone you might consider is being lazy or a waste of time is to just ignore them, not berate them. But the people who give others are hard time are just attempting to be "helpful" according to their own lights. To some extent, when asking a question, one can/should separate out useful information from "attitude" that probably says more about the answerer and their life than anything else.

But having this new system should help take out some of the sting, and will prove to be a good addition, I bet.

I'd like to see the label read something like "Java Experience:" or "JExp:" so that it is clear we are not talking about overall experience, but focusing on that experience most relevant to the questions presumably being asked and answered here.
 
I started learning Java part-time about 3 years ago, maybe 4, but have been in and out with programming work since the late 1970's. A lot of the work (paid!) has been at the Microsoft "macro's" level or lower (Paradox, Excel, Access, then VBA for Access). I wouldn't say THAT experience has added much of anything useful in terms of Java expertise. A lot of it had to be unlearned.

Also, there's the two years of FORTH game programming...whatever, and writing a couple games in assembly for glorified calculators around 1980. Really not relevant to much of anything, except an awareness that hardware can matter (or at least, it did at one time). So, I can boast of 30 yrs or be embarrassed by how little I know for having been at this so long. In fairness, most of the time was not full-time programming. So, hmmm, what to put in, must ponder.
25  Game Development / Newbie & Debugging Questions / Re: Shooting towards the mouse on: 2014-01-31 22:46:40
I am noticing that you ARE storing the movement data for the bullet with the Bullet class. The problem is that the information is static. Thus, whatever you last put into those variables will be shared by all instances of that class.

Without having looked at your code too deeply, it seems to me that something as simple as losing the static keywords for the variables and creating individual bullets instead of calling Bullet statically could solve your problem. You might have to write some additional code to manage the bullets and their lifetimes as a collection.
26  Discussions / General Discussions / Re: Anyone played this before? on: 2014-01-29 09:02:10
@ctomni231 -- Impressive high score! Mine is now 1690. I finally got a couple of those big ships, and I can now shoot at ships and boats while descending without (usually) crashing into them. The bouncing on water strategy did not take me very far. Very addictive. What makes it so?

My guesses: you can see the death coming (and say dah!), and it is easy to restart. Also there is a feeling of accomplishment while learning to use the controls, figuring out angles for most accurate shooting. I think there is also a big luck element which leads to wildly varying scores, and the occasional high scores are real goads.

A couple annoyances: I will legitimately knock out a boat or two and it won't end up in the score. Don't know what that is about.

Am starting to like the music a lot more. Will probably hear that stomping beat in my dreams tonight.
27  Discussions / General Discussions / Re: Anyone played this before? on: 2014-01-28 05:45:45
I like the idea about using the water!

I let the plane kind of bounce along in the water, shooting at passing planes. When the boats turn up, I found I can shoot directly at them while lying in the water, shooting horizontally. Just knocked out 5 boats! My high score is now 920.

I couldn't get the knack of shooting at them from above though. Hard to turn in time so as not collide with them!

That music is pretty raw.
28  Java Game APIs & Engines / Java Sound & OpenAL / Re: Paulscode loading from InputStream? on: 2014-01-27 23:56:23
If you know the location of the jar, you can just use it directly.

If not, the following is one technique:

1  
System.getProperty("user.dir");

Nice list of various properties here:
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getProperties%28%29

Here is another method:
1  
2  
     URL url = Location.class.getProtectionDomain()
        .getCodeSource().getLocation();

I've never tried it, but when I did a search, this came up numerous times.
(Search I did was: java find jar location)

With file access outside of the jar, there may be permission issues.
29  Discussions / General Discussions / Re: Anyone played this before? on: 2014-01-27 21:01:16
I like it! I can't seem to take out any of the ships, though. Best score so far a measly 640.
30  Java Game APIs & Engines / Java Sound & OpenAL / Re: Paulscode loading from InputStream? on: 2014-01-27 04:42:28
AudioInputStream is part of javax.sound.sampled. I can't recall how Paul has us load sounds. It's been a couple years since I looked at his library. I've just been using methods based on javax.sound.sampled.

I've been wondering, too, how to do what you are asking about, using LWJGL or LibGDX. My system is too slow to implement Android emulation, so I haven't tested sound coding in that context. But I also wonder if LWJGL & Libgdx make use of javax.sound.sampled for their implementation. I recall someone writing somewhere that this was true, but my memory is shaky and I could have it totally wrong.

Looking at this tutorial: http://www.lwjgl.org/wiki/index.php?title=OpenAL_Tutorial_1_-_Single_Static_Source
something called WaveData is used for loading a sound. By its syntax, it seems to me you could load either from within the jar or not, according to the usual rules of addressing files. But I haven't tested it.


InputStream has requirements for the file (e.g., Marking, Resetting) that are usually not met by audio data files.

I'm assuming you just meant input streaming in a general sense, weren't referring to the specific Java class InputStream.

InputStream methods mark() and reset() only have to provide their described functionality, if markSupported() returns true, which by default it does not.

Ah, I was being sloppy. Further clarifying, according to the comments in the api for AudioSystem.getAudioInputStream(InputStream inputStream)  http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream%28java.io.InputStream%29, this method for loading a file may or may not run the tests Riven mentions. For this reason, I use a URL for the input parameter instead of an InputStream. But some folks prefer to wrap the InputStream in a BufferedInputStream, and this also works.
Pages: [1] 2 3 ... 31
 

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

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (23 views)
2014-04-15 18:08:23

BurntPizza (18 views)
2014-04-15 03:46:01

UprightPath (32 views)
2014-04-14 17:39:50

UprightPath (16 views)
2014-04-14 17:35:47

Porlus (32 views)
2014-04-14 15:48:38

tom_mai78101 (58 views)
2014-04-10 04:04:31

BurntPizza (116 views)
2014-04-08 23:06:04

tom_mai78101 (216 views)
2014-04-05 13:34:39

trollwarrior1 (183 views)
2014-04-04 12:06:45

CJLetsGame (190 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!