使用画笔_graphics绘制线段的报错

Creator 版本: 2.4.3

import FF from “…/FF”;

const { ccclass, property } = cc._decorator;
const CALC_RECT_WIDTH = 40;
const CLEAR_LINE_WIDTH = 40;
/**

  • 小地图
    */
    @ccclass
    export default class FLiteMap extends cc.Component {

    @property(cc.Node)
    maskNode: cc.Node = null;

    @property(cc.Node)
    mIcon: cc.Node = null;

    private ff: FF;
    /**

    • 绘制的点
      /
      public tempDrawPoint: cc.Vec2 = null;
      onLoad() {
      }
      public initMap(ff:FF){
      this.ff = ff;
      let widget = this.node.getComponent(cc.Widget);
      widget.target = this.ff.main.node;
      }
      public transform(pos:cc.Vec2){
      let x = pos.x
      this.node.width/this.ff.mMap.node.width;
      let y = pos.y*this.node.height/this.ff.mMap.node.height;
      return cc.v2(x,y);
      }
      clearMask(pos:cc.Vec2) {
      //地图坐标转化为小地图坐标
      let tpos = this.transform(pos);
      this.mIcon.setPosition(tpos);
      let mask: any = this.maskNode.getComponent(cc.Mask);
      let stencil = mask._graphics;
      if (this.tempDrawPoint == null) {
      // 只有一个点,用圆来清除涂层
      stencil.circle(tpos.x, tpos.y, CLEAR_LINE_WIDTH / 2);
      stencil.fill();

      } else {
      // 存在多个点,用线段来清除涂层
      let prevPos = this.tempDrawPoint;
      let curPos = tpos;

       stencil.moveTo(prevPos.x, prevPos.y);
       stencil.lineTo(curPos.x, curPos.y);
       stencil.lineWidth = CLEAR_LINE_WIDTH;
       stencil.lineCap = cc.Graphics.LineCap.ROUND;
       stencil.lineJoin = cc.Graphics.LineJoin.ROUND;
       stencil.strokeColor = cc.color(255, 255, 255, 255);
       stencil.stroke();
      

      }
      this.tempDrawPoint = tpos;
      }

    reset() {
    let mask: any = this.maskNode.getComponent(cc.Mask);
    mask._graphics.clear();
    }
    }
    使用这个实现刮刮卡的功能,在web网页上没有问题,打包到android上报错
    E/renderer: (665): ccBindBuffer(0x8893, ib ? ib->getHandle(): 0); GL error 0x501: GL_INVALID_VALUE:restoreIndexBuffer

刚开始的时候是没有问题的,随着绘制的线段增加,就报错了。。

请问解决了吗,我也遇到同样的问题了

。。没有解决啊。暂时把这个功能去掉了:6:

参考这个,有个官方的pr修复了

1赞

感谢感谢~