How to draw circle?


(Skelyton) #1

I know this is probably stupidly simple, but I can’t seem to find a solution to this online, and I don’t know how to achieve the results I want.

I need a circle around that radio tower, and its radius should be the distance from your mouse to the center of the screen. I’ve made a hideous little gif to explain what I mean. https://dl.dropboxusercontent.com/u/1906363/mouse%20circle.gif

The thickness of the yellow line shouldn’t change no matter the circle’s radius.

Thanks for any help you can provide!


(Zachary Lewis) #2

You can use Input to get your mouse location. To draw a circle, I believe this thread has it all covered.


(Skelyton) #3

Okay well I guess I should explain my problem better. I’ve tried drawing a circle with Draw.circle but it won’t show up.

public class FreqCircle extends Entity
{
	
	public function FreqCircle() 
	{
		x = 100;
		y = 100;
		Draw.circlePlus(100, 100, 100, 0x641043, 0);
	}
	
}

I’m not sure what I’m doing wrong, and can’t find any references to see where people do it in their code.


(JP Mortiboys) #4

You need to put the drawing command in the render function - or make it a graphic, but let’s leave that for now.

public class FreqCircle extends Entity {
  public const MAX_RADIUS:Number = 200;
  public var radius:Number = NaN;
  public function FreqCircle() {
    x = 100; y = 100;
  }

  override public function update():void {
    radius = FP.distance(x, y, world.mouseX, world.mouseY);
    if (radius > MAX_RADIUS) radius = MAX_RADIUS;
    super.update();
  }

  override public function render():void {
    super.render();
    if (!isNaN(radius)) {
      Draw.circlePlus(x, y, radius, 0x641043, 1, false, 3);
      //                                      |    |    ↘ thickness
      //                                      |    ↘ no fill
      //                                      ↘ alpha
    }
  }
}

(Skelyton) #5

Thank you so much! This is exactly what I needed to understand.