0
\$\begingroup\$

I'm hoping to find out how many sprites are on the screen at any given time.

In other words, is it possible to find out how many times spriteBatch.Draw(); is called between spriteBatch.Begin(); and spriteBatch.End();?

I'm looking for a build-in function. Although I'm more then happy to write something myself, I'd rather not reinvent the wheel, and maybe I've overlooked something.

\$\endgroup\$
1
\$\begingroup\$

There is no built-in function.

You're using MonoGame, so you could just modify the MonoGame source to do exactly what you want.

You could also use reflection to get access to the internal SpriteBatch member that holds the current count. In XNA it's the spriteQueueCount field. MonoGame seems to be more complicated - look at the source code to determine what to reflect on.

Otherwise, the "nicest" thing to do, code-wise, would be to make a wrapper function for Draw. Or simply manually increment your own counter every time you call Draw.

Note that this will give you the number of sprites drawn - which is not necessaraly the same as the number that appear "on screen".

If you're just trying to measure performance during development, it might be better to do something at the GPU level (I used to recommend PIX for this, with XNA on DirectX 9 - you'll have to figure out what works best for MonoGame on your target platform).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.