public static AnimationSpec Create(Texture2D spriteSheetTexture, int frameWidth, int frameHeight, int duration, bool isRepeating) { var spec = new AnimationSpec { SpriteSheet = spriteSheetTexture.Name, Duration = duration, Repeating = isRepeating }; int cols = spriteSheetTexture.Width / frameWidth; int rows = spriteSheetTexture.Height / frameHeight; spec.NumberOfFrames = cols * rows; spec.Frames = new Rectangle[spec.NumberOfFrames]; int x = 0; int y = 0; for (int i = 0; i < spec.NumberOfFrames; i++) { spec.Frames[i] = new Rectangle(x, y, frameWidth, frameHeight); x += frameWidth; if (x >= spriteSheetTexture.Width) { x = 0; y += frameHeight; } } return(spec); }
public AnimatedSprite(AnimationSpec spec) { _spec = spec; }