public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { if (lightingEnabled.Selected) { GameMain.LightManager.UpdateLightMap(graphics, spriteBatch, cam); } graphics.Clear(Color.Black); if (Level.Loaded != null) { Level.Loaded.DrawBack(graphics, spriteBatch, cam); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.DepthRead, transformMatrix: cam.Transform); Level.Loaded.DrawFront(spriteBatch, cam); Submarine.Draw(spriteBatch, false); Submarine.DrawFront(spriteBatch); Submarine.DrawDamageable(spriteBatch, null); spriteBatch.End(); if (lightingEnabled.Selected) { spriteBatch.Begin(SpriteSortMode.Immediate, Lights.CustomBlendStates.Multiplicative, null, DepthStencilState.None, null, null, null); spriteBatch.Draw(GameMain.LightManager.LightMap, new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.White); spriteBatch.End(); } } if (editingSprite != null) { GameMain.SpriteEditorScreen.Draw(deltaTime, graphics, spriteBatch); } spriteBatch.Begin(SpriteSortMode.Deferred, rasterizerState: GameMain.ScissorTestEnable); GUI.Draw(Cam, spriteBatch); spriteBatch.End(); }
public static void Create(Submarine sub) { int width = 4096; int height = 4096; Rectangle subDimensions = sub.CalculateDimensions(false); Vector2 viewPos = subDimensions.Center.ToVector2(); float scale = Math.Min(width / (float)subDimensions.Width, height / (float)subDimensions.Height); var viewMatrix = Matrix.CreateTranslation(new Vector3(width / 2.0f, height / 2.0f, 0)); var transform = Matrix.CreateTranslation( new Vector3(-viewPos.X, viewPos.Y, 0)) * Matrix.CreateScale(new Vector3(scale, scale, 1)) * viewMatrix; using (RenderTarget2D rt = new RenderTarget2D( GameMain.Instance.GraphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.None)) using (SpriteBatch spriteBatch = new SpriteBatch(GameMain.Instance.GraphicsDevice)) { Viewport prevViewport = GameMain.Instance.GraphicsDevice.Viewport; GameMain.Instance.GraphicsDevice.Viewport = new Viewport(0, 0, width, height); GameMain.Instance.GraphicsDevice.SetRenderTarget(rt); GameMain.Instance.GraphicsDevice.Clear(Color.Transparent); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, null, null, null, null, transform); Submarine.Draw(spriteBatch); Submarine.DrawFront(spriteBatch); Submarine.DrawDamageable(spriteBatch, null); spriteBatch.End(); GameMain.Instance.GraphicsDevice.SetRenderTarget(null); GameMain.Instance.GraphicsDevice.Viewport = prevViewport; using (FileStream fs = File.Open("wikiimage.png", System.IO.FileMode.Create)) { rt.SaveAsPng(fs, width, height); } } }
/// <summary> /// This is called when the game should draw itself. /// </summary> public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { cam.UpdateTransform(); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f)); if (GameMain.DebugDraw) { GUI.DrawLine(spriteBatch, new Vector2(Submarine.MainSub.HiddenSubPosition.X, -cam.WorldView.Y), new Vector2(Submarine.MainSub.HiddenSubPosition.X, -(cam.WorldView.Y - cam.WorldView.Height)), Color.White * 0.5f, 1.0f, (int)(2.0f / cam.Zoom)); GUI.DrawLine(spriteBatch, new Vector2(cam.WorldView.X, -Submarine.MainSub.HiddenSubPosition.Y), new Vector2(cam.WorldView.Right, -Submarine.MainSub.HiddenSubPosition.Y), Color.White * 0.5f, 1.0f, (int)(2.0f / cam.Zoom)); } Submarine.Draw(spriteBatch, true); if (!characterMode && !wiringMode) { if (MapEntityPrefab.Selected != null) { MapEntityPrefab.Selected.DrawPlacing(spriteBatch, cam); } MapEntity.DrawSelecting(spriteBatch, cam); } spriteBatch.End(); //-------------------- HUD ----------------------------- spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); if (Submarine.MainSub != null) { DrawSubmarineIndicator(spriteBatch, Submarine.MainSub, Color.LightBlue * 0.5f); } leftPanel.Draw(spriteBatch); topPanel.Draw(spriteBatch); //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); if ((characterMode || wiringMode) && dummyCharacter != null) { if (dummyCharacter.SelectedConstruction != null) { dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, cam, dummyCharacter); } dummyCharacter.DrawHUD(spriteBatch, cam); if (wiringMode) { wiringToolPanel.Draw(spriteBatch); } } else { if (loadFrame != null) { loadFrame.Draw(spriteBatch); } else if (saveFrame != null) { saveFrame.Draw(spriteBatch); } else if (selectedTab > -1) { GUItabs[selectedTab].Draw(spriteBatch); } MapEntity.DrawEditor(spriteBatch, cam); } if (tutorial != null) { tutorial.Draw(spriteBatch); } GUI.Draw((float)deltaTime, spriteBatch, cam); if (!PlayerInput.LeftButtonHeld()) { Inventory.draggingItem = null; } spriteBatch.End(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch) { //cam.UpdateTransform(); graphics.Clear(Color.CornflowerBlue); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); Submarine.Draw(spriteBatch, true); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.Transform); //if (EntityPrefab.Selected != null) EntityPrefab.Selected.UpdatePlacing(spriteBatch, cam); //Entity.DrawSelecting(spriteBatch, cam); if (editingCharacter != null) { editingCharacter.Draw(spriteBatch); } spriteBatch.End(); //-------------------- HUD ----------------------------- spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, GameMain.ScissorTestEnable); GUIpanel.Draw(spriteBatch); EditLimb(spriteBatch); int y = 0; for (int i = 0; i < textures.Count; i++) { int x = GameMain.GraphicsWidth - textures[i].Width; spriteBatch.Draw(textures[i], new Vector2(x, y), Color.White); foreach (Limb limb in editingCharacter.AnimController.Limbs) { if (limb.sprite == null || limb.sprite.FilePath != texturePaths[i]) { continue; } Rectangle rect = limb.sprite.SourceRect; rect.X += x; rect.Y += y; GUI.DrawRectangle(spriteBatch, rect, Color.Red); Vector2 limbBodyPos = new Vector2( rect.X + limb.sprite.Origin.X, rect.Y + limb.sprite.Origin.Y); DrawJoints(spriteBatch, limb, limbBodyPos); //if (limb.BodyShapeTexture == null) continue; //spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos, // null, Color.White, 0.0f, // new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2, // 1.0f, SpriteEffects.None, 0.0f); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White); GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White); if (Vector2.Distance(PlayerInput.MousePosition, limbBodyPos) < 5.0f && PlayerInput.LeftButtonHeld()) { limb.sprite.Origin += PlayerInput.MouseSpeed; } } y += textures[i].Height; } GUI.Draw((float)deltaTime, spriteBatch, cam); //EntityPrefab.DrawList(spriteBatch, new Vector2(20,50)); //Entity.Edit(spriteBatch, cam); spriteBatch.End(); }