Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 8613 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 Devvie

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.

      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 Devvie

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.

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 Devvie

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.


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!
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));
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.
g2D.fill(rect);// now your rectangle has been cleared
after that you have to reset the composite by doing this:


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

Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (25 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (202 views)
2018-05-13 18:23:11

nelsongames (127 views)
2018-04-24 18:15:36

nelsongames (126 views)
2018-04-24 18:14:32

ivj94 (867 views)
2018-03-24 14:47:39

ivj94 (128 views)
2018-03-24 14:46:31

ivj94 (771 views)
2018-03-24 14:43:53

Solater (143 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!