Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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
1  Game Development / Newbie & Debugging Questions / Re: I'm desperate on: 2014-10-10 16:53:02
Since you are already familiar with Java, then try finding some simple game video tutorials (like pacman) that walk you through the entire process from start to finish and follow along line by line. This will get you familiar with the concepts that go into a game.

From there, start making very small tests where you implement just one aspect of a game at a time.

Some possible examples:
- Create a simple game loop that simply paints a circle.
- Next make the circle move across the screen from one end to the other.
- Next make the circle detect the edge of the screen and send it back the other direction when it hits an edge.
- Then get input from the user and make the circle move with the arrow keys instead of moving on its own.
Etc.

In just that little bit you've covered a game loop, updating, painting, basic collision detection, user input, etc all key components to creating games.

So instead of focusing on the exhausting task of "making a game" (OMG!!! Shocked) you can think about creating smaller individual puzzles for yourself that you have to solve. Focusing on these simpler tasks will also allow you to search for specific topics and find better explanations and tutorials related to what you want to know. For example, searching for "how to move an object with arrow keys in java" will likely provide much more useful results than "how to make a game in java", which is an extremely broad topic.

Finally, once you start working on more complex games, it's a very good idea to keep creating "side-projects" regularly where you work out a particular task in isolation without trying to figure it out inside of your more complex game. Once you know exactly how it works in isolation, then incorporating it into your actual game will be a whole lot easier.
2  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-10 16:04:13
Just a quick update: I was able to read in all the bytes from the wav file with the LibGDX FileHandle and then maneuver through the header bytes to extract just the audio bytes (using the document from standford I posted before). It works perfectly on both desktop and android, so I can now officially mark this problem solved!

Thanks again for all the help everyone! Smiley
3  Game Development / Newbie & Debugging Questions / Re: I'm desperate on: 2014-10-09 08:05:11
First off, as a semi-noobie to this forum myself, let me just say that you can expect to be treated with utmost respect here on this forum! Smiley So you need not worry about hate mail or having people treat you in an uncivilized manner for asking beginner questions. This place is beyond awesome!

Second, as has been mentioned before, you might be better served getting familiar with Java before diving head first into a game. You say you have a hard time following tutorial videos, but maybe you just need to find the right ones?

TheNewBoston on youtube is awesome for beginners because he assumes you know absolutely nothing and then builds from the ground up. Bucky is a little on the goofy side which makes the videos fun. He does have a tendency to mess up typing/spelling (something he constantly jokes about himself), so be weary of that. lol He has lots of videos on Java and some on game dev.
http://www.youtube.com/user/thenewboston/playlists

This is another series of Java videos that is highly recommended here on this forum. He sells courses on his site, but the intro to Java course is totally free:
http://courses.caveofprogramming.com/course/java-for-complete-beginners/

Once you have a good grasp of the core language, then expanding into more complex gaming topics and graphics will be a lot easier.

And finally, when you do get into developing games, it helped me a lot to simply follow along with tutorials showing how to make simple games like pacman. Even though the app I'm working on has absolutely nothing to do with pacman this really helped in understanding gaming concepts like game loops, painting, sprite animation, etc. then you can just keep getting more and more in depth and complex from there.

Hope that helps.
4  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-09 07:33:24
Thanks BurntPizza!

I'm also hoping to support iOS devices (assuming the LibGDX conversion process works well), so am I safe in assuming that a 3rd party library like musicg wouldn't be able to be converted to iOS via LibGDX?

If so, then would it be a good idea to just read the bytes straight from the wav file (since wav files aren't compressed) using a byte reader for files that android also supports (have to look more into this as apparently android doesn't support java.nio.Files either....go figure! Roll Eyes)? This gives a good description of the layout inside the wav file:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
5  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 07:22:55
Well....after having it work so fantastically on my desktop I tried running it on my Android phone and it crashed and burned!

After some debugging and then some googling I found that Android does not support Java's AudioInputStream! Grrrrrr! That sucks! Huh

I didn't see any kind of LibGDX equivalent to AudioInputStream, so am I going to have to code this separately for each device (android, iOS, blackberry, ect) using native code or is there something else I can do? Thanks!
6  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 02:04:48
Oh wow...that's interesting. Thanks for the heads up BurntPizza, I definitely won't be using asDoubleBuffer() then. Wink
7  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 01:14:50
Niiiiice that is slick! Smiley Thanks BurntPizza, I will give that a go.

Also, it looks like ByteBuffer also has asDoubleBuffer(), so I may even be able to go directly from the byte buffer to the double buffer and bypass the shorts all together:

ByteBuffer.wrap(data).asDoubleBuffer();
8  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-07 00:59:15
Thanks BurntPizza, that was it! Smiley Divided by Short.MAX_VALUE and it is working perfectly now!

Problem officially solved! Thanks everyone, you all are beyond amazing!! Smiley
9  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-07 00:29:09
Thanks philfrei, bypassing the InputStream and getting a File from the LibGDX FileHandle did the trick. Smiley

One last problem I'm having now is when the file plays it just plays a blast of white noise, so I think I'm converting the data from the wav file incorrectly.

The AudioInputStream reads bytes from file and I'm trying to store that into an array of doubles. To do the conversion, I'm storing two bytes into a ByteBuffer and then getting a short back out since a short is 2 bytes, and then I'm casting that to a double to put into the array...it seems like this should work, but maybe this is the wrong way to convert it?

I've also tried reversing the order of putting the bytes into the ByteBuffer (in case I had them backwards), but no change.

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  
   private void readAudioFile(){
      FileHandle fileHandle = Gdx.files.internal("click.wav");        
      File file = fileHandle.file();
      int byteLength = (int)fileHandle.length();
     
      byte[] audioFileBytes = new byte[byteLength];
      audioFile = new double[(byteLength/2)];
     
      try {
         audioInputStream = AudioSystem.getAudioInputStream(file);
         audioInputStream.read(audioFileBytes);
      } catch (UnsupportedAudioFileException e) { e.printStackTrace(); }
        catch (IOException e) { e.printStackTrace(); }
     
      int j=0;
      for (int i=0; i<audioFileBytes.length;){
         audioFile[j++] = bytesToDouble(audioFileBytes[i++], audioFileBytes[i++]);
      }
   }
   
   public double bytesToDouble(byte firstByte, byte secondByte){
      ByteBuffer bb = ByteBuffer.allocate(2);
      bb.order(ByteOrder.LITTLE_ENDIAN);
      bb.put(firstByte);
      bb.put(secondByte);
      return (double)bb.getShort(0);
   }
10  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-06 00:19:06
Hi kingroka123, thanks for the response.

That method works and it plays the sound file, so the Gdx.files.internal("click.wav") method is indeed working. I thought maybe that was the problem since the handle's status was "null" when I debugged and stepped through the program.

For my program I do need to be able to access the audio data from the wav/mp3 file and store the data in an array. I've looked at the LibGDX audio API but didn't see a way to load an audio file from disk and access the data directly. Currently my program generates its own sounds internally (just simple sine wave tones for testing) and stores them in double[]'s, so now I'm trying to load a file from disk and get it in the same format.

I know I can do that with Java's AudioInputStream, but it doesn't seem to work using the LibGDX file handle. Any ideas?

Thanks again!
11  Game Development / Newbie & Debugging Questions / [SOLVED] LibGDX Loading Audio File on: 2014-10-05 22:10:14
Hi all,

I’m trying to load an audio file and then get the audio data as an array using LibGDX, but it is not able to load the audio file. I’m currently using a wav file (I’d like to be able to use mp3’s as well) which is located in the Android assets folder where I have other files for creating text, buttons, etc. and these all work, so it is only the wav file that isn’t loading.

The wav file format is PCM, 44.1kHz, 16bit, mono, little endian.

Here is all the code I have added so far to see if it would pass the wav file to the AudioInputStream without crashing:

1  
2  
3  
4  
5  
6  
7  
try {
   FileHandle fileHandle = Gdx.files.internal("click.wav");        
   InputStream inputStream = fileHandle.read();
   AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);
}
catch (UnsupportedAudioFileException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }


I’ve debugged the program and after the line that should create the FileHandle, the handle’s status is “null”. The Gdx.files.internal() method is what I used to load my files for the graphics and they are working.

When I run the program it crashes on the line:
1  
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(inputStream);


Here is the error message I get:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
java.io.IOException: mark/reset not supported
   at java.io.InputStream.reset(Unknown Source)
   at com.sun.media.sound.SoftMidiAudioFileReader.getAudioInputStream(Unknown Source)
   at javax.sound.sampled.AudioSystem.getAudioInputStream(Unknown Source)
   at com.tekker.audioanimation.SoundFile.readAudioFile(SoundFile.java:61)
   at com.tekker.audioanimation.SoundFile.<init>(SoundFile.java:33)
   at com.tekker.audioanimation.Event.<init>(Event.java:30)
   at com.tekker.audioanimation.AudioAnimation.initArrays(AudioAnimation.java:82)
   at com.tekker.audioanimation.AudioAnimation.create(AudioAnimation.java:67)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)


Any ideas what I'm doing wrong? Thanks!
12  Game Development / Newbie & Debugging Questions / Re: LibGDX Problems Loading Skins on: 2014-09-16 01:54:41
D'oh!!! I knew I had to make sure to save the RAW files, but I guess I botched it somehow and it never occurred to me that I had actually saved them wrong. I re-saved the files and the default uiskin works great now on both desktop and android with the files in the Android "assets" folder. Thanks UprightPath and Grunnt you guys are awesome! Smiley


*** EDIT *** Never mind on the button problem, I just figured out what I was doing wrong trying to load the buttons.

The button pack has to be loaded as a TextureAtlas, not a Skin!

This was wrong:
1  
Skin skin = new Skin(Gdx.files.internal("button.pack"));


This is correct:
1  
2  
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("button.pack"));
Skin skin = new Skin(atlas);


I think I'm good to go....for now at least! Wink Thanks again for your help!
13  Game Development / Newbie & Debugging Questions / Re: LibGDX Problems Loading Skins on: 2014-09-15 02:24:41
Hi UprightPath, thanks for the reply.

Here is a specific example that doesn't do anything except try to load a skin and it still crashes:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
package com.tekker.animationattempt;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class AnimationAttempt extends ApplicationAdapter {
   Skin skin;
   
   @Override
   public void create () {
      skin = new Skin(Gdx.files.internal("uiskin.json"));
   }
}


With the files inside of the Android project "assets/data" folder, it runs for the desktop version and displays a blank screen as expected...the weird part is that I pointed the desktop version to the Android "assets" folder, not "assets/data". So I'm not actually sure why this works for the desktop version, but it does. However it crashes for the android version.

Here are the errors from the Android LogCat:

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  
09-14 19:00:27.934: E/AndroidRuntime(13801): FATAL EXCEPTION: GLThread 10870
09-14 19:00:27.934: E/AndroidRuntime(13801): Process: com.tekker.animationattempt.android, PID: 13801
09-14 19:00:27.934: E/AndroidRuntime(13801): com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:96)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:73)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.tekker.animationattempt.AnimationAttempt.create(AnimationAttempt.java:12)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
09-14 19:00:27.934: E/AndroidRuntime(13801): Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.utils.Json.fromJson(Json.java:662)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:94)
09-14 19:00:27.934: E/AndroidRuntime(13801):    ... 5 more
09-14 19:00:27.934: E/AndroidRuntime(13801): Caused by: com.badlogic.gdx.utils.SerializationException: Error parsing file: uiskin.json
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:77)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.utils.Json.fromJson(Json.java:660)
09-14 19:00:27.934: E/AndroidRuntime(13801):    ... 6 more
09-14 19:00:27.934: E/AndroidRuntime(13801): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: uiskin.json (Internal)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.files.FileHandle.reader(FileHandle.java:164)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.utils.JsonReader.parse(JsonReader.java:75)
09-14 19:00:27.934: E/AndroidRuntime(13801):    ... 7 more
09-14 19:00:27.934: E/AndroidRuntime(13801): Caused by: java.io.FileNotFoundException: uiskin.json
09-14 19:00:27.934: E/AndroidRuntime(13801):    at android.content.res.AssetManager.openAsset(Native Method)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at android.content.res.AssetManager.open(AssetManager.java:316)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at android.content.res.AssetManager.open(AssetManager.java:290)
09-14 19:00:27.934: E/AndroidRuntime(13801):    at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
09-14 19:00:27.934: E/AndroidRuntime(13801):    ... 9 more


Now if I move all of the files for the uiskin out of the Android "assets/data" folder and place them in just Android "assets" (then refresh the files in Eclipse and do Project->Clean for all projects) I get this error on the desktop version:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: uiskin.atlas
   at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:187)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
   at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:69)
   at com.tekker.animationattempt.AnimationAttempt.create(AnimationAttempt.java:12)
   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: Invalid line: <html lang="en" class="   ">
   at com.badlogic.gdx.graphics.g2d.TextureAtlas.readTuple(TextureAtlas.java:443)
   at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:115)
   ... 7 more


The Android LogCat gives this error:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
09-14 19:13:54.130: E/AndroidRuntime(16053): FATAL EXCEPTION: GLThread 10990
09-14 19:13:54.130: E/AndroidRuntime(16053): Process: com.tekker.animationattempt.android, PID: 16053
09-14 19:13:54.130: E/AndroidRuntime(16053): com.badlogic.gdx.utils.GdxRuntimeException: Error reading pack file: uiskin.atlas
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:187)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.scenes.scene2d.ui.Skin.<init>(Skin.java:69)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.tekker.animationattempt.AnimationAttempt.create(AnimationAttempt.java:12)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1520)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
09-14 19:13:54.130: E/AndroidRuntime(16053): Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Invalid line: <html lang="en" class="   ">
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas.readTuple(TextureAtlas.java:443)
09-14 19:13:54.130: E/AndroidRuntime(16053):    at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:115)
09-14 19:13:54.130: E/AndroidRuntime(16053):    ... 8 more


I believe the problem I'm having is in the initial directory setup and getting the Gdx.files.internal() method to find my files and not necessarily the actual code itself. I've seen several examples that use the Gdx.files.internal() method but I can't seem to get it to work consistently, so I think there is something else that I'm missing.

Thanks again!
14  Game Development / Newbie & Debugging Questions / [solved] LibGDX Problems Loading Skins on: 2014-09-15 01:04:14
Hi all,

I’m having some issues getting skins to load into my LibGDX program. I was able to get the default program to work that displays the badlogic.jpg image, but everything else I’ve tried to do using skins has been less successful.

I’m new to LibGDX and still learning, but from my understanding all images have to be placed under the Android project and I’ve tried placing files in the Android “assets” folder and I’ve also tried placing them in the “assets/data” folder (saw this mentioned on stackoverflow). In Eclipse I have pointed the desktop application to use the Android assets folder.

When trying to create a label using the uiskin the Android version gives an error on this line when trying to load the uiskin.json, however it does work on the desktop version.
skin = new Skin(Gdx.files.internal("uiskin.json"));

The button.pack I created won’t load on either the desktop or the Android version.
skin2 = new Skin(Gdx.files.internal("button.pack"));

As far as I can tell I have all the files that it needs to load these skins. For the uiskin I downloaded the 5 necessary files (default.fnt, default.png, uiskin.atlas, uiskin.json, and uiskin.png) and for the button I’ve gone through the steps of creating a 9-patch and then the button pack.

I haven’t been able to find anything that really spells out clearly where to put these files and how to load them in yet.

For example, the documentation for the Gdx.files.internal() method states:
“Convenience method that returns a Files.FileType.Internal file handle.”
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Files.html#internal-java.lang.String-

And for Files.FileType.Internal file handle:
“Path relative to the asset directory on Android and to the application's root directory on the desktop. On the desktop, if the file is not found, then the classpath is checked. This enables files to be found when using JWS or applets. Internal files are always readonly.”
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Files.FileType.html#Internal

This states the path is relative to the “assets” folder, however when I tried putting the default uiskin in the “assets” folder it didn’t load for the desktop, but when I put it in the “assets/data” folder it did load. Android didn’t load at all, whether I had the files in “assets” or in “assets/data”. However, running the default program with the badlogic.jpg image did work with it placed in the “assets” folder for both desktop and Android.

I’ve looked at the documentation and other tutorials, but it’s not coming together just yet. Can anyone break down the process of loading skins a more than the existing documentation? I’d greatly appreciate it, thanks! Smiley
15  Games Center / WIP games, tools & toy projects / Random Chord Progression Generator on: 2014-09-01 22:24:59
This is a project I completed several years ago as my final project in college. It was originally created as a web applet, but given the current problems running Java applets I just spent a little time today and converted it over to an application so I could upload it again.

The Random Chord Progression Generator was designed to be an inspirational tool for songwriting and a practice aid for developing musicianship skills. It provides different modes and settings that cover a wide range of skill levels from complete beginners to advanced musicians.

This chord progression generator is different from the ones that I have seen because it uses music theory to randomly generate 'good' sounding progressions instead of using a set of pre-determined progressions that you choose from or randomly picking chords from a key and putting them together (although there are settings for that too, as well as settings for generating chromatic progressions that don't follow a key at all).

No theory is involved in the addition of the chord extensions however, the extension is simply added at random if one or more of the extension buttons are pressed. So if you have several of the extensions enabled you may get some very strange sounding chords and progressions.

Enjoy! Smiley

Download JAR File:
http://www.java-gaming.org/user-generated-content/members/293272/randomprogressiongenerator.jar

16  Game Development / Newbie & Debugging Questions / Re: Where should a Java noob learn game programming? on: 2014-09-01 17:30:55
I recently found this amazing resource for written tutorials on nearly every programming language imaginable:
http://www.tutorialspoint.com/

For certain languages (like Java) it actually has a built in IDE right into the website so you can type and run the examples as you are working through the tutorials. That is just brilliant IMO! Smiley

And another plus for Bucky's Room (aka The New Boston) Bucky is awesome!
17  Game Development / Newbie & Debugging Questions / LibGDX Eclipse Setup Issues on: 2014-09-01 05:54:56
Hi all,

I'm in the process of moving over to LibGDX (based on several recommendations here) and I'm having some issues getting it setup in Eclipse.

I haven't been able to get it to work yet for android and in the process of trying to figure that out I think I broke the desktop version too... Huh I have no idea how I did it, but I think I deleted the DesktopLauncher setting under "Run" --> "Run Configurations..." because now underneath of "Java Application" it says "New_configuration" instead of "DesktopLauncher". I have tried creating a new LibGDX project with Gradle and I also deleted the entire Eclipse folder (since it doesn't actually install) and unzipped it again....but that setting doesn't come back. Is there anything else I can do to get it back?...I'm at a loss here.

The other problem that I've been trying to fix is Android has several errors in the AndroidLauncher:
* android.os.Handler cannot be resolved.
* com.tekker.guitest.GuiTest cannot be resolved
...and a couple others.

From my understanding it's some kind of issue with the Android SDK. But all of the "fixes" I found weren't working...
Right-click android project --> properties --> Java build path --> Order and export...all of those check boxes were already checked
I also tried downloading the ADT Eclipse plugin, but that didn't fix it either.

I do have the Android SDK installed and I pointed to it when creating the project with Gradle.
I also downloaded Samsung Kies for the USB driver, so I could plug my Galaxy S4 phone in and use it with Eclipse.

Any help in getting these issues resolved would be greatly appreciated. Smiley
18  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-17 01:22:32
Thanks BurntPizza! If there is no significant difference for compatibility with LibGDX, then from searching for IDE comparisons in general (not related to LibGDX) I've seen that Eclipse is more widely used, so I will probably go with that one then. Smiley
19  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-17 01:10:55
gouessej,

So basically, it sounds like LibGDX combines a variety of different existing tools together under "one roof" so to speak and allows them all to be used from a single code base? Is that correct?


Also, one more small question...

Is there a preferred IDE for use with LibGDX? For example, when I asked this question about Codename One on their forum, the developer specifically stated to use NetBeans that they use it and they tended to release more updates for it and it worked better overall with Codename One. Is there a similar preference for LibGDX? I have limited experience with both NetBeans and Eclipse, so I have no real personal preference either way. Which ever one has better LibGDX integration or even has more LibGDX tutorials available...I'll go with that one. Smiley

Thanks again!
20  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 23:48:36
BurntPizza,

YES! Scene2D.ui that's the one! Thank you so much.

I guess that's what I need is to find some good tutorials on Java --> LibGDX equivalents. Such as, are you looking for a JButton? Use LibGDX Scene2D.ui Widgets Button instead. Wink

I had no idea LibGDX was so awesome! Thank you SHC, gouessej, and BurntPizza for pointing me in this direction. Smiley
21  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 23:33:48
Thanks BurntPizza!

Do you know if there is another place where they list the standard Java libraries that is guaranteed to be supported by LibGDX? The LibGDX API only includes their libraries and doesn't include anything from the standard Java API (which is why I didn't know they actually did support Java standard libraries). I just want to make sure I don't end up mixing things that can't be mixed, like for example you said not to use AWT and Swing, so I want to make sure I'm not doing weird things like trying to use basic containers like JFrames to enclose the LibGDX animations if that is not going to work.

Thanks again! Smiley
22  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 23:23:27
BurntPizza,

Wow!!! Shocked I had no idea LibGDX supported the entire Java library otherwise I would have gone this route a lot sooner. Looking at the info you posted, RoboVM is how they convert to iOS? So I assume they have other tools they use to convert the Java library to the other platforms as well since it also supports Android, Blackberry, and HTML5?

I think I'm sold on LibGDX! This sounds amazing. Smiley
23  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 22:54:16
Hi BurntPizza, thanks for the response! Smiley

In regards to point 3 about using the standard library with libGDX...does this include converting to mobile devices? If so, how does the entire Java library get converted to mobile devices? From looking into Codename One you had to stick to their API in order for the code to be translated to the various devices. Is this the same with LibGDX or do they support converting the entire Java library? If they do, then I am totally SOLD on LibGDX!!! Smiley

Thanks again!
24  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 22:41:07
Hi gouessej,

I’d like my app to be supported by as many devices as possible, so the number of devices that an API supports is something I’m taking into consideration. However, it seems like I may not get the performance that I want out of standard Java and Codename One, and LibGDX does support everything else that Codename One supports minus Windows Phone...so the tradeoff might be worth it.

Although, I googled LibGDX to Windows Phone and I found a forum post talking about the possibility of going from LibGDX to HTML5 and then using PhoneGap to convert the HTML5 to Windows Phone...that’s certainly taking the scenic route, but maybe something like this would work?

For my metronome I shouldn’t need any kind of 3D animations. I have very basic animation needs really, just a few displays keeping a count of the current beat and 2D animations of an analog-style metronome.

I’ve looked a little harder at the LibGDX API and holy smokes it is totally different! lol It kind of feels like learning a brand new language, I didn’t even see basic java components I need like ArrayLists and such. I believe there are lists in LibGDX, but I just need to learn the new terminology now.

Thanks again!
25  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 11:25:06
Hi gouessej, thanks for the reply! Smiley

Yeah, the server builds on Codename One is certainly a drawback. I wasn't looking forward to that for sure especially if the whole process takes a while to get your code back from their server. Huh

I've done a little bit of research into LibGDX and I saw that it does a similar thing to Codename One in that it also writes native code for mobile devices. I wasn't able to find much in the way of direct comparisons to Codename One other than a general mention that LibGDX is geared more towards games and Codename One is geared towards applications...but I'm not sure what specifically that involves. I do know they have very different API's just from a quick glance at them. I was originally leaning more towards Codename One still because it's API was closer to Java SE, but now I'm sensing that may not be such a good thing. LOL

One other thing I noticed is that LibGDX doesn't appear to support Windows Phone where Codename One does. I don't really know how many people use Windows Phones, but maybe this would be a worthwhile tradeoff if the overall program would end up being a lot better if done in LibGDX?

I will give LibGDX a more solid look now that it is appearing this may be the better route to go in.

Thanks again! Smiley
26  Game Development / Newbie & Debugging Questions / Re: Game Loop Falling Behind on Slower Machines on: 2014-08-16 10:25:27
Hi SHC, thank you for your response. Smiley

The method I’m using now was worked out in another thread I had started here...which is rather long. lol
http://www.java-gaming.org/topics/double-buffering-with-a-jpanel/33983/view.html

I wasn’t aware that swing was going to be such a problem performance wise, that’s a real bummer! Sad

I don’t know that I can use any 3rd party libraries because I’m going to be using Codename One for developing my program on mobile devices, which uses their own Java API that is translated to native code for various mobile devices (Android, iOS, Windows Phone, Blackberry, etc). Everything I’ve been working on in my Java prototype I’ve been checking against the Codename One API to make sure the classes I use are also supported in Codename One.

I searched the Codename One API for “BufferStrategy” and it does not appear that this is supported in Codename One. Here is the Codename One API:
https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/index.html

Essentially what I need in my metronome are setting controls, such as text fields to enter numerical values, buttons (start/stop, tap tempo, etc), sliders (for tempo, volume, etc). Then I will have the visual display which will involve the beat counters (which is also changing color currently) and sprite animations. That’s about it!

It seems I need a mix of swing components and graphics (for animation) and not many tutorials seem to cover how to do all of this, which I think is why I’m getting so stuck on this. I’m usually pretty good at finding information, but this has been difficult finding anything close to what I need. Your article is about the only tutorial I’ve seen that goes into this kind of thing. However, you (and the article you posted) don’t actually recommend using swing at all for games...so that also complicates things.

If I was just sticking with Java then using 3rd party libraries wouldn’t be so much an issue. But I don’t think I’d be able to get them to work with Codename One when I move to mobile unfortunately.

So given all of these things, what seems like the best path forward? I’ve re-written my graphics code several times starting from complete scratch and it seems each time I try something different I still end up running into some kind of road block. I was really hoping this latest one would be more easily fixed with some tweaks to my game loop, but if this is still not the best route to go, then I’d rather do it a better way.

Is there another route I can go implementing a double buffer on my own? I read your article and it sounds like BufferStrategy essentially chooses the best method between double buffering or page flipping...so couldn’t I implement a double buffer myself using other Java components (which would be supported by Codename One) instead of relying on BufferStrategy? This is essentially what I started out trying to do originally in my other thread I posted above, but my method was not successful at all.

Thanks again!
27  Game Development / Newbie & Debugging Questions / Game Loop Falling Behind on Slower Machines on: 2014-08-16 06:18:08
Hi all,

I’m having problems where my game loop falls behind on slower machines and is not able to keep up with the frame rate I have set. I’m working on a metronome application which I will be moving over to mobile devices, so having this program run on slower devices is very important as I want it to work well for anyone who uses it.

This code runs flawlessly as long as the machine is fast enough to keep up. I ran it for close to 20 minutes or so on a fast laptop and the visual stayed in perfect sync with the audio, no problems at all.

I’m using JLabels and sprite sheets for my animations, which as I understand means that I can’t use some of the fixes I’ve found for handling this problem on slower machines. Methods like variable frame rates or changing how far objects move during each update based on how fast the computer moves through the loop seem like they require motion to be based on physics calculations instead of sprite sheets.

I’ve tried a few different methods using a constant frame rate. Initially I tried using the Util Timer, but this was really bad on the slow machine and I had no way of allowing it to skip ahead when it fell behind since it does all the timing stuff itself. Then I tried my own version of checking the system time and checking to see if it has time to spare to sleep or if it needs to rush ahead by skipping over the paint method...this worked a little better, but would cause glitches in the graphic where it would freeze for a bit and then start moving again. Also, even when it was moving smoothly the timing was off from the audio.

The current method I’m using now is one I found in this article:
http://entropyinteractive.com/2011/02/game-engine-design-the-game-loop/
This also used the technique of skipping the paint method, and so far this method seems to produce the smoothest animations (no long freezing glitches), but this still doesn’t keep time correctly with the audio on slower machines.

The only change I made to the method used in the article is I removed the option to reset the nextTime variable if it falls too far behind. I have two frame counters going, one on the audio side and one on the visual side and it seems like if I were to reset nextTime on the visual side that would cause it to simply drop those frames instead of trying to make them up. Thus the visual frame counter would never catch back up to the audio’s frame counter and the two would be permanently out of sync.

Here’s the entire working example which I posted to pastebin in case anyone wants to run my code and/or tweak it.
http://pastebin.java-gaming.org/7bb7d715d0b13

And here is the animation I made for it:
animation.jpg
http://media602.dropshots.com/photos/670604/20140816/b_021821.jpg

Here is just the visual loop part of my code, where I believe the problem is. Thanks! Smiley

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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
   // LOOP
   public Runnable loop = new Runnable(){
      public void run(){
         nextTime = System.currentTimeMillis();
         
         while (isPlaying){
            currentTime = System.currentTimeMillis();
           
            if (currentTime >= nextTime){
               update();
               nextTime += targetLoopDelay;
               
               if ((currentTime < nextTime) || (skippedFrames > maxSkippedFrames)){
                  edtPaint();
                  skippedFrames = 1;
               }
               else{
                  skippedFrames++;
               }
               
               frameCount++;
            }
            else{
               sleepTime = (nextTime - currentTime);
               try {
                  Thread.sleep(sleepTime);
               } catch(InterruptedException ie){}
            }        
         }
      }
   };
   
   // UPDATE
   public void update(){
      for (int i=0; i<2; i++){
         updateAnimation(i);
         updateBeatDisplay(i);
      }
   }
   public void updateAnimation(int i){
      if (frameCount >= animationFrame[i]){            
         animationPanel[i].setSubImage(imageIndex[i]);
         
         imageIndex[i] += rightDirection[i] ? 1 : -1;
         if (imageIndex[i] == 0) {
            rightDirection[i] = true;
         }
         if (imageIndex[i] == 8) {
            rightDirection[i] = false;
         }
         
         animationFrame[i] += (long)(frameRate / 8);
         // division rounding fix
         if (frameCount % 25 == 0){
            animationFrame[i]++;
         }
      }
   }
   public void updateBeatDisplay(int i){
      if (frameCount >= beatDisplayFrame[i]){
         currentColor[i] = (int)(labelIndex[i] % 2);
         currentCount[i] = (int)((labelIndex[i] % 4) + 1);
         labelIndex[i]++;
         
         beatDisplayFrame[i] += frameRate;
      }
   }
   
   // PAINT
   public void edtPaint(){
      final int[] finalCount = currentCount;
      final int[] finalColor = currentColor;
     
      SwingUtilities.invokeLater(new Runnable(){
         public void run(){
            for (int i=0; i<2; i++){
               paintAnimation(i);
               paintBeatDisplay(i, finalCount, finalColor);
            }
         }
      });
   }
   public void paintAnimation(int i){
      animationPanel[i].repaint();
   }
   public void paintBeatDisplay(int i, int[] finalCount, int[] finalColor){
      beatDisplay[i].setText(""+finalCount[i]);
      beatDisplay[i].setBackground(colors[finalColor[i]]);
   }
28  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 22:03:27
Ok, thanks a lot BurntPizza! Those are great things to be on the look out for. I will say that most of them were neglected only because this was a quick example to post on the forum and not things I intend to do in my real program. I did a lot of hacking, pasting, and moving things around so sometimes I didn't correct every detail just for the sake of time.

Thank you again for your help! I'm really glad I found this forum, you all are awesome! Smiley
29  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 20:58:48
Alright, thanks a lot BurntPizza!

I'm currently using a very simple Java IDE called jGrasp. When I start working on my actual program I'll be using NetBeans since that was recommended for use with Codename One, does NetBeans have a similar kind of auto-formatting feature? And just so I'm aware of them, what kinds of formatting issues have you noticed in my sample code?

Thanks again for your help! Smiley
30  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 19:54:09
BurntPizza,

Here's an updated version using multiple frames and the method you suggested for switching directions.

I also tweaked it so it's more like an "game loop" with an update and edtPaint methods. One thing I've noticed now is that I'm resetting the background color to the same color for the labels as well as redrawing the same image on the frames where the visuals don't change. Would it be more efficient to set a flag and check to see if it these items need to be updated before setting them again or is it ok to do this kind of constant updating on each frame on the edt?

I just want to make sure I'm not setting myself up for problems down the road as I started adding more stuff to it.

Thanks again!

Test.java
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  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

import java.awt.image.*;
import javax.imageio.ImageIO;
import java.io.IOException;

public class Test extends JFrame{
   JPanel panel = new JPanel();
   final JLabel label1 = new JLabel("Label 1");
   final JLabel label2 = new JLabel("Label 2");
    AnimationPanel animationPanel;
   
   final Color[] colors = new Color[] { Color.green, Color.yellow };
   final int[] position = { 100, 300 };
   
   int delay = 4;  
   int count = 0;
   int labelIndex = 0;
   
    private BufferedImage animation;
   
   boolean rightDirection = true;
   int currentImageIndex = 2;
   
   public static void main(String[] a) throws InterruptedException {
      Test test = new Test();
   }
   
   public Test() throws InterruptedException {
       try { animation = ImageIO.read(getClass().getResource("dot.jpg")); } catch (IOException ioe) { ioe.printStackTrace(); }
      animationPanel = new AnimationPanel(animation);
      animationPanel.setMinimumSize(new Dimension(400,100));
      animationPanel.setPreferredSize(new Dimension(400,100));
     
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(410, 300);
      setLocationRelativeTo(null);
     
      panel.setSize(new Dimension(400, 400));
      add(panel);
     
      label1.setMinimumSize(new Dimension(100,100));
      label1.setPreferredSize(new Dimension(100,100));
      label1.setOpaque(true);
     
      label2.setMinimumSize(new Dimension(100,100));
      label2.setPreferredSize(new Dimension(100,100));
      label2.setOpaque(true);
     
      panel.add(label1);
      panel.add(label2);
      panel.add(animationPanel);
     
      setVisible(true);
     
      loop();      
   }
   
   public void loop() throws InterruptedException {
      while (true) {
         update();
         edtPaint();
         Thread.sleep(16);
      }
   }
   
   public void update(){
      if (count % (int)(delay/4) == 0){
         animationPanel.setSubImage(currentImageIndex);
         
         currentImageIndex += rightDirection ? 1 : -1;
         if (currentImageIndex == 0) {
            rightDirection = true;
         }
         if (currentImageIndex == 4) {
            rightDirection = false;
         }
      }
     
      if (count % delay == 0){
         labelIndex++;
      }
     
      count++;
   }
   
   public void edtPaint(){
      final int li = labelIndex % 2;
     
      SwingUtilities.invokeLater(new Runnable(){
         public void run(){
            label1.setBackground(colors[li]);
            label2.setBackground(colors[li]);
            animationPanel.paintSubImage();
         }
      });
   }
}


AnimationPanel.java
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  
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

public class AnimationPanel extends JPanel{
   BufferedImage img;
   BufferedImage subImg;
   
   public AnimationPanel(BufferedImage imgIn){
      img = imgIn;
      setLayout(null);
   }
   
   public void setSubImage(int frameIn){
      subImg = img.getSubimage(400*frameIn, 0, 400, 100);
   }
   
   public void paintSubImage(){
      repaint();
   }
   
   public void paintComponent(Graphics g){
      g.drawImage(subImg, 0, 0, null);      
   }
}


dot.jpg
Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (44 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!