Exemplo n.º 1
0
        public Map(string filename)
        {
            tileset = Assets.Tileset;
            var jsonString = System.IO.File.ReadAllText(filename);
            var json       = JObject.Parse(jsonString);
            var map        = json["layers"][0];

            Size = new Size((int)map["gridCellsX"], (int)(map["gridCellsY"]));
            var coords = map["data2D"];

            float tileScale = TileWidth / TileSetGrid;

            spriteBatch = Love.Graphics.NewSpriteBatch(tileset, Size.Width * Size.Height, SpriteBatchUsage.Static);

            spriteBatch.Clear();
            var blockQuad  = Graphics.NewQuad(0, TileSetGrid, TileSetGrid, TileSetGrid, TileSetGrid * 4, TileSetGrid * 4);
            var grassQuads = new Quad[]
            {
                Graphics.NewQuad(0, 0, TileSetGrid, TileSetGrid, TileSetGrid * 4, TileSetGrid * 4),
                Graphics.NewQuad(TileSetGrid, 0, TileSetGrid, TileSetGrid, TileSetGrid * 4, TileSetGrid * 4),
                Graphics.NewQuad(TileSetGrid * 2, 0, TileSetGrid, TileSetGrid, TileSetGrid * 4, TileSetGrid * 4)
            };

            Blocks = new List <Rectangle>();

            for (int i = 0; i < Size.Width; i++)
            {
                for (int j = 0; j < Size.Height; j++)
                {
                    int coord = (int)coords[j][i];

                    switch (coord)
                    {
                    case 3:
                        spriteBatch.Add(blockQuad, i * TileWidth, j * TileWidth, 0, tileScale, tileScale);
                        Blocks.Add(new Rectangle(i * TileWidth, j * TileWidth, TileWidth, TileWidth));
                        break;

                    case 2:
                        var index = 2;
                        var rand  = Mathf.Random(0, 100);
                        if (rand < 10)
                        {
                            index = 0;
                            if (rand < 5)
                            {
                                index = 1;
                            }
                        }
                        spriteBatch.Add(grassQuads[index], i * TileWidth, j * TileWidth, 0, tileScale, tileScale);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Window window = new Window(new Point2(800, 600), "TKGameUtilities example", false, GraphicsMode.Default);

            window.KeyboardDefault.KeyDown += KeyboardDefault_KeyDown;
            window.Show();

            ColoredPrimitiveShader       coloredPrimitiveShader       = new ColoredPrimitiveShader();
            AlphaTexturedPrimitiveShader alphaTexturedPrimitiveShader = new AlphaTexturedPrimitiveShader();
            TexturedPrimitiveShader      texturedPrimitiveShader      = new TexturedPrimitiveShader();

            IndexedPrimitiveBatch primitiveBatch = new IndexedPrimitiveBatch();

            Font      font      = new Font(Environment.GetFolderPath(Environment.SpecialFolder.Fonts) + "\\arial.ttf", 16);
            FontBatch fontBatch = new FontBatch();

            Texture     texture     = new Texture("sprite.png");
            SpriteBatch spriteBatch = new SpriteBatch();

            while (window.Visible)
            {
                window.ProcessEvents();

                window.Clear();

                primitiveBatch.Begin();
                primitiveBatch.AddLine(new Vector2(100, 100), new Vector2(300, 300), Color.Cyan, Color.Orange);
                primitiveBatch.End();
                primitiveBatch.Draw(window, coloredPrimitiveShader, PrimitiveBatchDrawOptions.Default);

                fontBatch.Begin();
                fontBatch.Add("This is example text using TTF fonts", font, new Vector2(400, 300), Color.Magenta, new Vector2(1.2f, 1.5f), Vector2.Zero, 30f);
                if (m_spaceToggle)
                {
                    fontBatch.Add("Space key was pressed", font, new Vector2(100, 50), Color.White);
                }
                fontBatch.End();
                fontBatch.Draw(window, alphaTexturedPrimitiveShader, SpriteBatchDrawOptions.Default);

                spriteBatch.Begin();
                spriteBatch.Add(texture, texture.TextureRectangle, new Vector2(200, 300), Color.White, Vector2.One, texture.TextureRectangle.Size / 2, 200f);
                spriteBatch.End();
                spriteBatch.Draw(window, texturedPrimitiveShader, SpriteBatchDrawOptions.Default);

                window.Display();
            }

            coloredPrimitiveShader.Dispose();
            alphaTexturedPrimitiveShader.Dispose();
            primitiveBatch.Dispose();
            font.Dispose();
            fontBatch.Dispose();

            window.Close();
            window.Dispose();
        }
Exemplo n.º 3
0
        private void tlMainTabs_TabPointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            TabViewModel tvm = null;

            if (sender is FrameworkElement)
            {
                var fe = (FrameworkElement)sender;
                if (fe.DataContext is TabViewModel)
                {
                    tvm = (TabViewModel)fe.DataContext;
                }
                else
                {
                    return;
                }


                var visual = fe.TransformToVisual(layoutRoot);
                var point1 = visual.TransformPoint(new Point(0, 0));
                var point2 = new Point(point1.X + fe.ActualWidth + 180, point1.Y + fe.ActualHeight + 140);

                //hide all the current tabs in the canvas
                _spriteBatch.Elements.ToList().ForEach(delegate(IVisualTreeElement element) { element.IsVisible = false; });

                //now delete all the relevant elements in the spritebatch
                _spriteBatch.DeleteAll();

                //create the new thumbnail sprite for current button
                _spriteBatch.Add(new TabThumbnailSprite()
                {
                    Layout = new Rect(point1, point2), ID = const_TabPreview, TextureBackgroundUri = tvm.ThumbUri, IsVisible = true
                });

                _spriteBatch.IsVisible = true;
            }


            CanvasInvalidate();
        }
Exemplo n.º 4
0
 public virtual void AddSprite(Sprite sprite)
 {
     sprite.Load();
     batch.Add(sprite);
 }