コード例 #1
0
ファイル: MapLayer.cs プロジェクト: arthursouza/spacecreep
        public void Draw(SpriteBatch batch, Vector2 min, Vector2 max, Tileset tileset, Color color, int opacity)
        {
            Opacity = opacity;
            
            min.X = (int) MathHelper.Max(min.X, 0);
            min.Y = (int) MathHelper.Max(min.Y, 0);
            max.X = (int) MathHelper.Min(max.X, Width);
            max.Y = (int) MathHelper.Min(max.Y, Height);

            for (var x = (int) min.X; x < max.X; x++)
            {
                for (var y = (int) min.Y; y < max.Y; y++)
                {
                    int textureId = Map[y, x];

                    if (textureId != -1 && tileset != null)
                    {
                        //Vector2 offset = Vector2.Zero;
                        Vector2 offset = new Vector2(1, 1);

                        batch.Draw(
                            tileset.TextureMap,
                            new Rectangle(
                                x*MapHelper.TileSize,
                                y*MapHelper.TileSize,
                                (int) (MapHelper.TileSize + offset.X),
                                (int) (MapHelper.TileSize + offset.Y)),
                            tileset.GetRectForTexture(textureId),
                            new Color(color.R, color.G, color.B, opacity));
                    }
                }
            }
        }
コード例 #2
0
ファイル: Map.cs プロジェクト: arthursouza/spacecreep
        //public List<Event> MapEvents { get; set; }

        public void Draw(SpriteBatch spriteBatch, Tileset testTileSet, bool onlyDrawVisible)
        {
            Vector2 min;
            Vector2 max;

            if (onlyDrawVisible)
            {
                min = MapHelper.GetTileFromPixels(Camera.Position);
                max = MapHelper.GetTileFromPixels(
                    new Vector2(
                        Camera.Position.X + spriteBatch.GraphicsDevice.Viewport.Width + MapHelper.TileSize,
                        Camera.Position.Y + spriteBatch.GraphicsDevice.Viewport.Height + MapHelper.TileSize));
            }
            else
            {
                min = Vector2.Zero;
                max = new Vector2(
                    Width,
                    Height);
            }

            var layers = Layers;

            Color color;

            for (int i = 0; i < layers.Count; i++)
            {
                color = Color.White;
                layers[i].Draw(spriteBatch, min, max, testTileSet, color, color.A);
            }
        }