Ejemplo n.º 1
0
        public Rect ShrinkFrameSelect(Texture tex, Rect selectionRect, double alphaTolerance)
        {
            var x = selectionRect.Left - _currentShownSpriteSheet.BoundingRect.Left;
            var y = selectionRect.Top - _currentShownSpriteSheet.BoundingRect.Top;
            var translatedRect = Rect.FromBox(x, y, selectionRect.Width, selectionRect.Height);

            return(SpriteSheetAndTextureFuncs.ShrinkFrameSelect(tex, translatedRect, alphaTolerance));
        }
Ejemplo n.º 2
0
        public void SortFrames()
        {
            var rects = new List <Rect>();

            foreach (SpriteSheetFrame frameRect in Frames)
            {
                rects.Add(frameRect.BoundingRect);
            }

            Frames.Clear();

            SpriteSheetAndTextureFuncs.SortFramesLeftToRightTopToDown(rects);

            foreach (Rect rect in rects)
            {
                AddFrame(rect);
            }
        }
Ejemplo n.º 3
0
        public void CutSpriteSheetByAlpha()
        {
            if (Guard.CheckNull(_currentShownSpriteSheet))
            {
                Messager.ShowMessage(Messager.Mode.Exception,
                                     "No spritesheet loaded! Please load a sprite sheet first by clicking the button 'Import Spritesheet' on topbar");
                return;
            }

            if (_currentShownSpriteSheet.Frames.Count > 0)
            {
                _currentShownSpriteSheet.Frames.Clear();
            }

            var frameRects = SpriteSheetAndTextureFuncs.CutByAlpha(_currentShownSpriteSheet.Texture);

            foreach (var frameRect in frameRects)
            {
                _currentShownSpriteSheet.AddFrame(frameRect);
            }
        }
Ejemplo n.º 4
0
        public SpriteSheetResourceData LoadSpriteSheetFromSeparateImages(Bitmap[] images)
        {
            BitmapAtlas imageAtlas = new BitmapAtlas();


            for (int i = 0; i < images.Length; i++)
            {
                var image = images[i];
                if (!(Image.IsAlphaPixelFormat(image.PixelFormat)))
                {
                    ImageHelper.AdjustImagePixelFormat(ref image);
                }
                imageAtlas.AddImage(i.ToString(), image);
            }

            var spTex = imageAtlas.ToTexture(PixelFormat.DefaultAlpha);


            var finalSpTex = SpriteSheetAndTextureFuncs.TrimmByAlpha(spTex);

            finalSpTex.Options.Filter = Configuration.TextureFilterMode;

            spTex.Dispose();


            var id = string.Format("{0}", _spriteSheetsImages.Count);

            var spName = string.Format("AssembledSpriteSheet{0}", id);

            var spriteSheetResource = new SpriteSheetResourceData(spName, id, finalSpTex);

            _spriteSheetsImages.Add(id, spriteSheetResource);

            imageAtlas.Dispose();

            return(spriteSheetResource);
        }