RotateFlip - 何时应用?

发布于 2024-09-27 06:25:54 字数 125 浏览 0 评论 0原文

我正在使用 RotateFlip 水平翻转精灵。看来 RotateFlip 是在绘制 Graphics 而不是图像时应用的。

问题是有些精灵需要翻转,有些则不需要(取决于精灵的方向)。我不想每次绘制翻转精灵时都克隆图像。

I'm using RotateFlip to flip sprites horizontally. It seems that RotateFlip is applied when Graphics is drawn not image.

The problem is that some sprites needs to be flipped and some not (depending on direction of sprite). I don't want to clone image each time I'm drawing flipped sprite.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2024-10-04 06:25:54

考虑在 Graphics 对象上使用变换矩阵,而不是在图像上使用 RotateFlip。翻转相当于将 X 或 Y 坐标缩放 -1。您可以预先计算单个翻转矩阵并在需要时使用它:

Matrix flipX = new Matrix();
flipX.Scale(-1, 1);

graphics.Transform = flipX;
// Draw your sprite here
graphics.ResetTransform();

但请注意,您在绘图时必须传递修改后的坐标,例如。使用上述转换,您必须传入 ContainerWidth - X 而不是 X

Consider using a transformation matrix on the Graphics object instead of using RotateFlip on the image. Flipping is equivalent to scaling the X or Y coordinates by -1. You can pre-compute a single flip matrix and use it whenever you want:

Matrix flipX = new Matrix();
flipX.Scale(-1, 1);

graphics.Transform = flipX;
// Draw your sprite here
graphics.ResetTransform();

Note however that you will have to pass in modified coordinates when drawing, for eg. using the above transform, you'll have to pass in ContainerWidth - X instead of X.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文