ts 绘制多边形

ts 绘制多边形

    let bg = this.createBitmapByName("123_png");
    this.addChild(bg)
    bg.x = this.stage.width / 2
    bg.y = this.stage.height / 2
    bg.anchorOffsetX = bg.width / 2
    bg.anchorOffsetY = bg.height / 2
    let infoList = [5, 2, 7, 9, 4, 1]
    let list = this.getPolyPoint(infoList, bg)

    var shp: egret.Shape = new egret.Shape();
    shp.graphics.lineStyle(2, 0x00ff00); 
    shp.graphics.beginFill(0xff0000, 1)

    for (let i in list) {
        if (Number(i) == 0)
            shp.graphics.moveTo(list[i].x, list[i].y);
        else
            shp.graphics.lineTo(list[i].x, list[i].y);
    }

    shp.graphics.endFill();
    this.addChild(shp)

    for (let i in list) {
        var circle:egret.Shape = new egret.Shape();
        circle.graphics.beginFill( 0x00ff00, 1);
        circle.graphics.drawCircle( list[i].x, list[i].y, 5);
        circle.graphics.endFill();
        this.addChild(circle);
    }
         
         
public getPolyPoint(infoList, item){
        let list = []

        let x = this.stage.width / 2
        let y = this.stage.height / 2

        for (let i = 1; i <= 7; i++) {
            let info = infoList[i - 1]
            if (info == undefined)
                info = infoList[0]
                
            let point = new egret.Point
            let w = item.width / 2 * (info * 0.1)
            let h = item.height / 2 * (info * 0.1)
            let w1 = w / 2

            switch (i) {
                case 2:
                    point.x = x + w1
                    point.y = y - h
                    break
                case 3:
                    point.x = x + w
                    point.y = y
                    break
                case 4:
                    point.x = x + w1
                    point.y = y + h
                    break
                case 5:
                    point.x = x - w1
                    point.y = y + h
                    break
                case 6:
                    point.x = x - w
                    point.y = y
                    break
                default:
                    point.x = x - w1
                    point.y = y - h
                    break
            }

            list.push(point)
        }

        return list
    }

 

posted @ 2017-10-21 20:19 HaoK 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值