html5-canvas move object on line

前端 未结 1 448
鱼传尺愫
鱼传尺愫 2021-01-15 08:23

I want to move a object on a slanting line. I have given my code. In my code in my 3rd div as I move the slider I am drawing a slanting line on this line I want to move an o

相关标签:
1条回答
  • 2021-01-15 08:42

    You need to add the drawing code at the very end of functions drawSlopeCurve1() and drawSlopeCurve2(). The simplest way is to fix function newSprite() first and then use it (to avoid copying identical code-blocks over and over).

    In function newSprite():

    // Change that:
    ctx.globalCompositeOperation = 'source-atop';
    
    // To this:
    ctx.globalCompositeOperation = "source-over";
    

    (For more details on globalCompositeOperation see here.)

    At the end of functions drawSlopeCurve1/2():

    // Append this:
    newSprite(canId, x, y);
    

    See, also, this modified demo.

    0 讨论(0)
提交回复
热议问题