protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.ForestGreen); mapRenderer.Draw(cam.GetViewMatrix()); _spriteBatch.Begin(transformMatrix: cam.GetViewMatrix()); if (player.Health > 0) { player.anim.Draw(_spriteBatch, new Vector2(player.Position.X - 48, player.Position.Y - 48)); } foreach (Enemy en in Enemy.enemies) { Texture2D spriteToDraw; int rad; if (en.GetType() == typeof(Snake)) { spriteToDraw = snakeEnemy_Sprite; rad = 50; } else { spriteToDraw = eyeEnemy_Sprite; rad = 73; } _spriteBatch.Draw(spriteToDraw, new Vector2(en.Position.X - rad, en.Position.Y - rad), Color.White); } foreach (Obstacle o in Obstacle.obstacles) { Texture2D spriteToDraw; if (o.GetType() == typeof(Tree)) { spriteToDraw = tree_Sprite; } else { spriteToDraw = bush_Sprite; } _spriteBatch.Draw(spriteToDraw, o.Position, Color.White); } foreach (Projectile proj in Projectile.projectiles) { _spriteBatch.Draw(bullet_Sprite, new Vector2(proj.Position.X - proj.Radius, proj.Position.Y - proj.Radius), Color.White); } _spriteBatch.End(); _spriteBatch.Begin(); for (int i = 0; i < player.Health; i++) { _spriteBatch.Draw(heart_Sprite, new Vector2(3 + i * 63, 3), Color.White); } _spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); _camera.LookAt(_playerPosition); // TODO: Add your drawing code here _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix(), samplerState: SamplerState.PointClamp); _tiledMapRenderer.Draw(_camera.GetViewMatrix()); _spriteBatch.Draw(_playerTexture, _playerPosition, Color.White); _spriteBatch.End(); base.Draw(gameTime); }
private static void TranslateMovement(float dx, float dy, bool isRunning) { Player player = Player.Instance(); OrthographicCamera camera = JustCombat.WorldCamera; Vector2 screenCoords; int[] newPositions; int[] testPositions; bool translateCamera = false; newPositions = Util.GetNewPosition(dx, dy, isRunning); screenCoords = camera.WorldToScreen(newPositions[0], newPositions[1]); testPositions = new int[] { (int)(screenCoords.X), (int)(screenCoords.Y) }; translateCamera = Util.BeyondMapScrollTransformBounds(testPositions, (int)(player.GetWidth()), (int)(player.GetHeight())); if (translateCamera) { int oldX = (int)(player.GetX()); int oldY = (int)(player.GetY()); int newX = newPositions[0]; int newY = newPositions[1]; int diffX = (oldX - newX) * (-1); int diffY = (oldY - newY) * (-1); camera.Move(new Vector2(diffX, diffY)); // Update the TransformMatrix, because the camera has moved. JustCombat.TransformMatrix = camera.GetViewMatrix(); } player.Move(newPositions, isRunning); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { if (time < 1600) { GraphicsDevice.Clear(Color.CornflowerBlue); } else { GraphicsDevice.Clear(Color.DarkBlue); } // TODO: Add your drawing code here spriteBatch.Begin(transformMatrix: camera.GetViewMatrix()); player.GetCurrentLocation().Draw(spriteBatch); spriteBatch.End(); spriteBatch.Begin(); playerInfoBar.Draw(spriteBatch); foreach (Menu menu in menuList) { menu.Draw(spriteBatch); } spriteBatch.DrawString(font, "time: " + time, new Vector2(10, 10), Color.White); spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here _spriteBatch.Begin(transformMatrix: camera.GetViewMatrix(), samplerState: new SamplerState { Filter = TextureFilter.Point }); _mapRenderer.Draw(camera.GetViewMatrix()); _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); MouseState mouseState = Mouse.GetState(); var mousePosition = _camera.ScreenToWorld(mouseState.Position.ToVector2()); var cameraPosition = _camera.Position.X.ToString() + " : " + _camera.Position.Y.ToString(); var framerate = (1 / gameTime.ElapsedGameTime.TotalSeconds).ToString(); var viewMatrix = _camera.GetViewMatrix(); _world.Draw(gameTime); base.Draw(gameTime); _spriteBatch.Begin(); //_tiles.Draw(_camera); _spriteBatch.DrawString(_bitmapFont, cameraPosition, new Vector2(50, 50), Color.Red); _spriteBatch.DrawString(_bitmapFont, framerate, new Vector2(50, 70), Color.Red); _spriteBatch.DrawString(_bitmapFont, mousePosition.X.ToString(), new Vector2(50, 90), Color.Red); _spriteBatch.DrawString(_bitmapFont, mousePosition.Y.ToString(), new Vector2(50, 110), Color.Red); _spriteBatch.End(); }
public void Draw(OrthographicCamera camera, SpriteBatch spriteBatch) { var viewMatrix = camera.GetViewMatrix(); mapRenderer.Draw(viewMatrix); entities.ForEach(entity => { entity.Draw(spriteBatch); }); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); // background var sourceRectangle = new Rectangle(0, 0, _viewportAdapter.VirtualWidth, _viewportAdapter.VirtualHeight); sourceRectangle.Offset(_camera.Position * new Vector2(0.1f)); _spriteBatch.Begin(samplerState: SamplerState.PointWrap, transformMatrix: _viewportAdapter.GetScaleMatrix()); _spriteBatch.Draw(_backgroundTexture, Vector2.Zero, sourceRectangle, Color.White); _spriteBatch.DrawString(_font, $"{_score}", Vector2.One, Color.White); _spriteBatch.End(); // entities _spriteBatch.Begin(samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix()); _entityManager.Draw(_spriteBatch); _spriteBatch.End(); _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix()); _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here var transformMatrix = camera.GetViewMatrix(); loadedMap.renderMap(gameTime); //Renders the currently loaded hexmap //+ mouseWorldPosition.ToString() world.Draw(gameTime); //Runs all the draw systems attached to the World entity manager guiSpriteBatch.Begin(); selectedHex = loadedMap.GetHexVectorFromPixelCoord(mouseWorldPosition); string mousePositionText = $"Mouse Cursor Position: {mouseWorldPosition.ToString()}"; //guiSpriteBatch.DrawString(arialFont, "Test", new Vector2(100, 100), Color.Black); Vector2 textMiddlePoint = arialFont.MeasureString(mousePositionText) / 2; guiSpriteBatch.DrawString(arialFont, mousePositionText, new Vector2(200, 200), Color.Black, 0, textMiddlePoint, 1.0f, SpriteEffects.None, 1.0f); guiSpriteBatch.End(); gui.Draw(); base.Draw(gameTime); }
public void Draw(SpriteBatch spriteBatch) { Matrix transform = _camera.GetViewMatrix(); _tiledMapRenderer.Draw(_tiledMap.GetLayer("Space"), transform); _tiledMapRenderer.Draw(_tiledMap.GetLayer("ShipFloor"), transform); _tiledMapRenderer.Draw(_tiledMap.GetLayer("Collidable"), transform); spriteBatch.Begin(transformMatrix: transform, samplerState: SamplerState.PointClamp); // Draws all game objects to screen foreach (IEntity entity in _entities) { entity.Draw(spriteBatch); } _player.Draw(spriteBatch); spriteBatch.End(); _tiledMapRenderer.Draw(_tiledMap.GetLayer("UpperLayer"), transform); // HUD Section spriteBatch.Begin(samplerState: SamplerState.PointClamp); _playerInventoryHud.Draw(spriteBatch); _toolboxInventoryHud.Draw(spriteBatch); _healthBar.Draw(spriteBatch); spriteBatch.DrawString(_font, _brokenList, new Vector2(50f, 100f), Color.White); spriteBatch.End(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); _tiledMapRenderer.Draw(_camera.GetViewMatrix()); _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix()); Ball.Draw(_spriteBatch); _spriteBatch.End(); _spriteBatch.Begin(); DualStick.Draw(_spriteBatch); _spriteBatch.End(); base.Draw(gameTime); }
public void Draw(GameTime gameTime) { // Begin _sb.Begin(samplerState: SamplerState.PointClamp, sortMode: SpriteSortMode.FrontToBack, blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix()); // Draw Entities foreach (int entityId in ActiveEntities) { var renderForm = _renderFormMapper.Get(entityId); var transform = _transform2DMapper.Get(entityId); if (string.Compare("Background", renderForm.Name) == 0) { var renderer = _rendererMapper.Get(entityId); RenderBackground(renderer, transform); } else if (string.Compare("Chicken", renderForm.Name) == 0) { var animatedSprite = _animatedSpriteMapper.Get(entityId); RenderChicken(animatedSprite, transform); } } // End _sb.End(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); // the camera produces a view matrix that can be applied to any sprite batch var transformMatrix = _camera.GetViewMatrix(Vector2.Zero); _spriteBatch.Begin(transformMatrix: transformMatrix); _spriteBatch.Draw(_backgroundSky, Vector2.Zero, Color.White); _spriteBatch.Draw(_backgroundClouds, new Vector2(-_cloudsOffset, 0), Color.White); _spriteBatch.Draw(_backgroundClouds, new Vector2(_cloudsOffset, 10), Color.White); _spriteBatch.End(); for (var layerIndex = 0; layerIndex < 4; layerIndex++) { // different layers can have a parallax factor applied for a nice depth effect var parallaxFactor = Vector2.One * (0.25f * layerIndex); var viewMatrix = _camera.GetViewMatrix(parallaxFactor); _spriteBatch.Begin(transformMatrix: viewMatrix); for (var repeatIndex = -3; repeatIndex <= 3; repeatIndex++) { var texture = _backgroundHills[layerIndex]; var position = new Vector2(repeatIndex * texture.Width, 0); _spriteBatch.Draw(texture, position, Color.White); } _spriteBatch.End(); } // not all sprite batches need to be affected by the camera var rectangle = _camera.BoundingRectangle; var stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"WASD: Move [{_camera.Position.X:0}, {_camera.Position.Y:0}]"); stringBuilder.AppendLine($"EQ: Rotate [{MathHelper.ToDegrees(_camera.Rotation):0.00}]"); stringBuilder.AppendLine($"RF: Zoom [{_camera.Zoom:0.00}]"); stringBuilder.AppendLine($"World Pos: [{_worldPosition.X:0}, {_worldPosition.Y:0}]"); stringBuilder.AppendLine($"Bounds: [{rectangle.X:0}, {rectangle.Y:0}, {rectangle.Width:0}, {rectangle.Height:0}]"); _spriteBatch.Begin(blendState: BlendState.AlphaBlend); _spriteBatch.DrawString(_bitmapFont, stringBuilder.ToString(), new Vector2(5, 5), Color.DarkBlue); _spriteBatch.End(); base.Draw(gameTime); }
private void OnMouseClicked(object?sender, MouseEventArgs e) { var point = e.Position; var f = Vector2.Transform(point.ToVector2(), Matrix.Invert(_camera.GetViewMatrix())); var position = Vectors.Detransform(f); GameProcess.Instance.Player.Make(FindMove(position)); Log.Verbose("Player clicked at {position} cell", position); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _renderer.Draw(_camera.GetViewMatrix()); //_world.Draw(gameTime); base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { foreach (var entity in ActiveEntities) { var sprite = animatedSpriteMapper.Has(entity) ? animatedSpriteMapper.Get(entity) : spriteMapper.Get(entity); var transform = transforMapper.Get(entity); if (sprite is AnimatedSprite animatedSprite) { animatedSprite.Update(gameTime.GetElapsedSeconds()); } spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.GetViewMatrix()); spriteBatch.Draw(sprite, transform); spriteBatch.End(); var player = playerMapper.Get(entity); if (player != null) { if (player.ImmuneTimer > 1f) { spriteBatch.Begin(effect: damageEffect, transformMatrix: camera.GetViewMatrix()); spriteBatch.Draw(sprite, transform); spriteBatch.End(); } } var enemy = enemyMapper.Get(entity); if (enemy != null) { if (enemy.ImmuneTimer > 1f) { spriteBatch.Begin(effect: damageEffect, transformMatrix: camera.GetViewMatrix()); spriteBatch.Draw(sprite, transform); spriteBatch.End(); } } } }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _spriteBatch.Begin(blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix()); _spriteBatch.Draw(_sprite, _transform.Position, _transform.Rotation, _transform.Scale); _spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); base.Draw(gameTime); _spriteBatch.Begin(transformMatrix: _mainCamera.GetViewMatrix(), samplerState: SamplerState.LinearClamp, blendState: BlendState.AlphaBlend); switch (_gameScreen) { case GameScreen.HomeScreen: _homeScreen.Draw(_spriteBatch); break; case GameScreen.CinematicScreen: _cinematicScreen.Draw(_spriteBatch); break; case GameScreen.InstructionsScreen: _instructionScreen.Draw(_spriteBatch); break; case GameScreen.MainScreen: _mainScreen.Draw(_spriteBatch); break; case GameScreen.GameOverScreen: _gameOverScreen.Draw(_spriteBatch); break; default: throw new ArgumentOutOfRangeException(); } _screenFader.Draw(_spriteBatch); _spriteBatch.End(); if (_drawDebug) { DrawDebug(); } }
public override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp); mapRenderer.Draw(camera.GetViewMatrix()); foreach (var obj in world.GetGameObjects()) { obj.Draw(spriteBatch); } spriteBatch.End(); spriteBatch.Begin(); GameLog.Draw(spriteBatch); spriteBatch.End(); }
public void Draw(SpriteBatch spriteBatch) { _graphicsDevice.Clear(Color.Black); spriteBatch.Begin(samplerState: SamplerState.PointWrap, transformMatrix: _camera.GetViewMatrix()); // _viewportAdapter.GetScaleMatrix() spriteBatch.FillRectangle(new Rectangle(2, 2, 796, 1196), Color.LightBlue); spriteBatch.DrawCircle(new Vector2(400, 600), 400, 50, Color.Red); spriteBatch.DrawString(_font, $"Resolution: {_viewportAdapter.ViewportWidth}x{_viewportAdapter.ViewportHeight}", Vector2.Zero, Color.White); spriteBatch.DrawString(_font, $"Virtual Resolution: {_viewportAdapter.VirtualWidth}x{_viewportAdapter.VirtualHeight}", new Vector2(0.0f, 50.0f), Color.White); spriteBatch.End(); }
public void renderMap(GameTime gametime) { var transformMatrix = camera.GetViewMatrix(); spriteBatch.Begin(transformMatrix: transformMatrix); foreach (HexBase floorHex in floorHexes) { spriteBatch.Draw(floorHex.texture, GetPixelVectorFromHex(floorHex), null, Color.White, 0f, new Vector2(0, 0), new Vector2(1, 1), SpriteEffects.None, layerDepth: 0.1f); //USERECTANGLE TO FORCE SPRITE INTO CORRECT SHAPE } spriteBatch.End(); }
protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Pink); spriteBatch.Begin(transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp); map.Draw(camera, spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { _spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix()); foreach (var entityId in ActiveEntities) { var entity = GetEntity(entityId); var texture = entity.Get <TextureComponent>(); var transform = entity.Get <MoveablePositionComponent>(); _spriteBatch.Draw(texture.Texture, transform.Transform.Position); } _spriteBatch.End(); }
protected override void Draw(GameTime gameTime) { var transformMatrix = _cam.GetViewMatrix(); base.Draw(gameTime); GraphicsDevice.Clear(Color.CornflowerBlue); //Turn on Anti-aliasing by changing SamplerState.PointClamp _spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, transformMatrix: transformMatrix); _playerMouse.Draw(); WorldRenderer.Draw(gameTime); _spriteBatch.End(); _gui.Render(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(_backgroundColor); _spriteBatch.Begin(blendState: BlendState.AlphaBlend, transformMatrix: _camera.GetViewMatrix()); _spriteBatch.Draw(_sprite, Position, xx); _spriteBatch.End(); // Draw GUI on top of everything _gui.Draw(gameTime); base.Draw(gameTime); }
public override void Render(SpriteBatch spriteBatch) { // parallax parameter affects how movement of camera is applied. // with Zero, the position of the camera doesn't change // with One, it moves as desired (ie 10 units per update, as written below) // with Two, it moves twice as fast //var transformMatrix = _camera.GetViewMatrix(Vector2.Zero); //var transformMatrix = _camera.GetViewMatrix(Vector2.One); // default //var transformMatrix = _camera.GetViewMatrix(Vector2.One * 2); var transformMatrix = _camera.GetViewMatrix(); spriteBatch.Begin(transformMatrix: transformMatrix); _playerSprite.Render(spriteBatch); spriteBatch.End(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.BlendState = BlendState.AlphaBlend; GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; GraphicsDevice.RasterizerState = RasterizerState.CullNone; var viewMatrix = _camera.GetViewMatrix(); var projectionMatrix = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0f, -1f); _mapRenderer.Draw(ref viewMatrix, ref projectionMatrix, _customEffect); DrawText(); base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { // Lights ... DrawLights(); // Camera ... Draw main scene GraphicsDevice.SetRenderTarget(mainRenderTarget); GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); entityManager.Draw(spriteBatch); mapRenderer.Draw(camera.GetViewMatrix()); spriteBatch.End(); // Action ... Blend the scenes together BlendRenderTargets(); }
public override void Draw(GameTime gameTime) { var transformMatrix = camera.GetViewMatrix(); _spriteBatch.Begin(transformMatrix: transformMatrix); foreach (var entityID in ActiveEntities) { Vector2 position = _freePositionMapper.Get(entityID).position; Sprite sprite = _spriteMapper.Get(entityID); _spriteBatch.Draw(sprite.texture, position, Color.White); //Debug.WriteLine("Rendering Sprite: " + sprite.textureName); Entity entityobj = GetEntity(entityID); } _spriteBatch.End(); }
public override void Draw(GameTime gameTime) { spriteBatch.GraphicsDevice.Clear(Color.Black); var elapsedSeconds = gameTime.GetElapsedSeconds(); spriteBatch.Begin(transformMatrix: camera.GetViewMatrix()); foreach (var entity in ActiveEntities) { DrawSprite(entity, elapsedSeconds); transformMapper.TryGet(entity).IfSome(transform => DrawAiming(entity, transform)); DrawEntityDebugInfo(entity); } DrawGlobalDebugInfo(gameTime); spriteBatch.End(); }