一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

将元件的拖动范围限制为圆形(as3)

时间:2022-07-02 17:10:11 编辑:袖梨 来源:一聚教程网

直接粘贴代码就可以看到效果

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);
}

热门栏目