Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
1  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.