Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on a simple 2D game that is similar to the classic Invader arcade. What I want to know is:

How can I draw a new sprite over the player sprite upon colliding with an enemy/a bullet? Better yet, how can I hide the player so that the hit animation can be shown?

I got the collision detection up and running except for the hit animation. It's being drawn behind the player current position which is awkward.

share|improve this question
Maybe give us your draw code, then it would be easier to help. – zacharmarz Mar 13 '12 at 7:17
Never mind everyone. I just got it. All I have to do is change from spriteBatch.Begin(SpriteSortMode.BackToFront,BlendState.AlphaBlend) to spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.AlphaBlend) – Tommy Mar 13 '12 at 7:29
Try not to use Immediate, but rather use Defered. If it will work, it will be better. – zacharmarz Mar 13 '12 at 8:16
"If it will work, it will be better." Incredibly overgeneralized statement that's not true for many scenes that use multiple render states. – ClassicThunder Mar 15 '12 at 20:11

Please investigate the parameters of the spriteBatch.Draw-method. Try not to feel intimidated by the sheer number of parameters of the largest one. The last parameter there is the "layerDepth" which should be a floating point value between 0 and 1. This parameter will be used (only) if you begin your drawing with SpriteSortMode.BackToFront or FrontToBack. If you make use of the layerDepth you don't have to worry to make the Draw()-calls in any particular order.

share|improve this answer
Is that the best approach? I tend to add a Z field and sort sprites by Z before rendering. – ashes999 Dec 31 '12 at 21:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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