public override void Initialize() { _batch = new SpriteBatch(_device); _primitiveBatch = new PrimitiveBatch(_batch); _camera = new Camera(); _player = new Player(); _healthBar = new HealthBar(); }
public void Draw(GameTime gameTime, SpriteBatch batch, Camera camera) { var position = camera.Transform(_position); if (_currentAnimation != null) { batch.Draw(_texture, position, _currentAnimation.GetCurrentFrame(), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0f); } }
public void Draw(GameTime gameTime, SpriteBatch batch, Camera camera) { // TODO: Should use a quad tree (or similar) here to reduce drawn entities. // Draw the map and all entities. for (int layerIndex = 0; layerIndex < _map.Layers.Length; layerIndex++) { _map.Draw(gameTime, batch, camera, _map.Layers[layerIndex]); } }
public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Camera camera, Layer layer) { // Calculate the first visible cell index. float cameraCellX = (int)camera.Position.X / 16; float cameraCellY = (int)camera.Position.Y / 16; var firstIndex = (int)cameraCellX + (_size.Width * (int)cameraCellY); // Calculate stuff that we will need later. var horizontalCells = camera.ScreenSize.Width / 16; var verticalCells = camera.ScreenSize.Height / 16; var mapCellCount = _size.Width * _size.Height; for (var y = 0; y < verticalCells + 1; y++) { // How much should we increment the index position with? var verticalIncrement = y * _size.Width; for (var x = 0; x < horizontalCells + 1; x++) { var index = firstIndex + verticalIncrement + x; if (index < 0) { continue; } if (index >= mapCellCount) { return; } if (layer.Tiles[index] != null) { var tx = index % _size.Width * 16; var ty = index / _size.Width * 16; var position = new Vector2(tx, ty); position = camera.Transform(position); // Get the source rectangle and the texture. var sourceRectangle = layer.Tiles[index].GetRectangle(); var texture = layer.Tiles[index].Tileset.Texture; // Draw the tile. spriteBatch.Draw(texture, position, sourceRectangle, layer.Color); } } } }
public void Draw(GameTime gameTime, SpriteBatch batch, Camera camera) { _sprite.Draw(gameTime, batch, camera); }
public virtual void Draw(GameTime gameTime, SpriteBatch batch, Camera camera) { }