Exemple #1
0
 public TextureAtlas(TextureAtlas copy)
 {
     Size = copy.Size;
     _canvas = new Image(copy._canvas);
     Texture = new Texture(_canvas);
     Sources = new IntRect[copy.Sources.Length];
     copy.Sources.CopyTo(Sources, 0);
 }
 public FastTextureAtlas(TextureAtlas atlas)
 {
     TextureAtlas = atlas;
     _atlas = new Sprite(TextureAtlas.Texture);
     RenderTexture = new RenderTexture(atlas.Size, atlas.Size);
     RenderTexture.Draw(_atlas);
     RenderTexture.Display();
     _replace = new RenderStates(BlendMode.None, Transform.Identity, null, null);
 }
 static MapEngineHandler()
 {
     _tileanims = new List<TileAnimHandler>();
     _tileatlas = new TextureAtlas(1024);
     _triggers = new List<Entity>();
     _scripts = new FunctionScript[6];
     _defscripts = new FunctionScript[6];
     _delayscripts = new List<DelayScript>();
 }
Exemple #4
0
        // TODO: create method to rewrite a single tile rather than the whole layer.
        public void UpdateVertexLayer(int layer, TextureAtlas atlas)
        {
            Layer l = Layers[layer];
            int tw = Tileset.TileWidth;
            int th = Tileset.TileHeight;

            int size = l.Width * l.Height * 4;
            Vertex[] lverts = new Vertex[size];
            Vector2f loc1 = new Vector2f(0, 0);
            Vector2f loc2 = new Vector2f(tw, 0);
            Vector2f loc3 = new Vector2f(tw, th);
            Vector2f loc4 = new Vector2f(0, th);
            for (var i = 0; i < lverts.Length; i += 4)
            {
                int tile = l.GetTile((int)loc1.X / tw, (int)loc1.Y / th);
                if (tile >= 0)
                {
                    IntRect source = atlas.Sources[tile];
                    int w = source.Left + source.Width;
                    int h = source.Top + source.Height;
                    lverts[i + 0] = new Vertex(loc1, new Vector2f(source.Left, source.Top));
                    lverts[i + 1] = new Vertex(loc2, new Vector2f(w, source.Top));
                    lverts[i + 2] = new Vertex(loc3, new Vector2f(w, h));
                    lverts[i + 3] = new Vertex(loc4, new Vector2f(source.Left, h));
                }

                loc1.X += tw;
                loc2.X += tw;
                loc3.X += tw;
                loc4.X += tw;
                if (loc1.X == l.Width * tw)
                {
                    loc1.Y += th;
                    loc2.Y += th;
                    loc3.Y += th;
                    loc4.Y += th;
                    loc1.X = loc4.X = 0;
                    loc2.X = loc3.X = tw;
                }
            }

            _vertex_layers[layer] = lverts;
        }
Exemple #5
0
        /// <summary>
        /// Compiles the map into a texture-coordinated vertex array & render states.
        /// </summary>
        /// <returns>The tile map.</returns>
        /// <param name="tileatlas">The tileatlas to get tex-coords from use.</param>
        public Tuple<List<Vertex[]>, RenderStates> GetTileMap(TextureAtlas atlas)
        {
            _states.Texture = atlas.Texture;

            for (int i = 0; i < Layers.Count; ++i)
                UpdateVertexLayer(i, atlas);

            return new Tuple<List<Vertex[]>, RenderStates>(_vertex_layers, _states);
        }
        private void ConstructTextureAtlas(Image[] list)
        {
            if (TextureAtlas == null)
                TextureAtlas = new TextureAtlas(1024);

            TextureAtlas.Update(list);
        }