V
V
vaselekk2020-11-17 19:41:18
Canvas
vaselekk, 2020-11-17 19:41:18

How to draw a rotated object with an offset?

Here is a link to an example here is an example

The problem is that I am making a game, and I have an element to rotate an object by degrees. and in my example, when I rotated the 2nd square, the shape of the square itself changed and became at an angle. But in addition to this, when I change the coordinate for example x (shown in the example), then my rotated square does not go along the correct path, HE goes to the side somewhere, and I need the square to change the angle and direction of movement in my example it remained unchanged.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-11-18
@vaselekk

Instead of changing the coordinates in which you draw the object, change the origin of the coordinate system, and do the drawing itself at (0, 0). That is, instead of do , and replace with . context.translate(120, 120);context.translate(120 + x_pos, 120);context.fillRect(x_pos, 0, 100, 100);context.fillRect(0, 0, 100, 100);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question