public TiledSprite(TilesetTexture tilesetTexture, Vector2 position, Vector2 scale, int tileIndex) : base()
 {
     _texture    = tilesetTexture.Tex;
     _scale      = scale;
     Rows        = tilesetTexture.Rows;
     Columns     = tilesetTexture.Columns;
     TileIndex   = tileIndex;
     _multiTiled = false;
     Initialize();
 }
示例#2
0
        public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, GameObjectSettings settings)
        {
            Settings = settings;

            GL.DepthFunc(DepthFunction.Lequal);
            //GL.DepthFunc(DepthFunction.Always); // Ignores stored depth values, but still writes them

            // Tileset textures
            {
                // Set up tileset textures
                IEnumerable <Tileset> tilesets      = world.TilesetTable.GetTilesetImages();
                TilesetImage[]        tilesetImages = tilesets.Select(
                    t =>
                    new TilesetImage(
                        t.Image.Source,
                        new Vector2I(t.Tilewidth, t.Tileheight),
                        new Vector2I(t.Spacing),
                        world.TilesetTable.TileBorder))
                                                      .ToArray();

                TilesetTexture = renderer.TextureManager.Get <TilesetTexture>(tilesetImages);
            }

            // Set up tile grid shader
            {
                Effect = renderer.EffectManager.Get <NoEffectOffset>();
                renderer.EffectManager.Use(Effect); // Need to use the effect to set uniforms

                // Set up static uniforms
                Vector2I fullTileSize = world.TilesetTable.TileSize + world.TilesetTable.TileMargins +
                                        world.TilesetTable.TileBorder * 2; // twice the border, on each side once
                Vector2 tileCount = (Vector2)TilesetTexture.Size / (Vector2)fullTileSize;
                Effect.TexSizeCountUniform(new Vector3I(TilesetTexture.Size.X, TilesetTexture.Size.Y, (int)tileCount.X));
                Effect.TileSizeMarginUniform(new Vector4I(world.TilesetTable.TileSize, world.TilesetTable.TileMargins));
                Effect.TileBorderUniform(world.TilesetTable.TileBorder);

                Effect.AmbientUniform(new Vector4(1, 1, 1, EffectPainter.AmbientTerm));
            }

            // Set up geometry
            if (settings.Use3D)
            {
                Cube = renderer.GeometryManager.Get <DuplicatedCube>();
            }
            else
            {
                Cube = renderer.GeometryManager.Get <Quad>();
            }

            IgnoredGameObjects.Clear();
        }
示例#3
0
        /// <summary>
        /// Gets multiple tiles that fit the supplied rectangle
        /// and makes it into a single texture.
        /// Eeach unit in the suplied rectangle is
        /// </summary>
        /// <param name="rect">The area of the tileset to get</param>
        /// <returns></returns>
        public Texture2D GetTile(Rectangle rect)
        {
            rect.Width  = (rect.Width) * TileDimensions;
            rect.Height = (rect.Height) * TileDimensions;
            rect.X     *= TileDimensions;
            rect.Y     *= TileDimensions;

            int dimensions = rect.Width * rect.Height * (TileDimensions ^ 2);

            Color[] tileData = new Color[dimensions];

            TilesetTexture.GetData <Color>(0, rect, tileData, 0, dimensions);

            Texture2D tile = new Texture2D(TilesetTexture.GraphicsDevice, rect.Width, rect.Height);

            tile.SetData <Color>(tileData);

            return(tile);
        }
示例#4
0
        public override void Init(RendererBase <ToyWorld> renderer, ToyWorld world, OverlaySettings settings)
        {
            Settings = settings;

            // Set up overlay textures
            IEnumerable <Tileset> tilesets = world.TilesetTable.GetOverlayImages();

            TilesetImage[] tilesetImages = tilesets.Select(t =>
                                                           new TilesetImage(
                                                               t.Image.Source,
                                                               new Vector2I(t.Tilewidth, t.Tileheight),
                                                               new Vector2I(t.Spacing),
                                                               world.TilesetTable.TileBorder))
                                           .ToArray();

            m_overlayTexture = renderer.TextureManager.Get <TilesetTexture>(tilesetImages);

            // Set up overlay shader
            m_overlayEffect = renderer.EffectManager.Get <NoEffectOffset>();
            renderer.EffectManager.Use(m_overlayEffect); // Need to use the effect to set uniforms

            // Set up static uniforms
            Vector2I tileSize    = tilesetImages[0].TileSize;
            Vector2I tileMargins = tilesetImages[0].TileMargin;
            Vector2I tileBorder  = tilesetImages[0].TileBorder;

            Vector2I fullTileSize = tileSize + tileMargins + tileBorder * 2; // twice the border, on each side once
            Vector2  tileCount    = (Vector2)m_overlayTexture.Size / (Vector2)fullTileSize;

            m_overlayEffect.TexSizeCountUniform(new Vector3I(m_overlayTexture.Size.X, m_overlayTexture.Size.Y, (int)tileCount.X));
            m_overlayEffect.TileSizeMarginUniform(new Vector4I(tileSize, tileMargins));
            m_overlayEffect.TileBorderUniform(tileBorder);

            m_overlayEffect.AmbientUniform(new Vector4(1, 1, 1, 1));

            QuadOffset = renderer.GeometryManager.Get <Quad>();
        }