Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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
1  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!
2  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!
3  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
4  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

5  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!
6  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
7  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
8  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!
9  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
10  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
11  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
12  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!
13  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!
14  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
15  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!
16  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]]);
   }
17  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
18  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
19  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
20  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 16:07:40
Thanks BurntPizza!

I just tried re-working my original single sprite sheet example (using a BufferedImage) so I could post the code I was trying and I actually got it working this time!!! Smiley

Before I was trying to do it all in a single file and I calling repaint() from within the EDT, but it wasn't working. So instead I tried creating a separate animation JPanel class and this method works now. I’m not sure exactly what I was doing wrong before...but for whatever reason, starting over almost from scratch I finally got it!

Would this method be ok to use for animating more frames?

Thanks again!

[EDIT] CODE UPDATED! SEE NEXT POST...
21  Game Development / Newbie & Debugging Questions / Re: requst for newbie overview tutorial on porting options on: 2014-08-03 15:17:29
Looking through the libGDX api, I see what you mean about the graphics being very different philfrei.

Codename One maybe a better option then, it uses the standard Java graphics options.
https://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/com/codename1/ui/Graphics.html


I've tried to find some comparisons between these two, but not much luck on a detailed feature comparison. A basic platform difference is Codename One supports Windows Phones where libGDX doesn't, and libGDX supports HTML5 where Codename One doesn't. Other than that I did find a brief mention that libGDX is geared towards "games" and Codename One is geared towards "applications". Unfortunately, there wasn't any more information given than that...so I'm not exactly sure what specific differences that includes.

For me, I'll probably stick with my original plan of using Codename One. I'm very new to the graphics end of things and I'd rather not have to start over and learn an entirely new platform once I get my basic Java prototype finished. I'll just have to deal with the inconvenience of having to upload/download builds to their server.
22  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 14:23:23
SHC,

D’oh! Sorry about that, that was my bad! I didn’t want to create a bunch of new topics on the forum over this so I posted my updated question on the same topic. I just edited the original post to notify you all about the slightly changed topic. Smiley


BurntPizza,

Holy smokes, that is awesome! Grin Wow, I have a lot to learn on this stuff...I spent days trying to get those two stupid dots to move back and forth and you cranked out that awesome animation within the hour. lol

When I do get to making the swinging metronome animation, I would like to use images however rather than drawing with graphics so I can make the animation look “pretty” in photoshop. It’ll probably end up looking something like this...although I’ll probably make my own “less realistic” looking version.


Here is a mobile metronome program that is similar to the kind of animation style that I’m shooting for:
https://www.youtube.com/watch?v=X8zUw1BzVd8

I think I could get something like this to work with the “setIcon” method that I used above, but I don’t know if that’s a good method to use for animation as far as speed, smoothness, etc...I’ve never seen that used in any of the animation tutorials I’ve looked at, so I’m thinking this probably isn’t a recommended method.


Thanks again!
23  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-08-03 00:22:17
Hello again,

I have one more question...

I used BurntPizza’s example, tweaked it a bit and added an animation onto it using jpg’s. For my metronome program I’d also like to add a “swinging” metronome animation so I’m trying my hand at getting some kind of simple animation (only two frames) going along with updating the JLabels.

The only way I could get the animation to switch at the same time as the other JLabels was to use two separate jpg images, load them as ImageIcons, and then add them to a JLabel by calling setIcon in the invokeLater method. This method does work, but since I’m not experienced in animation I just wanted to make sure that this was an acceptable method to use for animation...or would I be better off using another method?

I did try the single “sprite sheet” method at first, but from the tutorials and examples I looked at this involved drawing inside of the paintComponent method and I wasn’t able to figure out how to get it that to work along with my JLabels. So I tried the ImageIcon method and that was fairly easy to get working.

Here is what I was able to get working...am I on the right path here? Thanks! Smiley

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

public class Test extends JFrame{
   JPanel panel = new JPanel();
   final JLabel label1 = new JLabel("Label 1");
   final JLabel label2 = new JLabel("Label 2");
   JLabel animationLabel = new JLabel();
   
   final Color[] colors = new Color[] { Color.green, Color.yellow };
   final int[] position = { 100, 300 };
   
   int count = 0;
   int index = 0;
   
   ImageIcon[] animation = new ImageIcon[2];
   
   public static void main(String[] a) throws InterruptedException {
      Test test = new Test();
   }
   
   public Test() throws InterruptedException {
      animation[0] = new ImageIcon(getClass().getResource("dot1.jpg"));
      animation[1] = new ImageIcon(getClass().getResource("dot2.jpg"));
     
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setSize(410, 300);
      setLocationRelativeTo(null);
     
      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);
     
      animationLabel.setMinimumSize(new Dimension(400,100));
      animationLabel.setPreferredSize(new Dimension(400,100));
      animationLabel.setOpaque(true);

      panel.setSize(new Dimension(400, 400));      
      panel.add(label1);
      panel.add(label2);
      panel.add(animationLabel);
     
      add(panel);
      setVisible(true);
     
      while (true) {
         if (count++ % 30 == 0) {
            final int i = index % 2;            
            SwingUtilities.invokeLater(new Runnable(){
               public void run(){
                  label1.setBackground(colors[i]);
                  label2.setBackground(colors[i]);
                  animationLabel.setIcon(animation[i]);
               }
            });
            index++;
         }
         Thread.sleep(16);
      }
   }
}


And here are the two jpgs I used:

dot1.jpg


dot2.jpg
24  Game Development / Newbie & Debugging Questions / Re: requst for newbie overview tutorial on porting options on: 2014-07-30 17:57:10
BurntPizza,

Interesting...libGDX, was not one of the options I looked into. I will have to look into that more and see. Looks quite promising after an uber fast google search.

How is the building process? Having to upload/download builds to/from the Codename One servers was really the only issue I had from looking into Codename One. But I haven't spent any time actually working with it yet screwing around with their GUI builder...which is pretty slick! Smiley
25  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-07-30 17:45:18
To everyone mentioning the EDT,

Ahhhhh, yeah! That's much better than the hack job that I was trying to do! Smiley

So let's see if I've worked this through correctly...instead of directly changing the text and background in my update method, I'd instead set a Boolean (to test whether or not to change the JLabel), Color, and String (which would both be sent to the JLabel) and then call another method which would use these variables to update the JLabel via the EDT. Correct?


BurntPizza,

Yeah, your example was pretty close to the delay I was getting, sometimes mine would be a little more actually. I also had to change your colors to alternate between yellow and green. The grey and white actually didn't show the delay as well.

I ran your code on the EDT (like you posted later) and I even increased the delay...this works PERFECT no delay at all!


KevinWorkman,

Wow, that's some serious seizure inducing flashing going on there! Shocked LOL

I believed you that they're in sync, but I took a screen shot anyways. Grin It was perfect as expected!


Thank you all again everyone for your awesome responses. This helps immensely!!!
26  Game Development / Newbie & Debugging Questions / Re: requst for newbie overview tutorial on porting options on: 2014-07-30 16:17:48
trollwarrior1,

They say it will always be free. Smiley

"Our client side product is 100% free and open source and will always remain as such. We also offer free & community accounts for basic usage, this free account can be used to create commercial royalty free/ad free applications."
http://www.codenameone.com/pricing.html

I have found some blogs from searching google where they walked you through how to do offline builds with Codename One, at least on Android and iOS. But Codename One says they don't give support for offline builds because they are difficult to do.

I'm not sure why this is so different from other mobile dev tools. Codename One is certainly doing a lot more by developing for every mobile platform, but as to HOW they compile and all that...I don't know. That would be a good question for their forum.
27  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-07-30 15:54:17
BurntPizza, these shorter code samples don't really show the problem, but my actual metronome app has a lot more code in between changing the display. I shortened this example down to the bare essentials of trying to get the double buffering to work. I didn't think anyone would want to sort through my current 9 files of code. Cheesy I'm also in the process of reworking my program (based on some help I had in another thread) in order to implement the "loop" as I did it a totally different way before. But I was having issues with the display being off sync and I wanted to get that problem sorted out before I got to deep in rewriting everything.
28  Game Development / Newbie & Debugging Questions / Re: Double Buffering with a JPanel on: 2014-07-30 15:14:55
Wow...you guys are quick! Cheesy Thanks everyone!

To everyone: Basically what I'm trying to do is prevent one of the label displays from getting updated slightly before the other one. This is for a metronome application and sometimes (especially at faster speeds) one display will change just slightly before the other one when they should both change at precisely the same time. That's basically what I'm trying to prevent from happening with my double buffering method. I know double buffering is usually used to prevent "flickering", but I figured that approach might work for what I need also.

KevinWorkman, I've read up on painting but I still don't fully understand some of the "magic" that happens behind the painting methods. I found an example of double buffering using Graphics that moved an oval around the screen with the arrow keys and I tried replacing the "draw oval" part with a "draw Image" which I'm trying to get from the JPanel. If drawing an oval works (and it does when I add that into my example code), then drawing an image should theoretically work as well as long as I get the get the Image correctly from the JPanel...which unfortunately isn't working.
29  Game Development / Newbie & Debugging Questions / Double Buffering with a JPanel on: 2014-07-30 14:37:27
---------------------------------------------------------------

*** UPDATE *** I have changed the topic slightly from my first post. Start from this post for the updated question:
http://www.java-gaming.org/topics/double-buffering-with-a-jpanel/33983/msg/320384/view.html#msg320384

---------------------------------------------------------------


Hi all,

I’m trying to get two JLabels to update at exactly the same time which I would like to do from my repaint method in my loop. However, the problem is that calling setText and setBackground on the JLables automatically calls the repaint method, therefore these labels aren’t actually getting updated by my repaint method in my loop.

I’m trying to implement a method of double buffering where I update the labels off screen and then in my repaint method I make an Image of the JPanel that holds the JLabels and display that Image. However, I cannot get this to work. The JFrame shows up solid black.

I believe that my problem is getting the Image of the JPanel and I’ve tried a couple different methods, but neither of them worked. I left both methods in my code so you can see the two methods I tried and one of them is commented out.

I did check to make sure everything else in my loop and double buffer were working correctly by removing all of the JPanel Image creating stuff in my paintComponent method and added a line to draw an oval with Graphics...
g.fillOval(x, 200, 20, 20);
Then I incremented “x” in my update method and the oval does move successfully across the screen. So everything else appears to be working.

Any help in getting my JPanel double buffer to work would be greatly appreciated...of if there is a better way I could be going about this, I’m open to suggestions there as well. Thanks! Smiley

Here’s my sample code:

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

public class TestApplication {
   static TestApplication app;
   static Loop loop;
   static Canvas canvas;
   
   JPanel         mainPanel;
   JLabel[]         beatDisplay;
   
   boolean isPlaying=true;
   
   int[] count = { 1, 1 };
   boolean[] isGreen = { true, true };
   
   JPanel center = new JPanel();
   
   public static void main (String[] args) {      
      app = new TestApplication();
     
      SwingUtilities.invokeLater(new Runnable(){
         public void run() {
            app.gui_Create();
            app.loop();
         }
      });
   }
   
   public void gui_Create() {
      gui_MainPanel();
      gui_AddContent();
      canvas = new Canvas(app);
   }
   public void gui_MainPanel() {
      mainPanel = new JPanel();
      mainPanel.setPreferredSize(new Dimension(400,400));
      mainPanel.setLayout(new BorderLayout());
      mainPanel.setVisible(true);
   }
   public void gui_AddContent() {
      center.setSize(new Dimension(400,400));
      center.setMaximumSize(new Dimension(400,400));
      center.setMinimumSize(new Dimension(400,400));
      center.setPreferredSize(new Dimension(400,400));
      center.setOpaque(true);
      center.setVisible(true);
     
      beatDisplay = new JLabel[2];
      for (int i=0; i<2; i++){
         String buttonName = "~ SOUND " + i + " ~";
         beatDisplay[i] = new JLabel(buttonName);
         beatDisplay[i].setPreferredSize(new Dimension(400, 50));
         beatDisplay[i].setHorizontalAlignment(SwingConstants.CENTER);
         beatDisplay[i].setOpaque(true);
         beatDisplay[i].setFont(new Font("Serif", Font.BOLD, 40));
         
         center.add(beatDisplay[i]);
      }
     
//       canvas.add(center, BorderLayout.CENTER);
  }
   
   public void loop(){
      loop = new Loop(app, canvas);
      loop.start();
   }
   
   public void update(){
      if (loop.frameCount%30 == 0){
         for (int i=0; i<2; i++){
            beatDisplay[i].setText(""+count[i]);
            if (isGreen[i]){
               beatDisplay[i].setBackground(Color.GREEN);
               isGreen[i] = false;
            }
            else{
               beatDisplay[i].setBackground(Color.YELLOW);
               isGreen[i] = true;
            }
           
            count[i]++;
            if (count[i] > 4)
               count[i] = 1;
         }
      }
   }
}


Loop.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class Loop extends Thread {
   static TestApplication app;
   static Canvas canvas;
   
   int fps = 60;
   long frameCount=1;
   
   public Loop(TestApplication appIn, Canvas canvasIn){
      app = appIn;
      canvas = canvasIn;
   }
   
   public void run(){
      while (app.isPlaying){
         app.update();
         canvas.repaint();
         try { Thread.sleep(fps); } catch (InterruptedException ie){}
         frameCount++;
      }
   }
}


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

import java.awt.image.BufferedImage;

public class Canvas extends JFrame{
   static TestApplication app;
   
   Image dbImage;
   Graphics dbg;
   
   public Canvas(TestApplication appIn){
      app = appIn;
     
      setTitle("Sound Test");
      setPreferredSize(new Dimension(400,400));
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      pack();
      setVisible(true);
   }
   
   public void setMainPanel(JPanel panel){
      setContentPane(panel);
   }
   
   public void paint(Graphics g){
      dbImage = createImage(getWidth(), getHeight());
      dbg = dbImage.getGraphics();
      paintComponent(dbg);
      g.drawImage(dbImage, 0, 0, this);
   }
   
   public void paintComponent(Graphics g){
      Image temp;
     
      // NEITHER OF THESE WORK FOR CRREATING THE "TEMP" IMAGE
//       temp = app.center.createImage(app.center.getWidth(), app.center.getHeight());  
      temp = createImage(app.center);
     
       g.drawImage(temp, 0, 0, this);
     
      repaint();
   }
   
   private static BufferedImage createImage(JPanel panel) {
      int w = panel.getWidth();
      int h = panel.getHeight();
      BufferedImage bi = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB);
      Graphics2D g = bi.createGraphics();
      return bi;
   }
}
30  Game Development / Newbie & Debugging Questions / Re: requst for newbie overview tutorial on porting options on: 2014-07-30 14:27:52
Hey philfrei,

Check out Codename One:
http://www.codenameone.com/

You write your code in Java using the Codename One API:
http://www.codenameone.com/codename-one-api.html

Then it converts the code to NATIVE code on each device! Smiley They support Android, iOS, Windows Phone, Blackberry, J2ME, and JavaSE...hopefully I'm not forgetting anything. lol

Best part, IT'S FREE and Open Source! For building you upload your code to their servers and they build it and then send it back to you. They do limit the number of builds per month to avoid abuse of the servers. Paid accounts have unlimited builds, so that's an option too.

There are some things Codename One doesn't support like some low level java API's (such as low level audio) but they do allow you to write your own interfaces where you can write native code for each device and include it in your program. In this case you would have to write native for every device you want to support, but the code would only be a small fraction of re-writing your entire program native.

Check it out, that's what I plan on using for my phone app unless I'm able to find something better...which is unlikely as I've looked at some other options already. Codename One looks really great!

Also, I should say that I haven't really used Codename One yet. I'm still developing my prototype with Java before going mobile. But I've watched most of the demo and tutorial videos they have on youtube and I've posted a few questions on their forum where the creator of Codename One (Shai Almong) is extremely active and helpful there and can pretty much answer any question you have....seriously, the guy is a super genius! Cool
Pages: [1] 2
 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (23 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (34 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (25 views)
2014-09-07 01:12:14

Longarmx (31 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!