/// <summary> /// Draws all LayerElements in view /// </summary> /// <param name="camera">Current view to draw</param> public void Draw(CameraManager camera) { //Sorts layers lowest to highest LayerList.Sort(delegate(Layer x, Layer y) { return(x.Depth.CompareTo(y.Depth)); }); //create transformation matrix for different screen resolutions and apply it at drawing float horScaling = (float)GraphicsDevice.PresentationParameters.BackBufferWidth / BaseScreenSize.X; float verScaling = (float)GraphicsDevice.PresentationParameters.BackBufferHeight / BaseScreenSize.Y; Vector3 screenScalingFactor = new Vector3(horScaling, verScaling, 1); Matrix globalTransformation = Matrix.CreateScale(screenScalingFactor); SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, globalTransformation); //apply previous transformation foreach (Layer l in LayerList) { foreach (ISpriteInterface le in l.elementList) { //draw texture at position * zoom relative to the camera center at a size*zoom //The actual position of the element in the world + camera position //area of the screen ocupied by the element Rectangle drawElement = getAreaOnScreen(le.Position, le, camera); //draw only if visible, not need to worry about depth as layers are sorted lowest to highest if (drawElement.Intersects(camera.DrawArea)) { le.Draw(SpriteBatch, drawElement, camera); } } if (l.Depth == Player.Depth) { Vector2 screenPos = getScreenPos(Player.Position, camera); Player.Sprite.Draw(SpriteBatch, getAreaOnScreen(Player.Position, Player.Sprite, camera), camera); } } SpriteBatch.End(); }