|
How do i properly do this? The rotation causes the image to be rendered outside of context... |
Replies: 2 comments
|
I managed to workaround this problem: But this should also be possible using context2d. |
|
This works the same way that in JS Canvas Context2D. stroke(2.0, Colors.RED) { line(0, 0, 10, 0); line(0, 0, 0, 10) }You are rotating that axis, and you are saying to render that bitmap in the 0,0, which means that it will render at the 0,0 in the top left corner. bitmap.context2d {
rotateDeg(rotation)
drawImage(otherBitmap, -otherBitmap.width / 2, -otherBitmap.height / 2)
}If you want to adjust the position of the image, you can adjust the position of the original axis with For example: bitmap.context2d {
translate(otherBitmap.width / 2, otherBitmap.height / 2)
rotateDeg(rotation)
drawImage(otherBitmap, -otherBitmap.width / 2, -otherBitmap.height / 2)
}Alternatively, for this case, you can also do something completely different. Since |
This works the same way that in JS Canvas Context2D.
When you are performing rotations and things like that, you can think like an imaginary axis that is transforming.
You can actually. Draw that axis. With something like:
You are rotating that axis, and you are saying to render that bitmap in the 0,0, which means that it will render at the 0,0 in the top left corner.
If you want a different behaviour, it is possible. If you want to render the image centered to that axis, you have to change the 0,0 coordinates into -width / 2, -height / 2.
bitmap.context2d { rotateDeg(rotation) drawImage(otherBitmap, -otherBitmap.width / 2…