public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; frameCounter.Update(deltaTime); graphicsDevice.Clear(Color.CornflowerBlue); /* * Background */ spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); spriteBatch.Draw(backgroundGradientStrip, new Rectangle(0, 0, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight), Color.White); spriteBatch.End(); /* * World Render */ spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.Transform); level.Draw(gameTime, spriteBatch); foreach (Sprite s in enemies) { s.Draw(gameTime, spriteBatch); } foreach (Sprite s in pufferFish) { s.Draw(gameTime, spriteBatch); } player.Draw(gameTime, spriteBatch); //DrawBodyShape(player, spriteBatch, new Color(0, 150, 0, 150)); //DrawBodyShape(player, spriteBatch, new Color(0, 160, 0, 170)); //DrawBodyShape(spikesPointingDown[0], spriteBatch, new Color(160, 0, 0, 170)); //DrawBodyShape(spikesPointingUp[0], spriteBatch, new Color(160, 0, 0, 170)); spriteBatch.End(); /* * GUI render */ spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); energyBar.Draw(spriteBatch, gameTime); healthBar.Draw(spriteBatch, gameTime); //spriteBatch.DrawString(font, $"{(int)camera.Position.X}, {(int)camera.Position.Y}, {camera.Zoom}", new Vector2(0, graphicsDevice.Viewport.Height - 16), Color.Red); spriteBatch.DrawString(font, player.Body.GetDebugString(), new Vector2(0, 48), Color.Red); spriteBatch.DrawString(font, $"{Math.Round(frameCounter.AverageFramesPerSecond)}", Vector2.Zero, Color.LightGreen); spriteBatch.End(); }
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; frameCounter.Update(deltaTime); graphicsDevice.Clear(Color.CornflowerBlue); #region [Layer 0 - Behind World Map - Static] spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); Color depthbasedtint = Color.White; float multiplyer = (1f - player.Body.Y / (level.Height * level.TileHeight)); if (multiplyer >= 1f) { multiplyer = 1f; } byte colorvalue = (byte)(255f * multiplyer); depthbasedtint.R = colorvalue; depthbasedtint.G = colorvalue; depthbasedtint.B = colorvalue; spriteBatch.Draw(backgroundWaterGradientStrip, new Rectangle(0, 0, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight), depthbasedtint); Vector2 skypos = camera.GetWorldToScreenPosition(new Vector2(0, 3f)); spriteBatch.Draw(backgroundSkyGradientStrip, new Rectangle(0, (int)skypos.Y - Graphics.PreferredBackBufferHeight, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight), Color.White); spriteBatch.End(); #endregion #region [Layer 1 - World Map - Camera] spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: camera.Transform); // beackground tiles level.Layers[0].Draw(gameTime, spriteBatch); // background particle effects foreach (ParticleEmitter p in backgroundParticles) { p.Draw(gameTime, spriteBatch); } // world tiles level.Layers[1].Draw(gameTime, spriteBatch); // enemies foreach (Sprite s in enemies) { s.Draw(gameTime, spriteBatch); //DrawBodyShape(s, spriteBatch, new Color(150, 0, 0, 150)); } //foreach (Sprite s in spikesPointingDown) //{ // DrawBodyShape(s, spriteBatch, new Color(0, 0, 150, 150)); //} //foreach (Sprite s in spikesPointingUp) //{ // DrawBodyShape(s, spriteBatch, new Color(0, 0, 150, 150)); //} // the gold stuff foreach (Sprite s in goldenFishs) { s.Draw(gameTime, spriteBatch); } // player player.Draw(gameTime, spriteBatch); //DrawBodyShape(player, spriteBatch, new Color(100, 0, 0, 150)); spriteBatch.End(); #endregion #region [Layer 2 - UI - Static] spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); energyBar.Draw(spriteBatch, gameTime); healthBar.Draw(spriteBatch, gameTime); //spriteBatch.DrawString(font, player.Body.GetDebugString(), new Vector2(0, 48), Color.Red); spriteBatch.DrawString(font, $"{Math.Round(frameCounter.CurrentFramesPerSecond)}", Vector2.Zero, Color.LightGreen); spriteBatch.DrawString(font, $"{(int)camera.Position.X}, {(int)camera.Position.Y}, {camera.Zoom}", new Vector2(0, graphicsDevice.Viewport.Height - 16), Color.Red); spriteBatch.End(); #endregion }