美文网首页
[cocos] graphic画虚线

[cocos] graphic画虚线

作者: 计西 | 来源:发表于2019-07-08 11:04 被阅读0次

代码来自cocos论坛用户pencik

let cmt = this.graphics.getComponent(cc.Graphics);
let startPos = cc.v2(300, 300);
let endPos =cc.v2(608, 987);
let line = endPos.sub(startPos);
let lineLenth = line.mag();
let unitLenth = 20;
let increment = line.normalize().mul(unitLenth);
let drawLine = true;
let pos = startPos.clone();
cmt.strokeColor = cc.Color.BLUE;

for(; lineLenth > unitLenth; lineLenth -= unitLenth){
     if(drawLine){
          cmt.moveTo(pos.x, pos.y);
          pos.addSelf(increment);
          cmt.lineTo(pos.x, pos.y);
          cmt.stroke();
      }else{
            pos.addSelf(increment);
      }
      drawLine = !drawLine;
  }

//最后一段
if(drawLine){
      cmt.moveTo(pos.x, pos.y);
      cmt.lineTo(endPos.x, endPos.y);
      cmt.stroke();
}

开启抗锯齿(新建一个js文件,写入以下代码即可)
if(!CC_EDITOR){
cc.macro.ENABLE_WEBGL_ANTIALIAS = true;
}

相关文章

  • [cocos] graphic画虚线

    代码来自cocos论坛用户pencik 开启抗锯齿(新建一个js文件,写入以下代码即可)if(!CC_EDITOR...

  • 。虚线。?。画。?。懂吗。?。

    。把。该。用。虚线。?。画。?。的。用。虚线。?。画。?。懂吗。?。 。这是。清理。?。大脑。?。的。重点。?。懂...

  • 画虚线

    绘制一条水平的虚线

  • 画虚线

  • 画虚线

    - (void)drawLine { UIView*lineView = [[UIViewalloc]init];...

  • 画虚线

    注意事项: android:layerType="software"

  • 画虚线

    毕业之后才发现,数学都还给数学老师了。就连三角函数都忘了。请教大佬手把手教我老半天终于会画虚线了!做一下笔记,说不...

  • 画虚线

    //画虚线 (UIImage *)drawLineWithView:(UIImageView *)imageVie...

  • iOS竖直虚线画法

    项目中有画水平虚线和竖直虚线的需求,便在网上参考了别人的水平虚线画法,子类化了竖直虚线的DashLineView ...

  • 使用css3的repeating-linear-gradient

    还在用 border-style: dashed 画虚线吗?虽然也是虚线,但是不能控制每一个虚线的宽度

网友评论

      本文标题:[cocos] graphic画虚线

      本文链接:https://www.haomeiwen.com/subject/cctohctx.html