Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  (Solved) Graphics2D.setColor(c) Calls Ignored  (Read 456 times)
0 Members and 1 Guest are viewing this topic.
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Posted 2013-08-18 04:50:08 »

Calling to setColor and setStroke in certain sections of my code does not affect the state of the graphics object. I do not create any new graphics objects at any point. The following four lines creates the output below.

1  
2  
3  
4  
      System.out.print(g.getColor());
      g.setColor(debugFillColor);
      System.out.println(debugFillColor);
      System.out.print(g.getColor());


Output:
java.awt.Color[r=255,g=0,b=0]
java.awt.Color[r=0,g=0,b=0]
java.awt.Color[r=255,g=0,b=0]


I set the color to red before calling drawString. debugFillColor is black.

I am not aware of any function that would cause that.
Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 128
Projects: 4
Exp: 3 years



« Reply #1 - Posted 2013-08-18 04:59:16 »

Not much we can do just with this basic code segment, maybe post the entire paint() method?
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #2 - Posted 2013-08-18 05:07:30 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
  @Override public void paint(Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke());
    final String mouseStr = "Mouse: " + (lmb ? 'L' : '-') + (mmb ? 'M' : '-') + (rmb ? 'R' : '-') + " ";
    g2.clearRect(0, 0, pixelWidth, pixelHeight);
    g2.setColor(Color.red);
    g2.setComposite(AlphaComposite.SrcOver);
    g2.drawString(mouseStr, 2, pixelHeight - 2);
    drawThings(g2);
  }
 
  private void drawThings(Graphics2D g)
  {
    for(Thing t : things)
    {
      t.drawDebug(g);
    }
  }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
  public void drawDebug(Graphics2D g)
  {
    if(debugFillColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.fill(r);
    }
    if(debugLineColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.setStroke(thickStroke);
      g.draw(r);
    }
  }
 
  protected final Composite solidComposite = AlphaComposite.SrcOver;
  protected final Stroke thickStroke = new BasicStroke(2f);
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #3 - Posted 2013-08-18 06:09:02 »

I found one problem.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
  public void drawDebug(Graphics2D g)
  {
    if(debugFillColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.fill(r);
    }
    if(debugLineColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor); // This line <------------------------------
     g.setComposite(solidComposite);
      g.setStroke(thickStroke);
      g.draw(r);
    }
  }
 
  protected final Composite solidComposite = AlphaComposite.SrcOver;
  protected final Stroke thickStroke = new BasicStroke(2f);

[/quote]

setColor of Graphics calls setPaint of Graphics2D. setColor does not specify what happens if null is passed. setPaint does nothing with a null reference. How annoying.

Now I will have to see what the problem with setStroke was.
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.

E.R. Fleming (15 views)
2014-07-29 03:07:13

E.R. Fleming (5 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!