Esempio n. 1
0
        public static int GetColoredDotTextureId(Color color)
        {
            int textureId;

            if (!Dots.TryGetValue(color, out textureId))
            {
                Texture2D texture;
                texture = new Texture2D(GraphicsUtility.CurrentGraphicsDevice, 1, 1);
                texture.SetData(new Color[] { color });
                textureId = GraphicsUtility.AddTexture(color.ToString(), texture);
                Dots.Add(color, textureId);
            }

            return(textureId);
        }
Esempio n. 2
0
        public int RenderTexture(string assetName, List <TiledTextureDescriptor> textureDescriptors, int width, int height)
        {
            int newTextureId = GraphicsUtility.TextureCollection.Count;

            SpriteBatch    spriteBatch  = new SpriteBatch(GraphicsUtility.CurrentGraphicsDevice);
            RenderTarget2D renderTarget = new RenderTarget2D(GraphicsUtility.CurrentGraphicsDevice, width, height); // TODO: figure out image size

            GraphicsUtility.CurrentGraphicsDevice.SetRenderTarget(renderTarget);
            GraphicsUtility.CurrentGraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin();

            foreach (TiledTextureDescriptor ttd in textureDescriptors)
            {
                Rectangle ttdr;
#pragma warning disable CS0618 // Type or member is obsolete
                if (TextureRectangles.TryGetValue(ttd.TiledTextureId, out ttdr))
                {
                    spriteBatch.Draw(texture: GraphicsUtility.TextureCollection[TextureIds[ttd.TiledTextureId]],
                                     position: ttd.position,
                                     sourceRectangle: ttdr);
                }
                else
                {
                    spriteBatch.Draw(texture: GraphicsUtility.TextureCollection[TextureIds[ttd.TiledTextureId]],
                                     position: ttd.position);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }

            spriteBatch.End();

            GraphicsUtility.CurrentGraphicsDevice.SetRenderTarget(null);

            newTextureId = GraphicsUtility.AddTexture(assetName, renderTarget);

            return(newTextureId);
        }