graphics2d - (Java) How can I use Anti Aliasing on java.awt.geom.Area objects? -
i want apply anti aliasing on little idlegame.
on first try used g.fillrect
create rectangles anti aliasing didn't work. commented things out , startet using area
. still seem not apply anti aliasing. side effect got slower due use of areas.
private void render() { boardparameters mbp = myboardparameters; bufferstrategy bs = mydisplay.getcanvas().getbufferstrategy(); if (bs == null) { mydisplay.getcanvas().createbufferstrategy(2); return; } graphics2d g2 = (graphics2d)bs.getdrawgraphics(); //clear screen g2.clearrect(0, 0, mbp.getwindowwidth(), mbp.getwindowheight()); //draw here! area area[] = {new area(),new area(),new area()}; drawunits(g2,area); int[][] cs = myboardparameters.getcolorscheme(); g2.setcolor(new color(cs[0][0],cs[0][1],cs[0][2])); g2.fill(area[0]); g2.setcolor(new color(cs[1][0],cs[1][1],cs[1][2])); g2.fill(area[1]); g2.setcolor(new color(cs[2][0],cs[2][1],cs[2][2])); g2.fill(area[2]); g2.setrenderinghint(renderinghints.key_antialiasing, renderinghints.value_antialias_on); //end drawing! bs.show(); g2.dispose(); } private void drawunits(graphics g, area[] area) { boardparameters mbp = myboardparameters; (int = 0; < mbp.getrows(); i++) { (int j = 0; j < mbp.getcollumns(); j++) { animal actanimal = myboarddata.animals[j][i]; int actualarea = 0; if (actanimal != null) { int[][] cs = myboardparameters.getcolorscheme(); switch (actanimal.getclass().getsimplename()) { case "fish": //g.setcolor(new color(cs[0][0],cs[0][1],cs[0][2])); actualarea = 1; break; case "shark": //g.setcolor(new color(cs[1][0],cs[1][1],cs[1][2])); actualarea = 2; break; case "plankton": //g.setcolor(new color(cs[2][0],cs[2][1],cs[2][2])); actualarea = 3; break; default: system.out.println("unknown unit found in 'myboardparameters.units[" + j + "][" + + "]': " + actanimal); break; } }else{ //g.setcolor(color.cyan); } //g.fillrect(j * mbp.getcellwidth(), * mbp.getcellheight(), mbp.getcellwidth(), mbp.getcellheight()); shape shape = new rectangle2d.double(j * mbp.getcellwidth(), * mbp.getcellheight(), mbp.getcellwidth(), mbp.getcellheight()); area areaadd = new area(shape); switch (actualarea) { case 1: area[0].add(areaadd); break; case 2: area[1].add(areaadd); break; case 3: area[2].add(areaadd); break; } } } }
does 1 have idea, try?
(maybe smoothing better description?)
Comments
Post a Comment