예제 #1
0
        public Sprite([NotNull] string image, [NotNull] int depth)
        {
            this.image = image;
            this.depth = depth;

            if (!image.Equals(string.Empty))
            {
                pathImage = Asset.Load(image);
                sprite    = new global::SFML.Graphics.Sprite(new global::SFML.Graphics.Texture(pathImage));
            }

            OnDraw += Sprite_OnDraw;
        }
예제 #2
0
        public SfmlVideo(Config config, GameContent content, RenderWindow window)
        {
            try
            {
                Console.Write("Initialize video: ");

                renderer = new Renderer(config, content);

                config.video_gamescreensize  = Math.Clamp(config.video_gamescreensize, 0, MaxWindowSize);
                config.video_gammacorrection = Math.Clamp(config.video_gammacorrection, 0, MaxGammaCorrectionLevel);

                this.window = window;

                windowWidth  = (int)window.Size.X;
                windowHeight = (int)window.Size.Y;

                if (config.video_highresolution)
                {
                    textureWidth  = 512;
                    textureHeight = 1024;
                }
                else
                {
                    textureWidth  = 256;
                    textureHeight = 512;
                }

                textureData = new byte[4 * renderer.Width * renderer.Height];

                texture = new global::SFML.Graphics.Texture((uint)textureWidth, (uint)textureHeight);
                sprite  = new global::SFML.Graphics.Sprite(texture);

                sprite.Position = new Vector2f(0, 0);
                sprite.Rotation = 90;
                var scaleX = (float)windowWidth / renderer.Width;
                var scaleY = (float)windowHeight / renderer.Height;
                sprite.Scale       = new Vector2f(scaleY, -scaleX);
                sprite.TextureRect = new IntRect(0, 0, renderer.Height, renderer.Width);

                renderStates = new RenderStates(BlendMode.None);

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
예제 #3
0
        /// <summary>Initializes a new instance of the <see cref="Sprite" /> class.</summary>
        /// <param name="image">The image.</param>
        public Sprite([NotNull] string image)
        {
            this.image = image;
            depth      = 0;

            if (!image.Equals(string.Empty))
            {
                pathImage = Asset.Load(image);
                sprite    = new global::SFML.Graphics.Sprite(new global::SFML.Graphics.Texture(pathImage));
                Logger.Log("Loaded the sprite(" + image + ") '");
            }

            OnDraw += Sprite_OnDraw;
        }
예제 #4
0
        public void Dispose()
        {
            Console.WriteLine("Shutdown renderer.");

            if (sprite != null)
            {
                sprite.Dispose();
                sprite = null;
            }

            if (texture != null)
            {
                texture.Dispose();
                texture = null;
            }
        }