dah01
JGO n00b  Posts: 46 Medals: 13
|
 |
«
on:
2011-03-14 20:13:03 » |
|
|
|
|
|
|
ra4king
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #1 on:
2011-03-14 21:22:44 » |
|
Holy crap this is amazing! **Bookmarked**
|
|
|
|
dah01
JGO n00b  Posts: 46 Medals: 13
|
 |
«
Reply #2 on:
2011-03-14 21:26:07 » |
|
Hours and hours of digging.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
ra4king
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #3 on:
2011-03-14 21:26:59 » |
|
You sir deserve an appreciation 
|
|
|
|
dah01
JGO n00b  Posts: 46 Medals: 13
|
 |
«
Reply #4 on:
2011-03-14 22:01:12 » |
|
My first one! 
|
|
|
|
|
ra4king
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #5 on:
2011-03-14 22:03:01 » |
|
Whoa?!? How did I get 9? I help people too much 
|
|
|
|
Sinuath
Jr. Member   Posts: 55 Medals: 2
|
 |
«
Reply #6 on:
2011-03-15 00:24:34 » |
|
You deserve a lot more then one for that! I gave you your second!
|
|
|
|
ra4king
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #7 on:
2011-03-15 00:46:54 » |
|
Hear ya go, I gave you another one. Which brings your total to.....3 
|
|
|
|
Nate
JGO Neuromancer     Posts: 1033 Medals: 26
mooooo
|
 |
«
Reply #8 on:
2011-03-15 01:33:48 » |
|
No libgdx!? Fail! 
|
|
|
|
dah01
JGO n00b  Posts: 46 Medals: 13
|
 |
«
Reply #9 on:
2011-03-15 07: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! Go get 'em!
|
|
dah01
JGO n00b  Posts: 46 Medals: 13
|
 |
«
Reply #10 on:
2011-03-15 07:56:30 » |
|
Now with the only books anyone ever mentions!
|
|
|
|
|
adon_y_coya
JGO n00b  Posts: 37 Medals: 1
|
 |
«
Reply #11 on:
2011-03-15 13:14:04 » |
|
Thanks! Appreciated!
|
|
|
|
|
Nate
JGO Neuromancer     Posts: 1033 Medals: 26
mooooo
|
 |
«
Reply #12 on:
2011-03-15 14: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
JGO Ninja    Posts: 747 Medals: 10
|
 |
«
Reply #13 on:
2011-04-17 20:37:35 » |
|
The link titled "Turk4n's game tutorials" can't be accessed
|
Twitter @drabiter
|
|
|
Gingerious
JGO n00b  Posts: 26 Medals: 2
|
 |
«
Reply #14 on:
2011-06-21 20: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
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #15 on:
2011-06-21 20: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
JGO n00b  Posts: 26 Medals: 2
|
 |
«
Reply #16 on:
2011-06-21 21: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
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #17 on:
2011-06-21 21: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
JGO n00b  Posts: 26 Medals: 2
|
 |
«
Reply #18 on:
2011-06-21 21:30:12 » |
|
I commented out the initialization of i, but still no dice. I shouldn't have to use a lock, should I?
|
|
|
|
|
philfrei
Sr. Member   Posts: 434 Medals: 21
|
 |
«
Reply #19 on:
2011-06-21 21: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.
|
"Life is short, art long, opportunity fleeting, experience treacherous, judgment difficult." 
|
|
|
Gingerious
JGO n00b  Posts: 26 Medals: 2
|
 |
«
Reply #20 on:
2011-06-21 22: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
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #21 on:
2011-06-22 01: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
JGO n00b  Posts: 2
|
 |
«
Reply #22 on:
2011-12-15 01:42:22 » |
|
To many links  ...
|
|
|
|
|
ra4king
JGO Kernel      Posts: 2342 Medals: 152
I'm the King!
|
 |
«
Reply #23 on:
2011-12-15 01:48:59 » |
|
Click em all!!
|
|
|
|
pyro sauce
JGO n00b  Posts: 2
|
 |
«
Reply #24 on:
2011-12-16 22: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...
|
|
|
|
|
|