用Point类实现拖拽范围是圆形的

作者:袖梨 2022-07-02

var b:Point=new Point();
var circle:Sprite = new Sprite();
var test:Sprite=new Sprite();
test.x=200;
test.y=200;
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(0, 0, 10);
test.addChild(circle);
addChild(test)
circle.addEventListener(MouseEvent.MOUSE_DOWN,cd);
stage.addEventListener(MouseEvent.MOUSE_UP,sd);
function cd(e:MouseEvent) {
        test.addEventListener(Event.ENTER_FRAME,line);
}
function sd(e:MouseEvent) {
        circle.alpha=1
        test.removeEventListener(Event.ENTER_FRAME,line);
}
function line(e:Event) {
        b.x=test.mouseX;
        b.y=test.mouseY;
        if (b.length>100) {
        b.normalize(100);//主要是这个方法实现半径为100的圆形范围
        }
        circle.x=b.x;
        circle.y=b.y;
        circle.alpha=.5
        test.graphics.clear();
        test.graphics.lineStyle(1);
        test.graphics.lineTo(b.x,b.y);
}

相关文章

精彩推荐