public void DrawLine() { if (!IsVisible) { return; } if (!IsInitialized) { throw new ApplicationException("Dialogue class was not initialized"); } // set the vertex declaration Game1.DefaultGraphics.GraphicsDevice.VertexDeclaration = _vertexDeclaration; Orthographic.StartOrtho(); _basicEffect.Begin(); // draw the quad foreach (EffectPass pass in _basicEffect.CurrentTechnique.Passes) { pass.Begin(); Game1.DefaultGraphics.GraphicsDevice.DrawUserIndexedPrimitives( PrimitiveType.TriangleList, _vertices, 0, 4, _indices, 0, 2); pass.End(); } _basicEffect.End(); _spriteBatch.Begin(); drawFancyBorders(); Orthographic.EndOrtho(); // Draw lines of dialogue // Write strings to screen string[] lines = _dialogueManager.GetLinesToWrite(); Vector2 textStart = new Vector2(_position.X + 5, _position.Y + 5); foreach (string s in lines) { _spriteBatch.DrawString(Font, s, textStart, TextColor); textStart.Y += Dialogue.FontHeight + Dialogue.FontVerticalSpacing; } _spriteBatch.End(); _spriteBatch.ResetFor3d(); }
private void initializeGraphics() { _spriteBatch = new SpriteBatch(Game1.DefaultGraphicsDevice); _basicEffect = new BasicEffect(Game1.DefaultGraphicsDevice, null); Orthographic.SetOrthoEffect(_basicEffect); _vertexDeclaration = new VertexDeclaration(Game1.DefaultGraphics.GraphicsDevice, new VertexElement[] { new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0) } ); // create vertices for the background quad _vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(_xSize, 0, 0), new Vector3(_xSize, _ySize, 0), new Vector3(0, _ySize, 0), }; // create indices for the background quad _indices = new short[] { 0, 1, 2, 2, 3, 0 }; // create an orthographic projection to draw the quad as a sprite _basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, Game1.DefaultGraphics.GraphicsDevice.Viewport.Width, Game1.DefaultGraphics.GraphicsDevice.Viewport.Height, 0, 0, 1); _basicEffect.DiffuseColor = BackgroundColor.ToVector3(); _basicEffect.Alpha = BackgroundAlpha; // move to correct position _basicEffect.World = Matrix.CreateTranslation(_position.X, _position.Y, 0); }