Click or drag to resize

SpriteSpriteHitsSprite Event

This happens when two sprites hit each-other. The SpriteEventArgs that is returned contains the sprite that this sprite hits.

Namespace:  SpriteLibrary
Assembly:  SpriteLibrary (in SpriteLibrary.dll) Version: 1.0.0.6 (1.0.0.6)
Syntax
C#
public event SpriteSpriteEventHandler SpriteHitsSprite

Value

Type: SpriteLibrarySpriteSpriteEventHandler
Examples
 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();
    }
}
See Also