예제 #1
0
        public void DrawBox(SpriteBatch spriteBatch, TileableTexture Texture, int x, int y, int w, int h, float opacity = 1f)
        {
            spriteBatch.Begin();
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int xs = 0;
                    int ys = 0;

                    if (j == 0)
                    {
                        xs++;
                        if (i == 0)
                        {
                            xs--;
                        }
                        else if (i == w - 1)
                        {
                            xs++;
                        }
                    }
                    else if (i == 0)
                    {
                        ys++;
                        if (j == h - 1)
                        {
                            ys++;
                        }
                    }
                    else if (i == w - 1)
                    {
                        xs++;
                        xs++;
                        ys++;
                        if (j == h - 1)
                        {
                            ys++;
                        }
                    }
                    else if (j == h - 1)
                    {
                        xs++;
                        ys++;
                        ys++;
                    }
                    else
                    {
                        xs++;
                        ys++;
                    }

                    Rectangle sourceRectangle = Texture.GetSource(Texture.GetIndex(xs, ys));
                    spriteBatch.Draw(Texture.Texture, new Rectangle(x + i * Texture.FrameWidth, y + j * Texture.FrameHeight, Texture.FrameWidth, Texture.FrameHeight), sourceRectangle, Color.White * opacity);
                }
            }
            spriteBatch.End();
        }
예제 #2
0
        public void DrawSprite(int x, int y, string location, int columns, int rows, int xt, int yt, float opacity)
        {
            Texture2D sprite = this.player.World.SpriteLibrary.GetSprite(location);

            if (sprite != null)
            {
                TileableTexture tileable = new TileableTexture(sprite, columns, rows);
                spriteBatch.Draw(sprite, new Rectangle(x, y, tileable.FrameWidth, tileable.FrameHeight), tileable.GetSource(tileable.GetIndex(xt, yt)), Color.White * opacity);
            }
        }
예제 #3
0
        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            int ypos = vscrollbar.Value;
            int xpos = hscrollbar.Value;

            if (Tileset != null)
            {
                if (Tileset.Texture != null && Tileset.Texture.Texture != null)
                {
                    batch.Begin();
                    batch.Draw(Tileset.Texture.Texture, -new Vector2(xpos, ypos), Color.White);

                    int x = Tileset.Texture.Texture.Width - xpos;
                    int y = Tileset.Texture.Texture.Height - ypos;

                    SelectionUtil.DrawStraightLine(batch, new Color(.9f, .4f, .4f, 1f), 1f, x, -ypos, 2, Tileset.Texture.Texture.Height);                    //vertical
                    SelectionUtil.DrawStraightLine(batch, new Color(.9f, .4f, .4f, 1f), 1f, -xpos, y, 1, Tileset.Texture.Texture.Width);                     //horizontal

                    SelectionUtil.DrawRectangle(batch, new Color(.7f, .1f, 0f, .6f), new Rectangle((xt << 4) - xpos, (yt << 4) - ypos, 16, 16));
                    SelectionUtil.FillRectangle(batch, new Color(.4f, .1f, 0f, .6f), new Rectangle((xt << 4) + 1 - xpos, (yt << 4) + 1 - ypos, 16, 16));

                    int ry = 0;
                    int rx = 0;
                    foreach (Tile t in Tileset.Tiles)
                    {
                        if (rx + 1 > Tileset.Texture.Texture.Width / 16)
                        {
                            rx = 0;
                            ry++;
                        }
                        batch.Draw(ox.Texture, new Rectangle((rx << 4) - xpos, (ry << 4) - ypos, 16, 16), ox.GetSource(t.DefaultBehavior.BehaviorId == this.Behavior ? 0 : 1), Color.White * 0.8f);
                        rx++;
                    }
                    batch.End();
                }
            }

            base.Draw(gameTime);
        }
예제 #4
0
        public void Dump()
        {
            try {
                Texture2D             texture         = Texture2D.FromStream(this.GraphicsDevice, File.OpenRead(@"C:\Users\Oxysoft\Desktop\_splitter_tool\input.png"));
                string                dumploc         = @"C:\Users\Oxysoft\Desktop\_splitter_tool\newdump\";
                const int             cols            = 10;
                const int             rows            = 10;
                TileableTexture       tileableTexture = new TileableTexture(texture, cols, rows);
                List <RenderTarget2D> results         = new List <RenderTarget2D>();
                Color chroma1 = new Color(0xBF, 0xC8, 0xFF);
                Color chroma2 = new Color(0xD8, 0xDE, 0xFF);
                for (int y = 0; y < rows; y++)
                {
                    for (int x = 0; x < cols; x++)
                    {
                        int[] order = new int[4 * 4];

                        order[0]  = 5;
                        order[1]  = 11;
                        order[2]  = 5;
                        order[3]  = 8;
                        order[4]  = 6;
                        order[5]  = 3;
                        order[6]  = 6;
                        order[7]  = 9;
                        order[8]  = 1;
                        order[9]  = 4;
                        order[10] = 1;
                        order[11] = 7;
                        order[12] = 0;
                        order[13] = 2;
                        order[14] = 0;
                        order[15] = 10;

                        RenderTarget2D  renderTarget         = new RenderTarget2D(GraphicsDevice, 96, 128);
                        TileableTexture tileableRenderTarget = new TileableTexture(renderTarget, 3, 4);
                        GraphicsDevice.SetRenderTarget(renderTarget);
                        SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice);
                        spriteBatch.Begin();
                        spriteBatch.Draw(texture, new Rectangle(0, 0, 96, 128), tileableTexture.GetSource(tileableTexture.GetIndex(x, y)), Color.White);
                        spriteBatch.End();
                        GraphicsDevice.SetRenderTarget(null);
                        RenderTarget2D  resultTarget         = new RenderTarget2D(GraphicsDevice, 128, 128);
                        TileableTexture tileableResultTarget = new TileableTexture(resultTarget, 4, 4);
                        GraphicsDevice.SetRenderTarget(resultTarget);
                        GraphicsDevice.Clear(Color.Transparent);

                        spriteBatch.Begin();
                        for (int i = 0; i < order.Length; i++)
                        {
                            Rectangle target = tileableResultTarget.GetSource(i);
                            spriteBatch.Draw(renderTarget, target, tileableRenderTarget.GetSource(order[i]), Color.White);
                        }
                        spriteBatch.End();
                        GraphicsDevice.SetRenderTarget(null);

                        //----> Start of CHROMA CLEARING
                        Color[] colors = new Color[resultTarget.Width * resultTarget.Height];
                        resultTarget.GetData <Color>(colors);

                        for (int i = 0; i < colors.Length; i++)
                        {
                            if (colors[i] == chroma1 || colors[i] == chroma2)
                            {
                                colors[i] = Color.Transparent;
                            }
                        }

                        resultTarget.SetData <Color>(colors);
                        //End of CHROMA CLEARING <----

                        results.Add(resultTarget);
                    }
                }
                for (int i = 0; i < results.Count; i++)
                {
                    results[i].SaveAsPng(File.OpenWrite(dumploc + i + ".png"), results[i].Width, results[i].Height);
                }
            } catch (Exception e) {
                Console.WriteLine("what da fack");
            }
        }