public void Invalidate(int texture, IFrame frame) { if (texture < 0 || texture >= _animationData.SpriteSheets.Count) { return; } var name = _animationData.SpriteSheets[texture]; _frames.Remove(new Tuple <string, int>(name, frame.GetHashCode())); }
public BitmapSource this[int texture, IFrame frame] { get { if (texture < 0 || texture >= _animationData.SpriteSheets.Count || frame == null) { return(null); } var name = _animationData.SpriteSheets[texture]; var tuple = new Tuple <string, int>(name, frame.GetHashCode()); if (_frames.TryGetValue(tuple, out BitmapSource bitmap)) { return(bitmap); } //if (!frame.IsEmpty) if (frame.Width > 0 && frame.Height > 0) { var textureBitmap = GetTexture(texture); try { bitmap = new CroppedBitmap(textureBitmap, new System.Windows.Int32Rect() { X = frame.X, Y = frame.Y, Width = frame.Width, Height = frame.Height }); } catch (ArgumentException) { } } else { bitmap = BitmapSource.Create(1, 1, 96, 96, PixelFormats.Bgr24, null, new byte[3] { 0, 0, 0 }, 3); } return(_frames[tuple] = bitmap); } }