/// <summary> /// loads a sprite from a SimpleArchive. /// </summary> public SpriteManager LoadSpriteManager(SimpleArchive sar) { SpriteManager ret = new SpriteManager(); ret.frames = new Image[sar.numFiles]; ret.NumFrames = sar.numFiles; for (int i=0; i<sar.numFiles; i++) using (Stream s = sar.open(sar.sortedFiles[i])) ret.frames[i] = Game.LoadImage(s); return ret; }
/// <summary> /// loads a spritemanager by dicing a source image /// </summary> public SpriteManager LoadSpriteManager(Image source, int width, int height, int xpad, int ypad) { //TODO - don't do this with blitting. that way we can keep the source texture format. but this will work for now.. SpriteManager ret = new SpriteManager(); int framesAcross = source.Width / (width+xpad); int framesDown = source.Height / (height+ypad); ret.NumFrames = framesAcross*framesDown; ret.frames = new Image[ret.NumFrames]; int ctr=0; DisableAlphaBlend(); for (int iy=0; iy<framesDown; iy++) { for(int ix=0;ix<framesAcross; ix++,ctr++) { Image img = NewImage(width, height); ret.frames[ctr] = img; Blitter b = new Blitter(img); //b.Clear(Color.Transparent); b.Blit(source, -ix*(width+xpad), -iy*(height+ypad)); img.Cache(); img.Premultiply(); } } EnableAlphaBlend(); return ret; }