Change image on Sprite.

Mar 10, 2011 at 9:27 PM

How do I change an Image on a Sprite so that I can animate it.

Thanks  Stuart

Mar 12, 2011 at 1:57 PM

Have you tried calling Sprite.SetAssetParts?


Mar 12, 2011 at 3:19 PM

HI, Yes sorry did not explain myself very well the first time. I have some Sprite sheets which I break down into images

These sheets come from a data source. Is it possible to assign the in memory images to the sprites. I am probably

missing somthing !!.

Mar 15, 2011 at 2:13 AM
Edited Mar 15, 2011 at 2:17 AM

I think I might be missing something about what you are trying to do. You can just create a Balder image with the in memory bitmaps.
Here is some code to do that. Then just assign that Balder image to the Sprite.SetAssetParts. To do this you’ll need a ContentManager,
which can be found from the Game object.

        public static Balder.Imaging.Image ToBalderImage(this WriteableBitmap bmp, Balder.Content.IContentManager ContentManager)
            var img = ContentManager.CreateAssetPart<Balder.Imaging.Image>();
            img.Width = bmp.PixelWidth; img.Height = bmp.PixelHeight;
            img.ImageContext.SetFrame(bmp.ToByteArray(), img.Width, img.Height);
            return img;

Is this what your after?  If not please explain again, I'm happy to try and help.

-Edit:  I just noticed you posted almost this same code to another thread.  So this isn't what your after! sorry!  I am afraid I still do not
understand what you are trying to do.

Mar 15, 2011 at 7:19 AM

Thats what I want to do but without using the Content manager, but from another look at the code I think for now it has to be done via the Content Manager

and then I need to Clear it out from the content manager and the Cache. The animated sprites only use the sheet once for a few seconds and then it gets replaced

with new data hence why I am looking to load direct onto the sprite. Thanks for your help Stuart.

Mar 15, 2011 at 5:11 PM

SpriteSheets is something I've wanted to add support for - sorry it is not there yet. We'll get there eventually. For now the suggestion from xersoft is probably the best way.