Exemplo n.º 1
0
 public void Sprite_Constructor_Test()
 {
     var texture = new Texture(Device, Path.Combine(RenderSettings.MediaPath, "Test/fatship256.tga"), "");
     var sprite = new Sprite(texture);
     Assert.AreEqual(texture, sprite.Texture);
     Assert.AreEqual(Color.White, sprite.Color);
 }
Exemplo n.º 2
0
 public TextureRenderTarget(Device device, Size size)
 {
     Texture = new Texture(device, "RenderTarget", size);
     TargetSurface = Texture.RawTexture.GetSurfaceLevel(0);
     DepthStencilSurface = D3D.Surface.CreateDepthStencil(device.RawDevice, (int)size.Width, (int)size.Height, D3D.Format.D16,
         D3D.MultisampleType.None, 0, false);
     Size = size;
 }
Exemplo n.º 3
0
 protected override object OnReadXml(XmlReader reader)
 {
     string textureName = reader["Source"];
     if (String.IsNullOrWhiteSpace(textureName) == false)
         Texture = this.assetManager.Load(textureName) as Texture;
     SourceRect = Rectangle.Parse(reader["SourceRect"]);
     return null;
 }
Exemplo n.º 4
0
 public Font(string name, Texture texture, string dataFile)
     : this(name, texture)
 {
     using (var stream = File.OpenRead(dataFile))
     {
         ReadWidthData(stream);
     }
 }
Exemplo n.º 5
0
        public void AnimateSprite_Animate_ByUpdate_Test()
        {
            var texture = new Texture(Device, TestHelpers.GetAssetFullPath("explosion_30_128.tga"), "");
            int startFrame = 6;
            var sprite = new AnimateSprite(texture, new Range<int>(0, 29), startFrame, 6, 128, 128);

            sprite.Update(1.0f);
            Assert.AreEqual(startFrame + 1, sprite.CurrentFrame);
        }
Exemplo n.º 6
0
 public Sprite(Texture texture)
 {
     Texture = texture;
     Color = Color.White;
     Position = Vector2.Zero;
     Scale = new Vector2(1.0f, 1.0f);
     Rotation = new Radian(0.0f);
     SourceRect = new Rectangle(0, 0, Texture.Width, Texture.Height);
 }
Exemplo n.º 7
0
        public void Texture_FromToStream_Test()
        {
            var expected = CreateTexture("TextureName");
            var stream = new MemoryStream();
            expected.ToStream().CopyTo(stream);
            stream.Position = 0;

            var actual = new Texture(Device, stream, "TextureName");
            Assert.AreEqual(expected.Width, actual.Width);
        }
Exemplo n.º 8
0
        public static Font Load(Device device, string fileName, string name, AssetManager assetManager)
        {
            using (var zip = new ZipArchive(fileName))
            {
                string textureFile = Path.ChangeExtension(Path.GetFileName(fileName), ".tga");
                Texture texture = new Texture(device, zip.Load(textureFile), name);

                string widthDataFile = Path.ChangeExtension(Path.GetFileName(fileName), ".dat");
                return new Font(name, texture, zip.Load(widthDataFile));
            }
        }
Exemplo n.º 9
0
        public void AnimateSprite_Render_Test()
        {
            var texture = new Texture(Device, TestHelpers.GetAssetFullPath("explosion_30_128.tga"), "");
            var sprite = new AnimateSprite(texture, new Range<int>(0, 29), 0, 6, 128, 128);

            Device.RawDevice.BeginScene();
            SpriteRenderer.RawSprite.Begin(D3D.SpriteFlags.AlphaBlend);
            Assert.IsTrue((sprite as ISprite).Render(SpriteRenderer));
            SpriteRenderer.RawSprite.End();
            Device.RawDevice.EndScene();
        }
Exemplo n.º 10
0
        private Font(string name, Texture texture)
        {
            Name = name;
            Texture = texture;

            int numCharPerLine = 16;
            int charWidth = texture.Width / numCharPerLine;
            int charHeight = texture.Height / numCharPerLine;

            this.sprite = new AnimateSprite(texture, new Range<int>(0, 0), 0, numCharPerLine, charWidth, charHeight);
        }
Exemplo n.º 11
0
        public ParticleEmitter(Texture texture)
        {
            this.texture = texture;
            MaxSprite = 100;
            Length = 200;
            ColorRange = new Range<Color>(Color.Black, Color.White);
            Spread = 10;
            Velocity = 1.0f;
            Scale = 2.0f;

            this.timer.Start();
        }
Exemplo n.º 12
0
        public void Font_Print_Test()
        {
            var texture = new Texture(Device, Path.Combine(RenderSettings.MediaPath, "Engine/system12.tga"), "");
            string fontData = Path.Combine(RenderSettings.MediaPath, "Engine/system12.dat");
            var font = new Font("system12", texture, fontData);

            Device.RawDevice.BeginScene();
            SpriteRenderer.RawSprite.Begin(D3D.SpriteFlags.AlphaBlend);
            Assert.IsTrue(font.Print("text", Vector2.Zero, Color.White, SpriteRenderer));
            SpriteRenderer.RawSprite.End();
            Device.RawDevice.EndScene();
        }
Exemplo n.º 13
0
        public void ParticleEmitter_Constructor_Test()
        {
            var texture = new Texture(Device, TestHelpers.GetAssetFullPath("particle16.tga"), "");
            var emitter = new ParticleEmitter(texture);

            Assert.AreEqual(Vector2.Zero, emitter.Position);
            Assert.AreEqual(new Radian(0.0f), emitter.Direction);
            Assert.AreEqual(100, emitter.MaxSprite);
            Assert.AreEqual(200, emitter.Length);
            Assert.AreEqual(new Range<Color>(Color.Black, Color.White), emitter.ColorRange);
            Assert.AreEqual(10, emitter.Spread);
            Assert.AreEqual(1.0f, emitter.Velocity);
            Assert.AreEqual(2.0f, emitter.Scale);
        }
Exemplo n.º 14
0
        public void AnimateSprite_Constructor_Test()
        {
            var texture = new Texture(Device, TestHelpers.GetAssetFullPath("explosion_30_128.tga"), "");
            int frameRangeMin = 0, frameRangeMax = 29;
            int startFrame = 6;
            int numColumn = 6;
            int frameWidth = 128, frameHeight = 128;

            var sprite = new AnimateSprite(texture,
                                    new Range<int>(frameRangeMin, frameRangeMax),
                                    startFrame,
                                    numColumn,
                                    frameWidth, frameHeight);
            Assert.AreEqual(texture, sprite.Texture);
            Assert.AreEqual(new Range<int>(frameRangeMin, frameRangeMax), sprite.FrameRange);
            Assert.AreEqual(startFrame, sprite.CurrentFrame);
            Assert.AreEqual(frameWidth, sprite.FrameWidth);
            Assert.AreEqual(frameHeight, sprite.FrameHeight);
        }
Exemplo n.º 15
0
        public void ParticleEmitter_Render_Test()
        {
            var texture = new Texture(Device, TestHelpers.GetAssetFullPath("particle16.tga"), "");
            var emitter = new ParticleEmitter(texture);

            Device.RawDevice.BeginScene();
            SpriteRenderer.RawSprite.Begin(D3D.SpriteFlags.AlphaBlend);
            Assert.IsTrue((emitter as ISprite).Render(SpriteRenderer));
            SpriteRenderer.RawSprite.End();
            Device.RawDevice.EndScene();

            emitter.Update(1000.0f);

            Device.RawDevice.BeginScene();
            SpriteRenderer.RawSprite.Begin(D3D.SpriteFlags.AlphaBlend);
            Assert.IsTrue((emitter as ISprite).Render(SpriteRenderer));
            SpriteRenderer.RawSprite.End();
            Device.RawDevice.EndScene();
        }
Exemplo n.º 16
0
 private Sprite CreateSprite(string textureFile = "Test/fatship256.tga")
 {
     var texture = new Texture(Device, Path.Combine(RenderSettings.MediaPath, textureFile), "");
     return new Sprite(texture);
 }
Exemplo n.º 17
0
 public SpriteMock(Device device)
 {
     this.texture = new Texture(device, SampleTexturePath, "");
 }
Exemplo n.º 18
0
 public Font(string name, Texture texture, Stream widthStream)
     : this(name, texture)
 {
     ReadWidthData(widthStream);
 }