Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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: ProjectBuilder help on: 2004-02-10 00:19:33
I used to use Project Builder, until folks around here told me to switch to Eclipse.

It's a free development environment from IBM. It's a billion zillion times better for Java than Project Builder.  I was resistant to making the change, because it took a little effort to learn how to use Eclipse, but once I put the time in (really all it took was reading the help screens) I was hooked.  I highly, highly recommend that you check it out.
2  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-02-03 20:54:55
Oops.  I looked and looked and looked at that, and didn't see it.  Embarassed, once again, me.

On the plus side, I've got the code in and now it's working perfectly! Yayy!  Thanks to all!
3  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-02-02 19:29:58
OT:  I don't see the difference between what you wrote and what I coded.

The error I spotted was that while I was normalizing the vectors I was dividing B.x and B.y by Alength instead of Blength.
4  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-02-02 19:12:23
Oops.  I posted some code, 'cuz it wasn't working, and I was asking if anyone could see an error in it, and while I was posting it I saw the error in it.

Nevermind!
5  Game Development / Newbie & Debugging Questions / Advice on map scrolling? on: 2004-02-01 21:58:30
My game has a map that needs to scroll left and right.  Not like a side-scrolling game, where different scenery scrolls on screen, but like a Civ-type game, where I'm representing a globe that has to scroll around and around, both left and right.  

I might (*might*) be able to figure out how to do this if all I had to worry about was the map image, but it's a little more complicated than that.  The map also has a hexagon grid drawn on top of it, and each hex is a separate GeneralPath shape, and mouse-clicks are detected by what shape they happen in.  Now, when the map scrolls, some hexes will always need to be partly on one side of the screen, and partly on the other.  How do I handle that?

Help will be greatly appreciated.
6  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-02-01 21:50:13
Thanks, Tom and OT.  Thanks for explaining so much to me.  Now all I have to do is use this stuff in my code.  Wish me luck!
7  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-01-31 23:11:50
OT:

I get you, but I was thinking of this situation:

1  
2  
3  
4  
5  
6  
7  
8  
9  
      |     /
      |    /
      |a /
      | /
      |/
     /|b
    / |
   /  |
  /   |


in which b = 180 - a.

So that leaves only my other question: will the dot calculation produce an angle in degrees or in radians?
8  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-01-31 15:06:07
Tom, thanks for your efforts.  I still just barely understand.  I looked at the website you referred me to, but it too was too hard for me to understand.  I'm not sure you should put any more work into explaining it to me.  There is one thing I'd like you to explain a little more about:

Quote
It gives you the absolute angle of the two vectors A and B. Absolute angle means there are two solutions. The second solution is (2*PI-angle). To find out wich to use you can use the "cross-product"


Again, pretty much lost on me.  Looking at that web page, it doesn't say anything about absolute angle, it just shows one solution.  Does absolute angle mean it's always the smaller of the two possible angles?

"2*Pi-angle" confuses me.  If there are two solutions, isn't solution b=180 minus solution a?  Is that not true because the answer will be in radians and not degrees?  If so, don't I need to do some kind of multiplication to solution a, also?

Actually, I'm not sure whether you should bother explaining any of that.  I'm willing to take your word for it and just try using the calculations you provide.  I just need to know how to find the smallest of the two possible angles, in degrees.
9  Game Development / Newbie & Debugging Questions / Re: How can I find the angle between two lines? on: 2004-01-31 00:32:26
Wow, that is way over my head.  I barely understand any of it.

Quote
a dot b = |a||b|cos a


Uh, what do a and b represent here?  Vectors, you say?  Does that mean the same thing as "line segments?"  And (feeling stupid, he asks:) what does "dot" mean?  And what does "|a|" mean?  From context, I assume it represents a "normalized" vector, but I don't know what that is.  You show me the calculations for normalization later on in your post, but I have no idea what you're doing or why.

Quote
Firt get the lines vectors between the endpoints (subtract x,y,z):
A = A2-A1
B = B2-B1


"Subtract x,y,z?"  Hah?  It looks to me like A and B are points, here, since they're derived by subtracting one point from another, but I'm not sure how you do that.  Subtract A1.x from A2.x and A1.y from A2.y?  What is this "z" I keep hearing about?  And if A and B are points, why are they "Vectors?" Confused = me.

Quote
A.x /= ALength
A.y /= ALength
A.z /= ALength


What does "/=" do? <------ another embarassing question.


Finally, exactly what angle does this calculation produce?  If the lines intersect without having a common endpoint, there are actually two angles formed by the lines (if I remember correctly, an "acute" angle and an "obtuse" angle, but I wouldn't bet on it).  Which angle would this calculation return?  Or would it only work if the line segments have a common endpoint (which actually would work fine for me)?

Thanks for your post, sorry I'm so dumb.
10  Game Development / Newbie & Debugging Questions / How can I find the angle between two lines? on: 2004-01-30 01:02:00
I've looked through the .geom package, and I can't find anything that does this.  Here's my goal: I have two line segments that intersect, and I want to find the angle between them.

I've thought of one way to do it.  It's pretty convoluted.  First, find the intersection of the two lines by choosing one line and using a PathIterator to count through the points on that line until we find the point with a distance of zero from the other line.  There's our intersection.

Next, create two lines of equal size, thus: find the shorter of the two lines; create a new line (if necessary) that is identical to the longer line, but whose P1 is at the intersection of the two lines; use a PathIterator again to count through the points on the longer line until we've defined a segment of the longer line that is the same length as the shorter line.  

Now we should have two lines of equal length.  This length is the radius of the circle we need to create to find the angle between the lines.  But what we need to actually define is the rectangle that *bounds* the circle that encompasses the lines.  We can do that by starting from the intersection point and subtracting the segment length from the x and y of that point.  That should give us the location of the upper left corner of the rectangle we're looking for.

Now, the last leg of this process: iterating through a bunch of different Arc2Ds. Using the endpoint of one of the lines as a startPoint for the arcs, we iterate to find an arc whose endPoint is 0 distance from the second line.  Once we've found the startPoint and the endPoint of an arc that runs from one line to the other, the parameter that defines the degrees of that arc segment will also give us the angle between the two lines.  Voila!

Whew.

That's the simplest (hah!) method I can think of.  I'd love to hear of another.  Anyone?
11  Games Center / Archived Projects / Re: TripleA 0.3 released on: 2004-01-29 21:28:54
I don't know how to post images here, I suspect it involves using a web page address and I can't do that, so I've sent an image to your email.

I think max and min buttons are a good idea, I just don't think they look quite right, at least on the Mac.
12  Game Development / Newbie & Debugging Questions / Fractional Fonts on the Mac? on: 2004-01-29 21:17:44
Does anybody know how to draw fractional fonts on the Mac?  Apparently the Mac won't do it.  It should work just like it does on the PC, but it don't.  This here feller showed me some test code that he ran on the PC that utilized fractional point sizes, and I ran the same code on my Mac and only got integer point sizes.  Does anybody know what's up here?
13  Game Development / Newbie & Debugging Questions / Re: Announcements on: 2004-01-29 21:14:54
First off, shouldn't that huge reply up there have been posted on its own, instead of here?

Second, I believe the proper spelling of this forum should be "CLUEbies," as opposed to "CLUbies."

With love,

--the niggler
14  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-29 20:56:10
Doug, thanks for your responses.  I've given up on trying to get fractional fonts, and I'm using, um, Font.getBounds ( string , fontRenderContext ) , I think that's it, and it's working all right.  I really wish I could get exact point sizes, but I guess the mac just doesn't do that.  Maybe I'll start a new thread with that question.  Thanks for your help.
15  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-24 20:14:34
The latest Mac version, I think it's 1.4.something.  In OS X 1.2.6.
16  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-23 14:09:12
Doug:

I took your code home and ran it and it didn't quite work.  It fell into an infinite loop at the first panel size, because of the font-size problem I mentioned before: it doesn't matter if you set the font size with a float, its actual size gets set by rounding that float to an integer.  So, on panel width 200, the longestWidth keeps flipping back and forth between 198.0 and 231.0; each time the longestWidth is lower the code increases the fontSize, and each time it's higher it decreases the fontSize, and it never resolves.  Note that I didn't change your code at all, I cut and pasted it right into Eclipse.

Also, I should note that the font sizes the code hovers around are 10.whatever and 11.whatever, not 13.whatever as shown in your output.  This suggests to me that the weird thing about PixelBounds returning a wildly inaccurate rectangle is a Mac-platform bug.  Perhaps not being able to use fractional font sizes is also Mac-specific, though that would be odd.
17  Games Center / Archived Projects / Re: TripleA 0.3 released on: 2004-01-22 21:55:26
Hi sbridges.  I'm a mac user, and it runs perfectly on OS X 10.2.4.  It would be cool to not have to use the terminal, but I'm sure that's a plan of yours for someday.

Nice work!  Fun to play.  I think the graphics are, for the most part, excellent.  My only quibble is that the shading on the units is so un-saturated that sometimes it's hard to tell which units belong to which side.  Britain and Germany especially have units that are hard to tell apart.  Since usually units are inside a country of their own color, this doesn't matter much, but when units are at sea, it can get pretty confusing.  I would recommend not using quite-so-light coloring on the units.  But the look of the board is really cool, the unit designs look cool, it's cool.

I should mention that I've never played the real A'n'A, so I can't report any gameplay inaccuracies.

Some other comments:

There are times when I don't think the unit-selection window should pop up, for instance, when there's only one unit to unload onto a land space, or certain times during the battle sequence.  I can't remember exactly when during battle there were unnecessary windows, but I do remember a couple different times thinking, "the game should detect this situation and skip this window."

The graphics for the unit selection arrows look very clunky on my Mac.  I'm not sure if that's because they don't go well with OS X's window graphics or what, but the first time I saw them I thought they were a bug.  There appears to be a little half circle at the top and bottom of the arrows that really muddies things up.  If possible, you should make the arrows bigger, I think.

My first instinct was to drag units from one space to another, not to click one space and then click another space.  It would probably not be too hard to let the player have both options, clicking AND dragging.

Have you seen Solace (demo available at freeverse.com)?  It uses an A'n'A-based combat system, and its combat screen is really cool.  Check it out.  You should totally rip it off.  You probably won't want to go as far as having 3-D dice rolls, but the main layout and battle flow would be pretty easy to copy.

I found the mouse-at-the-border-of-the-screen scrolling system unwieldly.  My hand kept going to the arrow keys.  I recommend making the arrow keys move the viewable box around on the map.

I don't know how much of a hassle it would be, but I'd also like to see a more-zoomed-out view available.  Civ III has a close-up view and a zoomed-out view, and I end up using each for different things.

Often, I would finish a phase and click done and then remember something else I'd wanted to do.  It would be cool to have a "go back to last phase" button ("undo," maybe?) that would let you, duh, go back to the last phase.  Naturally, the player shouldn't be able to undo combat, but I often forgot about attacks I'd wanted to make when I was in the movement phase.  Undoing all that movement and going back to combat wouldn't really be cheating, and it would be kind to absent-minded players like myself.

Sometimes when I tried to move a transport into a shore space and unload it in one move, I'd get an error message.  I forget what it said, but I was then able to do the move in two parts: first move the transport to the shore space, then move the units off.  That seems like a bug.

Well, that's all my comments.  All in all, I think it looks great and I encourage you to keep working on it.  It's coming out excellent.  Thanks for posting it.
18  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-22 21:21:12
Doug, thanks so much for your detailed, thoughtful reply.  I'll have to take that code home and play with it a little.  But at first pass I have a couple questions/comments.

Re: your BTW: when won't my characters be ASCII?  I'm sure they'll be ASCII for all the purposes I'm using the class for.  Is there something else you'd recommend doing that would be applicable to both ASCII and non-ASCII characters?

In the part of the code where the longest line is found, I notice that you made it more efficient by removing at least a couple of extra calls to createGlyphVector.  Thanks for the instruction; your approach is superior to mine.  Just one thing: shouldn't it start with i=0 now, instead of i=1?

And again, the part where you specify "iterate until we converge within half a pixel" is a much better way to do things than the way I was doing them.  I'm really happy to get such excellent feedback.

But, and I perhaps shouldn't mention this until I've tried out your code, but still... all your streamlining doesn't get at the main problem I was having: getPixelBounds returns a rectangle that, to my eye, has nearly nothing to do with the actual size of the displayed text.  I was actually not having a problem scaling using getPixelBounds, I was scaling entirely accurately, it's just that I was scaling to the wrong thing: a really inaccurate rectangle.  This discrepancy won't show up until you actually try to display the text, which is why your test code looks like it's working perfectly.  My debugging outputs always reported that my clumsy scaling was working perfectly, too, when I could plainly see that it wasn't, which is part of what was driving me batty.

getLogicalBounds, however, returns a rectangle that appears to be exactly the same size as the displayed text.  Using getLogicalBounds, my code works just fine.  Not as efficiently as yours, but it gets the job done.

One last thing:  I'm confused about fractional fonts.  When I use a float to specify a Font (using Font.deriveFont ( float )), the font stores that fraction inside itself put sets it point size by rounding that fraction off to the nearest integer.  Is there a way to get my fonts to display at fractions of their point sizes?  If so, I'd love to know about it.

Again, thanks a lot for your response.
19  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-22 03:35:01
Well, I don't know what to make of all this.  I tinkered with my code so that my program actually displayed the bounding boxes produced by GlyphVector.getPixelBounds, and all I can say is, I don't know what the hell those boundaries represent, but they certainly don't represent what they're supposed to.  

They're supposed to represent the bounding box around all the pixels actually affected by the given GlyphVector, and I know for a fact they don't, because I had my program draw the GlyphVector and then draw the pixelBounds, and the freakin' pixelBounds came out almost twice as wide as the GlyphVector text.  Then I tried checking out the GlyphVector.getVisualBounds method, and it was just as wrong as getPixelBounds.

Finally, I tried using the GlyphVector.getLogicalBounds method, even though Mark said the logical bounds would be inaccurate, and darn if they don't look pretty accurate to me.  I have no idea why Font.getStringBounds.getWidth should return a different value than Font.createGlyphVector.getLogicalBounds.getWidth, but my code wasn't working with getStringBounds, and it IS working with getLogicalBounds.  Go figure.  This Java, she crazy, no?
20  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-20 03:02:06
Okay, this is driving me bizzonkers.  I tried fixing everything up with GlyphVectors, and now the fonts are coming out WAY too small!  Like, HALF the size they should be.

Here's the modified 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  
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  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
// Setting the fontSize.  First we find the longest line.  We create an
// integer to hold the place in the allTexts array of the longestLine:
                 
int longestLine = 0 ;
                 
// We'll need a FontRenderContext to get widths with:
                 
FontRenderContext fontRC = g2D.getFontRenderContext () ;
                       
// And a double to hold the longest width:
                       
double longestWidth = allFonts [ longestLine ]
      .createGlyphVector ( fontRC , allTexts [ longestLine ] )
      .getPixelBounds ( null, 0 , 0 ).getWidth () ;
                 
// Now we count through the lines:
                 
for ( int i = 1 ; i < allTexts.length  ; i ++ ) {
                       
      // Is the current line longer than the longest line?
                       
      if ( allFonts [ i ].createGlyphVector ( fontRC , allTexts [ i ] )
            .getPixelBounds ( null, 0 , 0 ).getWidth ()
            > longestWidth ) {
                                   
            // If so, set a new longestLine:
                             
            longestLine = i ;
                                   
            // And set longestWidth:
                                   
            longestWidth =       allFonts [ longestLine ]
            .createGlyphVector ( fontRC , allTexts [ longestLine ] )
                  .getPixelBounds ( null, 0 , 0 ).getWidth () ;
     
                       
      }
                       
}
                 
//**TEMP:
                       
System.out.println ( allTexts [ longestLine ] ) ;
                 
// Setting maxFont and maxWidth, using longestLine:
                 
Font maxFont = allFonts [ longestLine ] ;
                 
String maxWidth = allTexts [ longestLine ] ;
                 
// the ratio of the longest line's point size to its width, so that we
// can make a ballpark guess as to the right font size:
                 
float widthRatio = maxFont.getSize2D () / ( float ) longestWidth ;                  
                       
// Now using that ratio to make a ballpark guess as to the font size:
                 
fontSize = getWidth () * widthRatio ;
                 
// Setting maxFont to that size:
                 
maxFont = maxFont.deriveFont ( fontSize ) ;
                       
//***TEMP: the width of the panel:

double thisWidth = getWidth () ;

                 
// Is the maxWidth string smaller than the width of the panel?
                 
while ( getWidth () > longestWidth ) {
                                                                       
      // If so, increase the size of the font by half a point:
                                                     
      fontSize = fontSize + 0.5f ;
                             
      maxFont = maxFont.deriveFont ( fontSize ) ;
                                                                       
      // And set longestWidth:
                                   
      longestWidth = maxFont
            .createGlyphVector ( fontRC , maxWidth )
            .getPixelBounds ( null , 0 , 0 ).getWidth () ;
                                                                                                                 
}            
                 
// Is the maxWidth String now longer than the width of the panel?
                 
while ( getWidth () < longestWidth ) {
                                   
      // If so, decrease the size of the font by half a point:
                             
      fontSize = fontSize - 0.5f ;
                             
      maxFont = maxFont.deriveFont ( fontSize ) ;
                                                                                                           
      // And set longestWidth:
                                   
      longestWidth = maxFont
            .createGlyphVector ( fontRC , maxWidth )
            .getPixelBounds ( null , 0 , 0 ).getWidth () ;                                                                                                            
                             
}
                 
// Now we should have the the largest possible font size, within half a
// point.
                       
// ***TEMP:
                       
System.out.println ( "Panel Width: " + getWidth () ) ;
                       
System.out.println ( "MaxWidth: " + longestWidth ) ;


All the stuff commented with "//***TEMP:" is in there for debugging purposes.  Using that stuff, I can tell that, for example (these numbers are not exact), when getWidth returns 120, and longestWidth evaluates to 118, the on-screen font is only a little over half the size of the panel!  That is, the GlyphVector.getPixelBounds.getWidth method is correctly evaluating to very near the panel size, when the font it represents is way too small!

Hellllllllp!
21  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-19 22:38:12
Mark and Paul, thanks for responding.

Mark:

Thanks for the tip. I don't really understand what a 'logical size' is, but as you say it's different from the actual visible size, I'll look into these GlyphVectors you speak of.


Paul:

I'm sorry, I forgot to mention that I've modified my code a bit.  The first 'while' loop no longer test for the line being being within 3 pixels of the panel width, it just tests for the line being smaller than the panel width. So the process goes: if the line is smaller than the panel width, then increase it until it's larger, then take the larger line, and increase it until it's smaller.  This should result in a font size that is the maximum size possible within the panel boundaries.  It doesn't.  At least, not always.  I know for certain, from testing, that it sometimes chooses a font that's a full point smaller than the biggest possible font.  And I can't understand why.  But maybe I'll tinker with GlyphVectors and that will solve everything.
22  Game Development / Newbie & Debugging Questions / Re: Not-so-simple font-resizing questino... on: 2004-01-19 16:13:50
Paul, thanks for replying.  But I beg to differ with you about fixed-width fonts.  The method Font.getStringBounds ( String string, FontRenderingContext frc ) returns a Rectangle2D that bounds the given string for the given graphics context, whether or not it's a fixed-width font.  Using those rectangles, I can find the widest string among any number of strings, regardless of character spacing.  Then I should be able to test the width of the widest line at different point sizes.

My code tests first whether the width of the widest string is under the width of the panel, and if it is, it increases the width of the string until it is over the width of the panel.  Then it takes the string that is wider than the panel and decreases its point size by half a point until the string is smaller than the panel width.  It seems to me that this approach should guarantee that I have the widest possible font size, within half a point (or in practice a full point, since java's fonts don't really pay attention to fractional point sizes).

The problem is that my fonts *sometimes* come out at least a full point to small.  To test this, I added

fontSize = fontSize + 1F ;

to the end of the code that determines font size.  The result of this was that at some panel sizes, all the text still fit in the window, which means that normally the code was making it at least one point too small.  But at the same time, at other window sizes, the +1 font size proved too big, and the text didn't fit in the window.  I don't understand this.  Again, I tried changing the font-resizing increment from 0.5f to 0.05f, but my results didn't seem to be any more precise.

I'll greatly appreciate any help that can come my way.
23  Game Development / Newbie & Debugging Questions / Not-so-simple font-resizing questino... on: 2004-01-18 23:09:11
As many of you may well be aware (since I've mentioned it a lot), I'm trying to build a JPanel that resizes its text whenever the panel itself is resized, so that the text always takes up the maximum space it can.  I've struggled with this a lot, and I think I'm the closest I've come to date to having a solution.  

But I'm having one big problem.  First, let me give you my code.  The comments should explain most of it, but there's two variables that are unexplained.  "allTexts" is an array of Strings that holds all the lines of text that will be used for the panel (my approach only tests for line width, not height), and "allFonts" is an array of Fonts that holds all the fonts used by all the texts.

Here's my 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  
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  
// Setting the fontSize.  First we find the longest line.  We create an integer to specify the longest line:
                  
int longestLine = 0 ;
                  
// We'll need a FontRenderContext to get widths with:
                  
FontRenderContext fontRC = g2D.getFontRenderContext () ;
                  
// Now we count through the lines:
                  
for ( int i = 1 ; i < allTexts.length  ; i ++ ) {
                        
      // Is the current line longer than the longest line?
                        
      if ( allFonts [ i ].getStringBounds ( allTexts [ i ] , fontRC )
            .getWidth ()
            > allFonts [ longestLine ]
            .getStringBounds ( allTexts [ longestLine ] , fontRC )
            .getWidth () )
                                    
            // If so, set a new longestLine:
                              
            longestLine = i ;       
                        
}
                  
                  
// Setting maxFont and maxWidth, using longestLine:
                  
Font maxFont = allFonts [ longestLine ] ;
                  
String maxWidth = allTexts [ longestLine ] ;
                  
// the ratio of the longest line's point size to its width, so that we can
// make a ballpark guess as to the right font size:
                  
float widthRatio = maxFont.getSize2D ()
      / ( float ) maxFont.getStringBounds ( maxWidth, fontRC ).getWidth () ;                   
                        
// Now using that ratio to make a ballpark guess as to the font size:
                  
fontSize = getWidth () * widthRatio ;
                  
// Setting maxFont to that size:
                  
maxFont = maxFont.deriveFont ( fontSize ) ;
                  
// Is the maxWidth string smaller than the width of the panel by more than 3
// pixels?

while ( getWidth () - maxFont.getStringBounds ( maxWidth, fontRC ).getWidth ()
> 3 ) {
                                    
            // If so, increase the size of the font by half a point:
                                                      
            fontSize = fontSize + 0.5f ;
                              
            maxFont = maxFont.deriveFont ( fontSize ) ;
                              
            // Is the maxWidth String now longer than the width of the panel?
                  
            if ( getWidth () < maxFont.getStringBounds ( maxWidth, fontRC ).getWidth () )
                                          
                  // If so, break out of the loop:
                                          
                  break ;
                                                
}            
                  
// Is the maxWidth String now longer than the width of the panel?
                  
while ( getWidth ()
      < maxFont.getStringBounds ( maxWidth, fontRC ).getWidth () ) {
                              
            // If so, decrease the size of the font by half a point:
                              
            fontSize = fontSize - 0.5f ;
                              
            maxFont = maxFont.deriveFont ( fontSize ) ;
                              
}

// Now we should have maxFont at the largest size possible, within half a point.


So, this all seems to work, with one problem: the lines come out too short.  I realize my code allows the lines to be up to 3 pixels shorter than the width of the panel, but the lines come out way shorter than that.  The longest line of text seems to be 8-12 pixels short of the side of the panel.   I tried setting my code to be more sensitive, by changing the "0.5f"s to "0.05f"s, but it didn't seem to change the size the lines were coming out.  Can anyone see what's going on ?
24  Game Development / Newbie & Debugging Questions / Re: Simple assignment question. on: 2004-01-18 17:32:00
Thanks!
25  Game Development / Newbie & Debugging Questions / Re: Simple assignment question. on: 2004-01-18 17:29:54
Huh.  Okay, so, but let's just say we were talking about a Point2D and not a double.  In that case,

pointA = pointB

would make both pointA and pointB point to the same object, instead of copying pointB into a new object for pointA, right?
26  Game Development / Newbie & Debugging Questions / Simple assignment question. on: 2004-01-18 17:06:28
I'm trying to examine an array of strings and find out which is the widest.  Here's an approximation of the code I'm using:

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  
// The set of texts:

String [] texts = a bunch of texts

Font [] fonts = the fonts of those texts

// A variable to hold the longest line, initially set to the width of the first line:

double longestLine = ( the width of the first line, calculated using the font and the getStringBounds method) ;

// A variable to hold the current width when counting through the texts:

double currentWidth ;

// Now, counting through the texts to find the longest one:

for ( int i=1 ; i < texts.length ; i ++ ) {

     currentWidth =  ( again using getStringBounds, this time to find the width of the current line ) ;

     if ( longestLine < currentWidth )

          longestLine = new Double ( currentWidth ).doubleValue () ;

}




So, here's my assignment question.  What I really want to do in that last line is:

    longestLine = currentWidth ;

except I suspect that will make longestLine and currentWidth both pointers to the same variable, and thus longestLine will change whenever currentWidth changes.  That's not what I want.  But using "new Double ( currentWidth ).doubleValue ()" seems like a really dumb way to do things.  I mean, really: creating a Double from a double so that I can get a new double?  That seems really roundabout.  Is there a simpler way to do the same thing?
27  Game Development / Newbie & Debugging Questions / Re: Adding a capability to Line2D on: 2004-01-12 14:13:16
After working with this code for a little while, and having it not work correctly, and staring at it for a long time, I finally realized there's an error in it.  Since no one else caught it, I thought I'd post it myself:

1  
2  
3  
4  
5  
                  // Finding the change in x and y between the endpoints of the line: 
                  
                  double changeX = getP1 ().getX () - getP2 ().getX () ;
                  
                  double changeY = getP1 ().getY () - getP2 ().getY () ;


and

1  
2  
3  
4  
5  
6  
                  // Finding the end point of the new segment: 
                  
                  Point2D.Float newEnd =  
                        new Point2D.Float ( ( float ) ( getP1 ().getX () + newX ) ,  
                                                      ( float ) ( getP1 ().getY () + newY ) ) ;
          


add up to the new line segment heading away from the target point, not towards it.  To correct this, either the first snippet needs to be changed to

1  
2  
3  
4  
5  
                  // Finding the change in x and y between the endpoints of the line: 
                  
                  double changeX = getP2 ().getX () - getP1 ().getX () ;
                  
                  double changeY = getP2 ().getY () - getP1 ().getY () ;


which will result in the positivity/negativity of the changeX and changeY being reversed, or

1  
2  
3  
4  
5  
6  
                  // Finding the end point of the new segment: 
                  
                  Point2D.Float newEnd =  
                        new Point2D.Float ( ( float ) ( getP1 ().getX () - newX ) ,  
                                                      ( float ) ( getP1 ().getY () - newY ) ) ;
          


which does almost the same thing.

Clear as mud?  Well, I tried.
28  Game Development / Newbie & Debugging Questions / Adding a capability to Line2D on: 2003-12-31 22:17:50
Hi all.

I found myself several times wishing that Line2D could do this specific thing, so I made it do that thing.  I called the new class Line2DPlus.  The new thing it does is this: it has a method called getClosestPt which returns the point on the line that is closest to any given point.

Here's the code for the getClosestPt method:

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  
           
            public Point2D.Float getClosestPt ( Point2D.Float targetPoint ) {
                  
                  // Find the distance from the line to the point:
                  
                  double ptLineDist = ptLineDist ( targetPoint ) ;
                  
                  // Find the distance from the line's beginning to the point:
                  
                  double endPtDist = getP1 ().distance ( targetPoint ) ;
                  
                  // Calculating the length of the line segment that runs from the line's
                  // beginning to the point on the line that is closest to the targetPoint:
                  
                  double segmentLength =
                        Math.sqrt ( ( endPtDist * endPtDist ) - ( ptLineDist * ptLineDist ) ) ;
                        
                  // Finding the change in x and y between the endpoints of the line:
                  
                  double changeX = getP1 ().getX () - getP2 ().getX () ;
                  
                  double changeY = getP1 ().getY () - getP2 ().getY () ;
                  
                  // Finding the length of the line:
                  
                  double length = getP1 ().distance ( getP2 () ) ;
                  
                  // Determining the change in X and Y for the new segment:
                  
                  double newX = segmentLength * changeX / length ;
                  
                  double newY = segmentLength * changeY / length ;
                  
                  // Finding the end point of the new segment:
                  
                  Point2D.Float newEnd =
                        new Point2D.Float ( ( float ) ( getP1 ().getX () + newX ) ,
                                                      ( float ) ( getP1 ().getY () + newY ) ) ;
                                                      
                  // Returning that point:
                  
                  return newEnd ;
                  
            }     



Any comments?  Specifically, I'm curious if anybody can see a better way to do the same thing.
29  Game Development / Newbie & Debugging Questions / Re: Does Metal universally suck? on: 2003-10-24 23:05:31
Regardless ( or irregardless  Smiley ) of what should or shouldn't be, m'man Onyx, Metal under OS X is bug-o-riffic ( not to say buggerriffic ) and the default, or OS X, LAF is not.
30  Game Development / Newbie & Debugging Questions / Re: Does Metal universally suck? on: 2003-10-19 02:18:21
It sounds like OS X is causing all the trouble.  People keep talking about 1.5.  I thought 1.4 was pretty new.  Am I wrong?  When is 1.5 expected?
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.

rwatson462 (31 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

toopeicgaming1999 (123 views)
2014-11-26 15:22:04

toopeicgaming1999 (114 views)
2014-11-26 15:20:36

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!