Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created August 5, 2012 19:26
Show Gist options
  • Save demonixis/3266800 to your computer and use it in GitHub Desktop.
Save demonixis/3266800 to your computer and use it in GitHub Desktop.
Expression Lambda with C#
public void AddExplosion(int x, int y)
{
Sprite explode = new Sprite("SFX/explosion2");
explode.LoadContent();
explode.Position = new Vector2(x, y);
explode.PrepareAnimation(94, 94);
explode.AddAnimation("0", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, 25, false);
// Expression Lambda
// equivalent à explode.GetAnimation("0").AnimationComplete += onAnimationComplete;
// et ensuite déclaration d'une fonction de callback public void onAnimationComplete(object sender, EventArgs e) { }
explode.GetAnimation("0").AnimationComplete += (sender, e) =>
{
explode.Kill();
_recycled.Add(Members.IndexOf(explode));
};
Add(explode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment