Kiril
Kiril

Reputation: 2131

How do I rotate a canvas without disturbing the coordinate system in Android?

I am trying to rotate a canvas with canvas.rotate and move an object on it at the same time. The problem is that with the rotation, the coordinate system of the canvas rotates as well, so I get cases when my object is supposed to be moving along the y axis, but the y axis is rotated on place of the x axis. It is a mess. Is there a way to go around this?

Upvotes: 1

Views: 2542

Answers (1)

SomeCallMeTim
SomeCallMeTim

Reputation: 4802

It's using matrix math; if you do things in the opposite order (translate then rotate, or vice versa), you'll get the opposite effect.

Also, use SetMatrix(null) to clear the matrix to the identity between operations; not sure if that's the kind of mess you're having trouble with.

Upvotes: 3

Related Questions