Why is my building in Java not drawing properly? -
i'm trying draw rectangle stylized edge on it, unfortunately edge covers left , top sides.
public graphics2d draw(graphics2d b, long camerax, long cameray) { //let's drawing stuff, yay renderimage = new bufferedimage(width, height, bufferedimage.type_int_argb); graphics2d g = renderimage.creategraphics(); int[] xps= new int[pointsarray.length]; int[] yps= new int[pointsarray.length]; int i=0; (pair p:pointsarray){ xps[i]=p.pair[0]; yps[i]=p.pair[1]; i++; } g.setcolor(color); g.fillpolygon(xps, yps, xps.length); g.setcolor(color.darker()); g.drawpolygon(xps, yps, xps.length); b = super.draw(b, camerax, cameray); return b; } yes, it's polygon. have keep extendable.
edit: pointsarray looks now.
pointsarray = new pair[4]; pointsarray[0] = new pair(0,0); pointsarray[1] = new pair(0,height); pointsarray[2] = new pair(width,height); pointsarray[3] = new pair(width,0); render method: (this overridden first method) (also admit -renderimage.getwidth()/2 part wrong)
public graphics2d draw(graphics2d b ,long camerax, long cameray) { affinetransform t = affinetransform.getrotateinstance(r); affinetransformop op = new affinetransformop(t,affinetransformop.type_bilinear); b.drawimage(renderimage, op, (int)(camerax-x), (int)(cameray-y)); return b; } jframe final render:
public void paintcomponent(graphics g) { graphics2d r = (graphics2d) g; graphics2d b = (graphics2d) r.create(); // herd liek buffers b.clearrect(0, 0, getwidth(), getheight()); // clear buffer // let's draw some... stuff long newcamerax = camerax; long newcameray = cameray; // background b.setcolor(color.white); b.fillrect(0, 0, getwidth(), getheight()); b.setcolor(color.black); (entity entity : entities) { entity.draw((graphics2d) b, camerax + (this.getsize().width / 2), cameray + (this.getsize().height / 2)); } // we're done drawing. let's put stuff in first thing r = b; camerax = newcamerax; cameray = newcameray; } pair class:
public class pair { public int[] pair = {0,0}; public pair(int num1, int num2) { pair[0] = num1; pair[1] = num2; } //you mad? }
basically drawing bottom , right portions of polygon outsize of image. java graphics.fillpolygon: how render right , bottom edges?
Comments
Post a Comment