protected override void Update(GameTime gameTime) { base.Update(gameTime); if (_addedLast == null || (DateTime.Now - _addedLast.Value).TotalMilliseconds >= RectangleAddDelayInMs) { var color = new Color(_random.Next(0, 256), _random.Next(0, 256), _random.Next(0, 256)); var width = _random.Next(1, MaximumRectangleSize); var height = _random.Next(1, MaximumRectangleSize); var pr = _packer.PackRect(width, height, color); // Double the size of the packer until the new rectangle will fit while (pr == null) { Packer newPacker = new Packer(_packer.Width * 2, _packer.Height * 2); // Place existing rectangles foreach (PackerRectangle existingRect in _packer.PackRectangles) { newPacker.PackRect(existingRect.Width, existingRect.Height, existingRect.Data); } // Now dispose old packer and assign new one _packer.Dispose(); _packer = newPacker; // Try to fit the rectangle again pr = _packer.PackRect(width, height, color); } _addedLast = DateTime.Now; } }
private void CreateNewTexture2D() { Texture2D texture = new Texture2D(_device, _width, _height, false, _format); _textureList.Add(texture); _packer?.Dispose(); _packer = new Packer(_width, _height); }
private static Packer PackImages(string[] imageFiles, int width, int height) { Console.WriteLine("Atlas Size: {0}x{1}", width, height); var packer = new Packer(width, height); foreach (var file in imageFiles) { Console.WriteLine("Processing {0}...", file); ImageResult image; using (var stream = File.OpenRead(file)) { image = ImageResult.FromStream(stream, StbImageSharp.ColorComponents.RedGreenBlueAlpha); } var imageInfo = new ImageInfo { Path = file, Image = image }; var name = Path.GetFileNameWithoutExtension(file); if (name.EndsWith(".9")) { ProcessNinePatch(imageInfo); } Console.WriteLine("Size: {0}x{1}, Components: {2}", image.Width, image.Height, image.SourceComp); var packRectangle = packer.PackRect(image.Width, image.Height, imageInfo); // Double the size of the packer until the new rectangle will fit while (packRectangle == null) { Packer newPacker = new Packer(packer.Width * 2, packer.Height * 2); Console.WriteLine("Image didnt fit. Thus atlas size had been doubled: {0}x{1}", newPacker.Width, newPacker.Height); // Place existing rectangles foreach (PackerRectangle existingRect in packer.PackRectangles) { newPacker.PackRect(existingRect.Width, existingRect.Height, existingRect.Data); } // Now dispose old packer and assign new one packer.Dispose(); packer = newPacker; // Try to fit the rectangle again packRectangle = packer.PackRect(image.Width, image.Height, imageInfo); } } return(packer); }
public void Dispose() { foreach (Texture2D texture in _textureList) { if (!texture.IsDisposed) { texture.Dispose(); } } _packer.Dispose(); _textureList.Clear(); }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { _destination?.Dispose(); _packer?.Dispose(); } _disposedValue = true; } }
public void Dispose() { _stream.Dispose(); _tcpClient.Dispose(); _packer.Dispose(); }
public void close() { packer.Dispose(); stream.Close(); }