A
A
Anon33632020-04-15 01:43:16
JavaScript
Anon3363, 2020-04-15 01:43:16

Canvas how to move an object?

5e963c569522e702785587.png
how to move triangle in canvas by top left values

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twobomb, 2020-04-15
@Anon3363

Option 1 via matrix offset

ctx.save();
  ctx.translate(50,0); // тут координаты смещения
  ctx.beginPath();
  ctx.moveTo(0,100);
  ctx.lineTo(200,100);  
  ctx.lineTo(100,0);  
  ctx.closePath();
  ctx.fill();
  ctx.restore();

Option 2 via variable offsets
var offX = 300;//по х
  var offY = 50;//по у
  ctx.beginPath();
  ctx.moveTo(offX+0,offY+100);
  ctx.lineTo(offX+200,offY+100);  
  ctx.lineTo(offX+100,offY+0);  
  ctx.closePath();
  ctx.fill();

R
rasschitai, 2020-04-15
@rasschitai

on, vskidku, attach to the coordinates of the triangle, positioning coordinates, such as:
pl + x1, pl + x2, pl + x3
pt + y1, pt + y2, pt + y3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question