Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
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   
Pages: [1]
  ignore  |  Print  
  How to remove previous drawStrings?  (Read 3490 times)
0 Members and 1 Guest are viewing this topic.
Offline Ambrose

Junior Newbie




Java games rock!


« Posted 2003-04-13 02:30:04 »

I know this is probably a pretty dumb question, but I'm stumped.

I am trying to use drawString to show a countdown timer.  However, the previous values never clear so I end up with all the numbers overlaying.

I tried to use clearRect but that clears to the background color.  I'm using the glasspane and want to show the countdown over what is already on screen.

How can I remove the text already showing on the glass Pane?
Offline mill

Junior Member




popcorn freak


« Reply #1 - Posted 2003-04-13 05:53:20 »

i haven't used glass Pane...

what's behind the timer? a background image? in that case, redraw the background and then draw the string on top.

to only draw behind the caiunter use Graphics.setClip(...) and then draw the image.

hope it makes sense! Cheesy

Offline Ambrose

Junior Newbie




Java games rock!


« Reply #2 - Posted 2003-04-13 12:36:50 »

The background is transparent so the board shows through.  When I try to use clearRect the screen gets set to the background color (grey) and hides the board.

I've tried setting the background color to a transparent alpha but that doesn't work.

Essentially, I need to be able to make a specified rectangle clear and be transparent so I can redraw the countdown.

If there is another way, that would be great too.

1  
2  
3  
4  
5  
6  
7  
8  
9  
      void drawBigText(String text) {
            Graphics2D g = (Graphics2D) getGlassPane().getGraphics();
            AttributedString styledText = new AttributedString(text);
            styledText.addAttribute(TextAttribute.FAMILY, "serif");
            styledText.addAttribute(TextAttribute.SIZE, new Float(120));
            styledText.addAttribute(TextAttribute.FOREGROUND, Color.yellow);
            AttributedCharacterIterator i = styledText.getIterator();
            g.drawString(i, 80, 250);
      }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline mill

Junior Member




popcorn freak


« Reply #3 - Posted 2003-04-13 12:50:25 »

ok, there gotta be something behind the timer since otherwise you would be looking through the monitor and on the wall that's behind it!

you have to redraw what's behind the timer! i'll use my car game as an example.

loop
1. draw track
2. draw cars
3. draw strings (lap info, time, etc).
end loop

here (1) redraws the whole track over everything else (this is not optimal but for the sake of simplicity just ignore this). then you need to draw everything else since that is overdrawn by the track.

makes sense? i'm not really sure how to describe it better. anyone else?

Offline Ambrose

Junior Newbie




Java games rock!


« Reply #4 - Posted 2003-04-13 12:58:35 »

Thanks.  I see what you are getting at now.  It was too obvious for my simple mind  :-/
Offline mill

Junior Member




popcorn freak


« Reply #5 - Posted 2003-04-13 13:12:00 »

anytime Smiley

if you are getting bad performance, look up Graphics.setClip(...)

Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2003-04-21 17:38:19 »

Actually if you are using glass pane then you shouldnty need to redraw the background I dont think.

Try setting your background color to something with 0 alpha.
That shoudl make clearRect work the way you want it to.

JK

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Ambrose

Junior Newbie




Java games rock!


« Reply #7 - Posted 2003-04-21 19:57:25 »

That was one of the first things I tried, and it seemed to ignore the alpha component.

I got it working by not even using glass pane though.
Offline hymatron

Junior Newbie




Java games rock!


« Reply #8 - Posted 2003-04-27 07:14:46 »

hey there.. umm basically you need to grab the Graphics2D and execute the following line:



g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
then:
Rectangle2D rect = new Rectangle(0,0,m_nBoardWidth,m_nBoardHeight);
// or whatever the size of your screen or rectangle you want to blank to transparent is.
then
g2D.fill(rect);// now your rectangle has been cleared
after that you have to reset the composite by doing this:

g2D.setComposite(AlphaComposite.SrcOver);

// blit your image or text to the graphics2d now and your done.

Later.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (32 views)
2014-09-19 03:14:18

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

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

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

Tekkerue (50 views)
2014-09-09 02:24:56
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!