Moving the start position of canvas pattern

后端 未结 3 840
误落风尘
误落风尘 2020-12-09 05:14

I have a code:

function draw(ctx) {
  // create new image object to use as pattern
  var img = new Image();
  img.onload = function(){
    // create pattern
         


        
3条回答
  •  难免孤独
    2020-12-09 05:47

    In response to the accepted answer: rather than undo the offset, I would use save() & restore() to avoid potential problems:

    ctx.save();
    ctx.translate(offset_x, offset_y);
    ctx.fillRect(-offset_x, -offset_y, fill_x, fill_y);
    ctx.restore();
    

提交回复
热议问题