This site requires JavaScript, please enable it in your browser!
Greenfoot back
RUMMAKER
RUMMAKER wrote ...

2014/5/16

is there a more efficient way of doing this?

RUMMAKER RUMMAKER

2014/5/16

#
Im making a hp bar, but i want my hp bar to be curved like an arc instead of a rectangle. so i did it like so
public CurvedBar(int width, int height, int thickness, int startAngle, int arcLength, Player p, int resource)//IMPORTANT, length goes clockwise!!!, resource is the resource this bar is displaying
    {
        this.width = width;
        this.height = height;
        this.p = p;
        maxValue = p.getResource(resource);
        this.thickness = thickness;
        this.arcLength = arcLength;
        this.startAngle = startAngle;
        this.resource = resource;
        
        if(resource == 1)
        {
            c = Color.GREEN;
        }
        else
        {
            c = Color.CYAN;
        }
        
        bar = new GreenfootImage(width, height);
        bar.setColor(Color.GRAY);//value color
        for(int n = 0; n < thickness; n ++)
        {
            bar.drawShape(new Arc2D.Double(n, n, width-2*n, height-2*n, startAngle, - arcLength, Arc2D.OPEN));
        }
        setImage(bar);
    }
im like 100% sure that that's probably not the correct way of doing it but i can't find anything that lets me draw an arc like this with the thickness. I tried bar.drawShape(new Arc2D.Double(n, n, width-2*n, height-2*n, startAngle, - arcLength, Arc2D.PIE)); and then filling a smaller arc with "invisible" color but i realized invisible color just means u still see the previous arc xD link to my scenerial that i currently use this for http://www.greenfoot.org/scenarios/11459
danpost danpost

2014/5/16

#
Does the way shown above work?? or are you still looking for a way that will work? NVM. I looked at the scenario.
RUMMAKER RUMMAKER

2014/5/16

#
danpost wrote...
Does the way shown above work?? or are you still looking for a way that will work? NVM. I looked at the scenario.
it works, but as you can see its imperfect, and there are pixels "missing" from the bars... im also pretty sure there are better ways then setting the thickness by repeatly drawing the arc. But i can't think of anything so thats what im asking xD is there a more efficient way of drawing the arcs then what im doing?
danpost danpost

2014/5/16

#
There is a way; but, it does take a lot of repeated image manipulations. The plus side is that you only have to do the pixel-by-pixel transparency adding once, during construction of the actor. To keep the bar updated with its value, though, requires the image be drawn back and forth between two images multiple times. One drawback is I have yet to find an easy way to place a frame around the bar (probably need to go the 'not-so-easy' route requiring more back and forth action; this time using some 'not-so-easy' values).
danpost danpost

2014/5/17

#
I will be uploading a new scenario this weekend that will utilize my ArcBar Actor class (no framing around the arced bar, however). It will have two support type classes in it. The main one for controlling background music and the other for the bars (which I used one to display the volume and another to display the default size of the images for the BGMusic actors. Keep an eye out for it.
RUMMAKER RUMMAKER

2014/5/17

#
:D thx, danpost. Il keep an eye out.
You need to login to post a reply.