SpriteSpriteHitsSprite Event |
Namespace: SpriteLibrary
public event SpriteSpriteEventHandler SpriteHitsSprite
public void DefineSprite() { Sprite mySprite = MySpriteController.SpriteFromName("Monster"); mySprite.SpriteHitsSprite += MonsterHitBySprite; } public void MonsterHitBySprite(object sender, SpriteEventArgs e) { Sprite me = (Sprite)sender; //Check to see if we got hit by a "shot" sprite if (e.TargetSprite.SpriteOriginName == "Shot") { //we got shot. DIE! Sprite nSprite = MySpriteController.DuplicateSprite("Explosion"); nSprite.PutBaseImageLocation(me.BaseImageLocation); //put the explosion where the "hit" sprite is nSprite.SetSize(me.GetSize); //Use the size of the sprite that got hit. nSprite.AnimateOnce(0); //Animate once. Hopefully the explosion destroys itself when the animation ends //Play a boob sound SoundPlayer newPlayer = new SoundPlayer(Properties.Resources.Boom); newPlayer.Play(); //destroy the sprite that got hit me.Destroy(); //destroy the "shot" sprite that hit us e.TargetSprite.Destroy(); } }