收藏
回答

真机上看不到绘制的线

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小游戏 需求 iOS WIN7 Iphone5 6.74

做一个简单的画线功能,在模拟器上没有问题。在真机上看不到。

if (this.moveing)

{

ctx.beginPath();

ctx.lineWidth = '5'

ctx.strokeStyle = 'red'

ctx.moveTo(this.startX, this.startY);

ctx.lineTo(this.curX, this.curY);

ctx.stroke();

ctx.closePath();

}


回答关注问题邀请回答
收藏

3 个回答

  • nemo
    nemo
    2018-12-04

    环境无法复现,可否提供代码片段?

    2018-12-04
    有用
    回复 1
    • 2018-12-05

      新建一个小游戏项目,使用飞机那个。然后再main.js的render函数中添加如下代码:

      ctx.beginPath();
          ctx.lineWidth = '5'
          ctx.setLineCap = 'square'
          ctx.strokeStyle = 'white'
          ctx.moveTo(0,0);
          ctx.lineTo(400,400);
          ctx.stroke();
          ctx.closePath();



      2018-12-05
      回复
  • 2018-12-04
    import './libs/weapp-adapter.js'
     
    let ctx = canvas.getContext('2d')
     
    export default class Main
    {
      constructor()
      {
        this.bindLoop = this.loop.bind(this)
        this.aniId = window.requestAnimationFrame(
          this.bindLoop,
          canvas
        )
     
        canvas.addEventListener('touchstart', ((e) =>
         {
          e.preventDefault()
          this.startX = e.touches[0].clientX
          this.startY = e.touches[0].clientY
        }).bind(this))
     
        canvas.addEventListener('touchmove', ((e) =>
        {
          e.preventDefault()
          this.curX  = e.touches[0].clientX
          this.curY = e.touches[0].clientY
          this.moveing = true;
     
          if (this.touched)
            this.setAirPosAcrossFingerPosZ(x, y)
     
        }).bind(this))
     
        canvas.addEventListener('touchend', ((e) => {
          e.preventDefault()
     
          this.moveing = false;
        }).bind(this))
      }
     
      Render()
      {
        if (this.moveing)
        {
          ctx.beginPath();
          ctx.lineWidth = '5'
          ctx.strokeStyle = 'red'
          ctx.moveTo(this.startX, this.startY);
          ctx.lineTo(this.curX, this.curY);
          ctx.stroke();
          ctx.closePath();
           
        }
      }
     
      loop()
      {
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        this.Render();
        this.aniId = window.requestAnimationFrame(
          this.bindLoop,
          canvas
        )
      }
    }
     
    let app = new Main()


    2018-12-04
    有用
    回复
  • 卢霄霄
    卢霄霄
    2018-12-04

    能做个代码片段吗

    2018-12-04
    有用
    回复 1
登录 后发表内容