Troubleshooting this TutorialSometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on Additive Sprites. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used. If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it. If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more. |
Common MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
I use visual c# 2010 express edition with the new xna game studio 4 and it seems that there isn't a "SpriteBlendMode" to use. I was wondering what i should use instead?
I think you may want to try this line of code for your spriteBatch.Begin() method:
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
I don't think SpriteBlendMode exists in 4.0, so that should make things work.
In XNA3 I used:
spriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.None);
how can i use this additive blending only on some elements of the spritebatch?
i made this modification in the particles of the particle engine, but if i call the spriteBatch.Begin
(SpriteSortMode.Immediate, BlendState.Additive);
the game exit, and the compiler says that i have to call the end method before call another begin.
but if i call this in the main draw, where i draw all the other object, everything is under the additive blending…
so, how i can do additive blending only on the particle and not on all the scene?
ok, i have resolved! :)
if someone want to know something about this issue, this is my solution:
you have to declare ANOTHER SPRITEBACH in the main Draw method, so when the normal sprite batch end with the .End method, you can call the newSpritebatch.Begin method with the (SpriteSortMode.Immediate, BlendState.Additive) parameters.
using this method everything in the first Spritebatch is rendered as normal, and everything is rendered in the second spritebatch is with the Additive Blending function!
You'll have to do the two in separate batches.
I don't know your code, but I suspect this will be something a little like this in your main Draw method:
really thanks for your explanation.
but if after a few minutes (you're really great at responding so quickly!) I had thought too, and in fact I had thought of writing for sharing it!
REALLY THANKS FOR THIS TUTORIAL, now the particles are indeed SPECTACULAR!
Good! I'm glad you found a way to get it working!
You really shouldn't need to create a second actual SpriteBatch object though. Just use the same one a second time, with different parameters for Begin, like I described. I haven't measured it, but I'd guess that building a new sprite batch (especially if it's every frame) is going to take longer than just calling the Begin method more than once. It may not be slow enough to affect your game, but it might.
But if it works for you, then it works, so do what you want. :)
I'd like to know why all that cosinus/sinus stuff goes into the Draw-section and not the Update-section. I mean, it's not actual drawing, it's just calculating the position of the sprites, right?
That's a great question, Erik. I think you could argue it either way. You're hitting on the point about how in Update, you should nothing but update your game state, and in Draw, you should do nothing but drawing things, and the two should never mix.
So the question that remains to be answered here is, what constitutes my game state?
When I wrote this code, I had in mind that the game state defined these three objects by a distance and direction from the origin. That is, everything was essentially defined in polar coordinates. So in my Update method, I simply update those polar coordinates. When I'm drawing, I need things in the normal Cartesian coordinates (because that's what the screen works with) so I convert it to Cartesian at the last moment, in the Draw method. In this case, I treat it as a part of getting stuff drawn to the screen, and not a part of the underlying model for my game.
In fact, what I did is not all that different from building a world transformation matrix in 3D, which is a normal operation to do at draw time. I'm simply converting from one coordinate system to another.
Obviously, not everyone is going to use polar coordinates for their underlying game model. (I'd say, more often than not, you'll be using Cartesian instead.) In the event that you see your game state as being done in Cartesian coordinates, this computation with the sines and cosines should most definitely be done in the Update method, as you suggest.
Post preview:
Close preview