Example #1
0
        public void AddColor(Texture2D texture, Rectangle sourceRectangle, Rectangle rectangle, Color color)
        {
            _textureUpdating = true;

            var renderTarget = new RenderTarget2D(GraphicManager.Instance.GraphicsDevice, Settings.ScreenWidth, Settings.ScreenHeight);

            GraphicManager.Instance.GraphicsDevice.SetRenderTarget(renderTarget);
            GraphicManager.Instance.GraphicsDevice.Clear(Color.Black);

            _spritebatch.Begin();

            _spritebatch.Draw(_renderTarget, Vector2.Zero, Color.White);

            _spritebatch.Draw(texture, rectangle, sourceRectangle, color,
                              (float)_random.NextDouble(), new Vector2(0.5f, 0.5f),
                              SpriteEffects.None, 0);

            _spritebatch.End();

            GraphicManager.Instance.GraphicsDevice.SetRenderTarget(null);

            //_textureGame = (Texture2D)renderTarget;

            _renderTarget.Dispose();
            _renderTarget = renderTarget;
            //_renderTarget.Dispose();
            //spritebatch.Dispose();

            _textureUpdating = false;
        }
        protected override void OnDraw(ref DrawParams p)
        {
            if (timeParam != null)
            {
                timeParam.SetValue(SimTime);
            }
            if (positionParam != null)
            {
                positionParam.SetValue(Motion.Position);
            }

            Color col = DrawInfo.DrawColor;

            if (EffectEnabled)
            {
                // this is a conversion from 'halotime' to the time format that can be given to the pixel shader
                // via the 'draw color' parameter
                int t  = (int)(haloTime * 256);
                int c3 = t % 256;
                int c2 = ((t - c3) / 256) % 256;
                int c1 = ((t - c2 - c3) / 65536) % 256;
                col = new Color(c1, c2, c3, col.A);
            }
            MySpriteBatch.Draw(Texture, DrawInfo.DrawPosition, null, col,
                               Motion.RotateAbs, DrawInfo.DrawCenter, DrawInfo.DrawScale, SpriteEffects.None, DrawInfo.LayerDepth);
        }
Example #3
0
        protected override void OnDraw(ref DrawParams p)
        {
            if (timeParam != null)
            {
                timeParam.SetValue(SimTime);
            }
            if (positionParam != null)
            {
                positionParam.SetValue(Motion.Position);
            }

            if (Texture != null)
            {
                Color col = DrawInfo.DrawColor;
                if (EffectEnabled)
                {
                    // this is a conversion from 'halotime' to the time format that can be given to the pixel shader
                    // via the 'draw color' parameter
                    double warpedTime = 20 * (1 + Math.Sin(1.5f * MathHelper.Pi + MathHelper.TwoPi * 0.05 * (double)haloTime));
                    int    t          = (int)(warpedTime * 16);
                    int    c3         = t % 256;
                    int    c2         = ((t - c3) / 256) % 256;
                    //int c1 = ((t - c2 - c3)/65536) % 256;
                    col = new Color(col.R, c2, c3, col.A); // (intensity, timeMSB, timeLSB, alpha) passed to shader
                }
                MySpriteBatch.Draw(Texture, DrawInfo.DrawPosition, null, col,
                                   Motion.RotateAbs, DrawInfo.DrawCenter, DrawInfo.DrawScale, SpriteEffects.None, DrawInfo.LayerDepth);
            }
        }
Example #4
0
 public void Draw(MySpriteBatch spritebatch)
 {
     if (!_textureUpdating)
     {
         spritebatch.Draw(_renderTarget, Vector2.Zero, Color.White);
     }
 }
Example #5
0
        protected override void OnDraw(ref DrawParams p)
        {
            Vector2 pos = DrawInfo.DrawPosition;
            double  progressValuePercent = 100 * progressValue;
            float   drawSc = DrawInfo.DrawScale;
            int     width  = 1 + (int)Math.Round(ToPixels(DrawInfo.WidthAbs) * progressValue * barWidth);
            int     height = (int)Math.Round(ToPixels(DrawInfo.HeightAbs));

            if (width > Texture.Width)
            {
                width = Texture.Width;
            }

            Rectangle srcRect = new Rectangle(0, 0, width, Texture.Height - 2);

            MySpriteBatch.Draw(Texture, pos, srcRect, DrawInfo.DrawColor,
                               Motion.RotateAbs, new Vector2(0f, height / 4), drawSc, SpriteEffects.None, DrawInfo.LayerDepth);

            // plot text percentage
            Color   textColor = DrawInfo.DrawColor;
            Vector2 tpos      = pos + new Vector2(width * drawSc, height / 4); //Texture.Height / 2.0f - 10.0f) ;
            Vector2 origin    = new Vector2(10f, 6f);

            MySpriteBatch.DrawString(spriteFont, String.Format("  {0,3}%", Math.Round(progressValuePercent)), tpos,
                                     textColor, Motion.RotateAbs, origin, textScale * drawSc * 0.72f, SpriteEffects.None, DrawInfo.LayerDepth);
        }
Example #6
0
        public override void Draw(double elapsedTime, MySpriteBatch spriteBatch)
        {
            var offsetX = (int)((MyGame.Instance.ScreenWidth - (MyGame.MapWidth * MyGame.Instance.SpriteWidth)) * 0.5f);
            var offsetY = (int)((MyGame.Instance.ScreenHeight - (MyGame.MapHeight * MyGame.Instance.SpriteHeight)) * 0.5f);

            for (int i = 0; i < MyGame.MapWidth * MyGame.MapHeight; i++)
            {
                var region = MyGame.Instance.TextureManager.GetRegionByIndex(33);
                spriteBatch.Draw(MyGame.Instance.TextureManager.GetTexture(),
                                 new Rectangle(
                                     (int)(i % MyGame.MapWidth) * MyGame.Instance.SpriteWidth + offsetX,
                                     (int)(i / MyGame.MapHeight) * MyGame.Instance.SpriteHeight + offsetY,
                                     (int)(region.Width),
                                     (int)(region.Height)
                                     ),
                                 new Rectangle(
                                     region.X,
                                     region.Y,
                                     region.Width,
                                     region.Height
                                     ),
                                 Color.White,
                                 0,
                                 new Vector2(
                                     MyGame.Instance.SpriteWidth * 0.5f,
                                     MyGame.Instance.SpriteHeight * 0.5f),
                                 SpriteEffects.None,
                                 0);
            }
        }
        public override void Draw(double elapsedTime, MySpriteBatch spriteBatch)
        {
            var entities = _world.EntityManager.GetEntities();

            var entitiesFounded = entities.Where(x => x.HasComponents(_componentTypes)).ToList();

            foreach (var e in entitiesFounded)
            {
                var spriteComponent    = e.GetComponent <SpriteComponent>();
                var transformComponent = e.GetComponent <TransformComponent>();

                var region = MyGame.Instance.TextureManager.GetRegionByIndex(spriteComponent.SpriteIndex);

                spriteBatch.Draw(MyGame.Instance.TextureManager.GetTexture(),
                                 new Rectangle(
                                     (int)(transformComponent.X) * MyGame.Instance.SpriteWidth + _offsetX,
                                     (int)(transformComponent.Y) * MyGame.Instance.SpriteHeight + _offsetY,
                                     (int)(region.Width * spriteComponent.ScaleX),
                                     (int)(region.Height * spriteComponent.ScaleY)
                                     ),
                                 new Rectangle(
                                     region.X,
                                     region.Y,
                                     region.Width,
                                     region.Height
                                     ),
                                 spriteComponent.Color,
                                 transformComponent.Rotation,
                                 new Vector2(
                                     region.Width * spriteComponent.OriginX,
                                     region.Height * spriteComponent.OriginY),
                                 spriteComponent.Effect,
                                 0);
            }
        }
Example #8
0
 public void Draw(MySpriteBatch spritebatch)
 {
     if (!_textureUpdating)
     {
         var center = _position - new Vector2(_texture.Width * Settings.Zoom * 0.5f, _texture.Height * Settings.Zoom * 0.5f);
         spritebatch.Draw(_texture,
                          new Rectangle((int)center.X, (int)center.Y, (int)(_texture.Width * Settings.Zoom), (int)(_texture.Height * Settings.Zoom)),
                          Color.White);
     }
 }
Example #9
0
        public void Draw(GameTime gameTime, MySpriteBatch spritebatch)
        {
            _mapManager.Draw(spritebatch);


            //Player Positions
            var texturePlayerPositionWidth  = TextureManager.Instance.GetTexture("Textures/PlayerPosition_Width");
            var texturePlayerPositionHeight = TextureManager.Instance.GetTexture("Textures/PlayerPosition_Height");

            spritebatch.Draw(texturePlayerPositionWidth, _rectRed, Color.White);
            spritebatch.Draw(texturePlayerPositionHeight, _rectBlue, Color.White);
            spritebatch.Draw(texturePlayerPositionWidth, _rectGreen, Color.White);
            spritebatch.Draw(texturePlayerPositionHeight, _rectYellow, Color.White);



            //Draw balls
            var textureBall = TextureManager.Instance.GetTexture("Textures/Paint");

            foreach (var ball in _paintBalls)
            {
                if (!ball.IsDrawed)
                {
                    var position = ball.Position - new Vector2(16, 16);
                    spritebatch.Draw(textureBall, new Rectangle((int)position.X, (int)position.Y, 32, 32), ball.Color);
                }
            }

            SpriteFont font = FontManager.Instance.GetFont("Arial-10");

            spritebatch.DrawString(font, "Pinch : " + _pinchDistance, new Vector2(10, 90), Color.Yellow);

            if (_lastScore != null)
            {
                spritebatch.DrawString(font, "Time : " + TimeSpan.FromSeconds(_timeGame - _timeCurrent),
                                       new Vector2(Settings.ScreenWidth - 200, 10), Color.Yellow);
                spritebatch.DrawString(font, "Red : " + _lastScore.Red.ToString("0") + "%", new Vector2(Settings.ScreenWidth - 200, 30), Color.Yellow);
                spritebatch.DrawString(font, "Blue : " + _lastScore.Blue.ToString("0") + "%", new Vector2(Settings.ScreenWidth - 200, 50), Color.Yellow);
                spritebatch.DrawString(font, "Green : " + _lastScore.Green.ToString("0") + "%", new Vector2(Settings.ScreenWidth - 200, 70), Color.Yellow);
                spritebatch.DrawString(font, "Yellow : " + _lastScore.Yellow.ToString("0") + "%", new Vector2(Settings.ScreenWidth - 200, 90), Color.Yellow);
            }
        }
Example #10
0
        public void UpdateTexture()
        {
            _textureUpdating = true;

            MySpriteBatch spritebatch = new MySpriteBatch(GraphicManager.Instance.GraphicsDevice);

            Width  = Settings.SubZoneWidth * (int)Settings.Tile_Size;
            Height = Settings.SubZoneHeight * (int)Settings.Tile_Size;
            var renderTarget = new RenderTarget2D(GraphicManager.Instance.GraphicsDevice, Width, Height);

            GraphicManager.Instance.GraphicsDevice.SetRenderTarget(renderTarget);

            GraphicManager.Instance.GraphicsDevice.Clear(Color.Transparent);

            Sprite spriteGrass  = SpriteManager.Instance.GetSprite("Grass");
            Sprite spriteRock   = SpriteManager.Instance.GetSprite("Rock");
            Sprite spriteDirt   = SpriteManager.Instance.GetSprite("Dirt");
            Sprite spriteWater1 = SpriteManager.Instance.GetSprite("Water1");
            Sprite spriteWater2 = SpriteManager.Instance.GetSprite("Water2");
            Sprite spriteWater3 = SpriteManager.Instance.GetSprite("Water3");

            spritebatch.Begin();

            for (var line = _zone.Height - 1; line >= 0; line--)
            {
                for (var col = _zone.Width - 1; col >= 0; col--)
                {
                    var tile     = _zone.LayerFloor.Tiles[line, col];
                    var position = Convert2DToIso(new Vector3(col, line, tile.Altitude));
                    position.X += renderTarget.Width * 0.5f - Settings.Tile_Size * 0.5f;
                    position.Y += renderTarget.Height * 0.5f - Settings.Tile_Size * 0.5f;

                    if (tile.Terrain.Type == TypeTerrain.Rock)
                    {
                        spritebatch.Draw(spriteRock.Texture,
                                         new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size),
                                         spriteRock.RectangleSource,
                                         spriteRock.Color);
                    }
                    else if (tile.Terrain.Type == TypeTerrain.Grass)
                    {
                        spritebatch.Draw(spriteGrass.Texture,
                                         new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size),
                                         spriteGrass.RectangleSource,
                                         spriteGrass.Color);
                    }
                    else if (tile.Terrain.Type == TypeTerrain.Dirt)
                    {
                        spritebatch.Draw(spriteDirt.Texture,
                                         new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size),
                                         spriteDirt.RectangleSource,
                                         spriteDirt.Color);
                    }
                }
            }

            spritebatch.End();

            GraphicManager.Instance.GraphicsDevice.SetRenderTarget(null);

            _texture = (Texture2D)renderTarget;

            _textureUpdating = false;
        }