XNA SpriteBatches-使它们绘制偏移?

发布于 2024-12-01 05:23:00 字数 625 浏览 0 评论 0原文

有什么好的建议来做到这一点吗?

我希望能够在 XNA 中绘制大量 2D 物体——通常是在偏移位置。例如,如果某物位于 (X,Y) 位置,那么理想情况下,我希望能够向其传递一个修改后的 SpriteBatch,当调用 Draw(X,Y) 时,它会考虑偏移量并在 (X +偏移X、Y+偏移Y)。

我不想将此偏移量传递给子级,并且必须在每个子级中单独处理它 - 这可能会搞砸,也会搞砸我的界面!

首先,我想到了一个 SpriteBatch 的装饰器,如果我为位置 (X,Y) 的某些东西调用 Decorator.Draw ,则会将其路由到原始 SpriteBatch 作为 (X+offsetX, y+offsetY)。但是我无法重写 SpriteBatch 类中的 Draw 方法,即使我创建了自己的“Decorator.DrawOffset”,装饰器似乎也需要调用“SpriteBatch.Begin()”以及似乎会破坏的东西...... :(

然后我想到了扩展方法,但我认为每次调用 draw() 时他们都需要将偏移量作为变量传递给它们?这仍然需要我通过子项向下传递偏移量...

另一种选择是是为了吸引孩子们RenderTarget(或 XNA4 中的任何内容),然后以偏移位置将其渲染到屏幕上......但这似乎效率低下?

感谢您的评论!

Any suggestions for a good way to do this?

I want to be able to draw lots of 2D things in XNA- often in offset position. eg if something is in position (X,Y) then ideally I'd like to be able to pass it a modified SpriteBatch which, when Draw(X,Y) is called would take account of the offset and draw the thing at (X+OffsetX, Y+OffsetY).

I don't want to pass this offset to the children and have to deal with it separately in each child- that could screw up and would also screw up my interfaces!

Firstly I thought of having a Decorator to a SpriteBatch which if I call Decorator.Draw for something in position (X,Y) would route this to the original SpriteBatch as (X+offsetX, y+offsetY). But then I can't override the Draw methods in the SpriteBatch class, and even if I created my own "Decorator.DrawOffset", the Decorator seems to need "SpriteBatch.Begin()" called and stuff which seems to break... :(

I then thought of Extension Methods, but I think they'd need the offset passed to them as a variable each time draw() is called? Which still requires me to pass the offset down through the children...

Another option would be to draw the children to a RenderTarget (or whatever they are in XNA4) and then render this to the screen in an offset position... but that seems hideously inefficient?

Thanks for any comments!

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

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

发布评论

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

评论(1

心舞飞扬 2024-12-08 05:23:00

你应该使用变换矩阵。

Matrix Transform = Matrix.CreateTranslation(offsetX, offsetY, 0);

SpriteBatch.Begin(...,...,...., Transform);

you should use a Transformation Matrix.

Matrix Transform = Matrix.CreateTranslation(offsetX, offsetY, 0);

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