dah01
|
 |
«
Posted
2011-03-15 00:13:03 » |
|
|
|
|
|
ra4king
|
 |
«
Reply #1 - Posted
2011-03-15 01:22:44 » |
|
Holy crap this is amazing! **Bookmarked**
|
|
|
|
dah01
|
 |
«
Reply #2 - Posted
2011-03-15 01:26:07 » |
|
Hours and hours of digging.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
ra4king
|
 |
«
Reply #3 - Posted
2011-03-15 01:26:59 » |
|
You sir deserve an appreciation 
|
|
|
|
dah01
|
 |
«
Reply #4 - Posted
2011-03-15 02:01:12 » |
|
My first one! 
|
|
|
|
ra4king
|
 |
«
Reply #5 - Posted
2011-03-15 02:03:01 » |
|
Whoa?!? How did I get 9? I help people too much 
|
|
|
|
Sinuath
|
 |
«
Reply #6 - Posted
2011-03-15 04:24:34 » |
|
You deserve a lot more then one for that! I gave you your second!
|
|
|
|
ra4king
|
 |
«
Reply #7 - Posted
2011-03-15 04:46:54 » |
|
Hear ya go, I gave you another one. Which brings your total to.....3 
|
|
|
|
Nate
|
 |
«
Reply #8 - Posted
2011-03-15 05:33:48 » |
|
No libgdx!? Fail! 
|
|
|
|
dah01
|
 |
«
Reply #9 - Posted
2011-03-15 11:18:01 » |
|
Thanks guys! I'll keep updating it. I'll dig up some libgdx. I gave you 2 or 3 because you answered like every thread I posted in for like a week.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
dah01
|
 |
«
Reply #10 - Posted
2011-03-15 11:56:30 » |
|
Now with the only books anyone ever mentions!
|
|
|
|
adon_y_coya
Senior Newbie 
|
 |
«
Reply #11 - Posted
2011-03-15 17:14:04 » |
|
Thanks! Appreciated!
|
|
|
|
Nate
|
 |
«
Reply #12 - Posted
2011-03-15 18:11:32 » |
|
For learning Java in general I'd recommend Thinking in Java for noobs. If you have a little programming experience already, this online book moves a little faster: http://math.hws.edu/javanotes/
|
|
|
|
ReBirth
|
 |
«
Reply #13 - Posted
2011-04-18 00:37:35 » |
|
The link titled "Turk4n's game tutorials" can't be accessed
|
|
|
|
Gingerious
|
 |
«
Reply #14 - Posted
2011-06-22 00:45:27 » |
|
Great compilation of information. I'm stuck on the GameDev Java Game Programming 2 link. I figured out that I was getting an error because the author forgot to import java.awt.*;, but now it appears that my repaint() function isn't working correctly. The count for i is not increasing and it just stays stuck at i = 0. Does anyone know why this is? Here's his code below: 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
| import java.applet.*; import java.awt.*;
public class SampleThread extends Applet implements Runnable { Thread t; int i; public void init() { t = new Thread(); t.start(); i = 0; } public void run() { while(true) { i++; repaint(); try{ t.sleep(1000); } catch (InterruptedException e) { ; } } } public void paint(Graphics g) { g.drawString("i = "+i, 10, 20); } } |
And here's the html page running it: 1 2 3 4 5 6 7 8 9 10 11
| <HTML> <HEAD> <TITLE>Sample Thread Applet</TITLE> </HEAD> <BODY> <CENTER> <H1>Sample Thread Applet</H1> <APPLET CODE="SampleThread.class"> </APPLET> </BODY> </HTML> |
Thanks to anyone who can help me!
|
|
|
|
ra4king
|
 |
«
Reply #15 - Posted
2011-06-22 00:59:41 » |
|
You should have started a new thread instead of hijacking an old thread.
But to answer your question, try putting the word "volatile" before the declaration of "int i;"
This happens because usually the CPU caches data that is in use often, instead of accessing RAM repeatedly. This causes variables to not be in sync, especially here since you have a thread updating "i" and another thread, the EDT, repainting the screen. Setting a variable as "volatile" makes sure it is updated among all threads.
|
|
|
|
Gingerious
|
 |
«
Reply #16 - Posted
2011-06-22 01:16:26 » |
|
Sorry about that. If a mod can take my first post and create a new thread for it and the responding posts, that would be awesome.
Regarding adding volatile to the declaration of int i, that didn't seem to work. Nothing seemed to change.
Just so I'm clear in my understanding, the thread I created is updating the value of i, but another thread exclusive to handling events in the AWT is created when calling repaint(), correct?
|
|
|
|
ra4king
|
 |
«
Reply #17 - Posted
2011-06-22 01:19:54 » |
|
Right but it is not created, it is a queue that dispatches events, hence its called the Event Dispatching Thread, EDT. And also remove that call to "i = 0" that will set "i" back to 0 after the tread starts incrementing it.
|
|
|
|
Gingerious
|
 |
«
Reply #18 - Posted
2011-06-22 01:30:12 » |
|
I commented out the initialization of i, but still no dice. I shouldn't have to use a lock, should I?
|
|
|
|
philfrei
|
 |
«
Reply #19 - Posted
2011-06-22 01:56:50 » |
|
When you create the thread, you need to include "this" That's the only way the compiler knows to use the run method you put in. Also, when you sleep, it might be better to use this form: The "i = 0;" in init doesn't hurt anything. The init code is only executed once. But it is not needed because when you declare i as an instance variable, the default value of 0 is assigned.
|
|
|
|
Gingerious
|
 |
«
Reply #20 - Posted
2011-06-22 02:02:49 » |
|
Philfrei, that seemed to work, thanks. Does that mean the compiler was using some default run method instead of the one I wrote for it?
|
|
|
|
ra4king
|
 |
«
Reply #21 - Posted
2011-06-22 05:56:00 » |
|
Haha wow I can't believe I didn't notice that. Yeah you need to give Thread the actual Runnable who's run() method should be called, else it uses an empty run() method 
|
|
|
|
The Voice
Junior Newbie
|
 |
«
Reply #22 - Posted
2011-12-15 06:42:22 » |
|
To many links  ...
|
|
|
|
ra4king
|
 |
«
Reply #23 - Posted
2011-12-15 06:48:59 » |
|
Click em all!!
|
|
|
|
pyro sauce
Junior Newbie
|
 |
«
Reply #24 - Posted
2011-12-17 03:46:06 » |
|
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
| import java.applet.*; import java.awt.*;
public class SampleThread extends Applet implements Runnable { Thread t; int i; public void init() { t = new Thread(); t.start(); i = 0; } public void run() { while(true) { i++; repaint(); try{ t.sleep(1000); } catch (InterruptedException e) { ; } } } public void paint(Graphics g) { g.drawString("i = "+i, 10, 20); } } |
Thanks to anyone who can help me! Try this code: 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
| import java.applet.*; import java.awt.*;
public class SampleThread extends Applet implements Runnable { private static final long serialVersionUID = 1L; Thread th; int i; public void init() { th = new Thread(); i = 0; }
public void start() { th = new Thread(this); th.start(); }
public void stop() { th = null; }
@Override public void run() { Thread thisThread = Thread.currentThread();
while (th == thisThread) { i++; repaint();
try{ Thread.sleep(1000); } catch (InterruptedException e) { break; } } }
public void paint(Graphics g) { g.drawString("i = "+i, 10, 20); } } |
If that doesn't work it's gotta be something wrong with the HTML or something else...
|
|
|
|
|