Building a custom SpriteBatch?

I’m new to MonoGame and XNA, so please excuse the beginner question…

I found an example that explains how to write a custom spritebatch, here: https://social.msdn.microsoft.com/Forums/en-US/7e5cc12f-3b75-49ef-8da9-c00a75139a21/write-your-own-spritebatch-101-longcode-included?forum=xnaframework . The problem is that the example is extremely old (2006). It doesn’t compile with MonoGame; I tried modifying it to get it to work, but I have no prior experience with MonoGame or XNA (and very little with C#), so once I did get it to compile, it just didn’t work (no images were rendered… just a blank window).

So, I’m just wondering whether anyone has any modern examples of how to write a custom sprite batch in MonoGame / XNA 4.0. The reason I can’t use the built-in spritebatch for my current [and first MonoGame] project is that I need to be able to specify vertex coordinates for the quads being rendered, for the sake of scaling/rotation/etc. that’s already built into the 2D engine I’m trying to port. Custom shaders are also something my engine needs, but I think that’s supported with the default spritebatch as well.

I hope that makes sense and isn’t too rambly. That’s what I get for trying to post while very tired. :smile:

SpriteBatch.Begin and transformMatrix parameter is not good enough?

2 Likes

I don’t think so, but correct me if I’m wrong, as it’s been a long time since I’ve worked with matrix math. If I can accomplish my goal with the built-in sprite batcher, by all means, I’d like to do so.

My goal is to transform individual vertices. Rather than transforming an entire quad (or, technically, both triangles) by a certain xyz amount, I’d like to transform each corner of the quad (most vertices of the triangles) by a certain xyz amount.

That might sound strange, but I have some pseudo-2.5D effects that rely on doing so, which I’ve built with another library and am hoping to port to MonoGame.

On second thought, after doing a little more documentation-digging, it looks like that will work. Sweet. :smiley: