XNA SpriteBatches-使它们绘制偏移?
有什么好的建议来做到这一点吗?
我希望能够在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你应该使用变换矩阵。
you should use a Transformation Matrix.