Reputation: 399
Here's my problem I am using a depth control but now i have different sprites that need different blendstates how can i change this if I already started the spritebatch.begin(...)
I was trying to change spritebatch.graphicsDevice.blendstate but it doesn't seems to be working
I cannot turn a black area into transparency
Thank you
Still seems it cannot save the layer order between them by using that code...
I guess the problem might be in using object.draw(spritebatch) and then draw inside the method.
I think theres a problem because i have 2 classes each one with a draw method with input spritebatch
this is what im doing
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.Additive);
d.drawAttack(gameTime, spriteBatch);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
drawObjects(gameTime, spriteBatch);
charactersDraw(gameTime, spriteBatch); // same class as the d.drawAttack
spriteBatch.End();
they both draw but the layer !BETWEEN both spritebatche! doesn't seems to make any difference
the layerdepth works fine with characters and draw objects... only doesn't work with drawAttack
Upvotes: 0
Views: 2398
Reputation:
You need to do multiple SpriteBatch.Begin() .. End() calls, each with a different BlendState. You can still preserve your layerDepth among them.
For example:
batch.Begin(SpriteSortMode.FrontToBack, BlendState.Additive);
batch.Draw(tex1, sprite1, null, Color.White, 0.0f, Vector2.Zero, 1.0f,
SpriteEffects.None, layer1);
batch.Draw(tex2, sprite2, null, Color.White, 0.0f, Vector2.Zero, 1.0f,
SpriteEffects.None, layer2);
batch.End();
//new blend state, new begin...end
batch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
batch.Draw(tex3, sprite3, null, Color.White, 0.0f, Vector2.Zero, 1.0f,
SpriteEffects.None, layer3);
batch.Draw(tex4, sprite4, null, Color.White, 0.0f, Vector2.Zero, 1.0f,
SpriteEffects.None, layer4);
batch.End();
Upvotes: 0