Results 1 to 6 of 6
Thread: Small game
- 04-12-2011, 01:34 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
Small game
Hi,
I'm pretty new to Java, I have studied a couple of modules on it at University (even though I'm studyin Networking :confused:) and I like what I see, so plan to continue expanding my knowledge on it :cool:.
I am developping a small bat and ball game which initially, I thought would be relatively straight forward... How wrong could I be?
I am having problems repainting the bat.
Initially my ball moves around the screen and my bat is painted. I have attached a mouselistener to my main applet which gets the x co-ordinate that the mouse is at, which is then passed to a constructor inside my bat class.
Although, for some reason my bat remains stationary.
I have added some S.O.P testing and I have found where the issue is, although I can't find a way round it. Any help will be much appreciated :cool:.
S.O.P produces this...Java Code:import java.awt.*; public class Bat { public int x; public void setx (int x) { this.x = x; System.out.println("X1 = "+this.x); } public void paint (Graphics h) { System.out.println("X2 = "+x); h.setColor(Color.red); h.fillRect(x, 490, 50, 10); System.out.println("X3 = "+x); System.out.println("Painted"); } }
Why is the x value being reset to 0?:confused:X1 = 224
X2 = 0
Painted
Thanks in advanceLast edited by ivlatt; 04-12-2011 at 01:38 PM.
- 04-12-2011, 01:48 PM #2
Weird. Are you sure you're calling paint() after you call setx()?
Without seeing an SSCCE, we're just going to be guessing.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2011, 02:07 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
Thank you for your response
Yeah I'm fairly sure because the "X2 = " and "Painted" is produced everytime the mouse is moved
- 04-12-2011, 02:10 PM #4
Okay. Like I said, without an SSCCE, we're just guessing.
That doesn't mean paste your whole program here- it would be best if you could simplify things as much as possible, take out anything that doesn't directly relate to the problem. One class containing one mouseListener and one paintComponent() method, added to a JFrame, should be enough.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2011, 02:10 PM #5
Wait.. is "X1= " printed every time the mouse is moved?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 04-12-2011, 02:15 PM #6
Member
- Join Date
- Apr 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
a small advice
By java_newby in forum New To JavaReplies: 10Last Post: 12-04-2010, 09:37 PM -
small windows
By ghostofdarling in forum Java AppletsReplies: 1Last Post: 04-17-2010, 08:55 AM -
small problem
By rawan in forum Java AppletsReplies: 2Last Post: 04-07-2010, 03:32 AM -
small question about 'this'
By GPB in forum New To JavaReplies: 3Last Post: 02-28-2010, 05:46 PM -
A small doubt
By ranganathan in forum New To JavaReplies: 5Last Post: 02-19-2010, 06:18 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks