Click or drag to resize

SpriteSpriteHitsPictureBox Event

This happens when the sprite hits the border of the picture-box. Useful for when you want to have shots explode when they hit the side.

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

Value

Type: SpriteLibrarySpriteSpriteEventHandler
Examples
Here is an example of us defining a Sprite. We retrieve a named Sprite and set the function on the master template to call the SpriteBounces function whenever the Sprite hits the picturebox.

You only need to add the function once, if you are putting it on the Named Sprite. After that time, all the sprites duplicated from the template will have this function set for them.

public void DefineSprite()
{
    Sprite mySprite = MySpriteController.SpriteFromName("Ball");
    mySprite.SpriteHitsPictureBox += SpriteBounces;
}

public void SpriteBounces(object sender, EventArgs e)
{
   Sprite me = (Sprite)sender;
   int degrees = (int)me.GetSpriteDegrees();
   if (Math.Abs(degrees) > 120)
   {
       me.SetSpriteDirectionDegrees(0);//go right
   }
   else
   {
       me.SetSpriteDirectionDegrees(180); //go back left
   }
}
See Also