3
votes

I am trying to create an animated sprite from a spritesheet in wpf. The current technique I am using is breaking down an image of containing all the frames of the animation into separate images and just swapping them out.

However this is costly on memory and was wondering if there is a way to just draw a section of an image (specify the source rectangle) rather than splitting the image up.

1
You should post some code so we can help you. - aybe
Maybe you if you could convert to Path - Tico
here is a link that describesw the current technique i am using: programmingwithkinect.wordpress.com/2013/04/09/… - Damir Bojan

1 Answers

2
votes

You can definitely do this. In order for this to be supported by WPF's built-in animation system you need to animate a dependency property. In your case it seems you want to animate the SourceRect property of a CroppedBitmap using a RectAnimationUsingKeyFrames with the DiscreteRectKeyFrame class.

If you're displaying the image using an Image element then you would set it's Source property to a CroppedBitmap, then the cropped bitmap would have its Source property set to a BitmapImage. The cropped bitmap wraps the standard bitmap and adds cropping functionality.