public void Draw() { SpriteBatchEx.DrawFilledRectangle(spriteBatch, rectangle, Color.White, Color.Gray); foreach (Text line in lines) { line.Draw(); } }
private void InnerBegin() { switch (lastItem) { case ItemType.Sprite: if (this.sprite == null) { this.sprite = new SpriteBatchEx(this.GraphicsDevice); } this.sprite.Begin(SpriteSortMode.Deferred, this.alphaBlendState, transformMatrix: this.matrix); break; case ItemType.Skeleton: if (this.spineRender == null) { this.spineRender = new SkeletonMeshRenderer(this.GraphicsDevice); } this.spineRender.Effect.World = matrix ?? Matrix.Identity; this.spineRender.Begin(); break; case ItemType.D2DObject: if (this.d2dRender == null) { this.d2dRender = new D2DRenderer(this.GraphicsDevice); } if (this.matrix == null) { this.d2dRender.Begin(); } else { this.d2dRender.Begin(this.matrix.Value); } break; case ItemType.Sprite_BlendAdditive: if (this.sprite == null) { this.sprite = new SpriteBatchEx(this.GraphicsDevice); } this.sprite.Begin(SpriteSortMode.Deferred, BlendState.Additive, transformMatrix: this.matrix); break; case ItemType.Sprite_BlendNonPremultiplied: if (this.sprite == null) { this.sprite = new SpriteBatchEx(this.GraphicsDevice); } this.sprite.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, transformMatrix: this.matrix); break; } }
private void DrawNameTooltip(RenderEnv env, string name, XnaFont font, Vector2 mapPosition, Color color) { SpriteBatchEx sprite = env.Sprite; Vector2 size = font.MeasureString(name); Rectangle rect = new Rectangle((int)(mapPosition.X - size.X / 2 - 2), (int)(mapPosition.Y + 2), (int)(size.X + 4), (int)(size.Y + 3)); sprite.FillRectangle(rect, new Color(Color.Black, 0.7f), env.Camera.Origin); sprite.DrawStringEx( font, name, new Vector2(rect.X + 2, rect.Y + 2), color, env.Camera.Origin); }
public void Draw(SpriteBatch sb) { DrawSquare(Game1.Instance.GraphicsDevice); sb.Begin(); SpriteBatchEx.DrawLine(sb, PointA, PointB, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointB, PointD, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointD, PointC, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointC, PointA, Color.Black, 1); sb.End(); //Vector2[] Points = new Vector2[4] { PointA, PointB, PointD, PointC }; //SpriteBatchEx.DrawPolyLine(sb, Points, Color, 3, true); }
public static void DrawNineForm(RenderEnv env, NineFormResource res, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; var blocks = LayoutNinePatch(res, size.ToPoint()); foreach (var block in blocks) { if (block.Texture != null && block.Rectangle.Width > 0 && block.Rectangle.Height > 0) { Rectangle rect = new Rectangle(block.Rectangle.X + (int)position.X, block.Rectangle.Y + (int)position.Y, block.Rectangle.Width, block.Rectangle.Height); sprite.Draw(block.Texture, rect, Color.White); } } }
/// <summary> /// Initializes a new instance of the <see cref="WcR2Renderer" /> class. /// </summary> /// <param name="graphicsDevice">The graphics device.</param> /// <param name="nativeScreenWidth">Width of the native screen.</param> /// <param name="nativeScreenHeight">Height of the native screen.</param> public WcR2Renderer(GraphicsDevice graphicsDevice, int nativeScreenWidth, int nativeScreenHeight) { spriteBatch = new SpriteBatchEx(graphicsDevice); GraphicsDevice = graphicsDevice; if (graphicsDevice.PresentationParameters.IsFullScreen) { NativeScreenWidth = nativeScreenWidth; NativeScreenHeight = nativeScreenHeight; } else { NativeScreenWidth = graphicsDevice.PresentationParameters.BackBufferWidth; NativeScreenHeight = graphicsDevice.PresentationParameters.BackBufferHeight; } clipRectanges = new Stack <Rectangle>(); activeEffects = new Stack <Effect>(); }
private void DrawFrame(RenderEnv env, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; sprite.Draw(this.frame["nw"], position, Color.White); sprite.Draw(this.frame["ne"], position + new Vector2(size.X - 13, 0), Color.White); sprite.Draw(this.frame["sw"], position + new Vector2(0, size.Y - 13), Color.White); sprite.Draw(this.frame["se"], position + new Vector2(size.X - 13, size.Y - 13), Color.White); if (size.X > 26) { sprite.Draw(this.frame["n"], new Rectangle((int)position.X + 13, (int)position.Y, (int)size.X - 26, 13), Color.White); sprite.Draw(this.frame["s"], new Rectangle((int)position.X + 13, (int)(position.Y + size.Y) - 13, (int)size.X - 26, 13), Color.White); } if (size.Y > 26) { sprite.Draw(this.frame["e"], new Rectangle((int)(position.X + size.X) - 13, (int)position.Y + 13, 13, (int)size.Y - 26), Color.White); sprite.Draw(this.frame["w"], new Rectangle((int)position.X, (int)position.Y + 13, 13, (int)size.Y - 26), Color.White); } if (size.X > 26 && size.Y > 26) { sprite.Draw(this.frame["c"], new Rectangle((int)position.X + 13, (int)position.Y + 13, (int)size.X - 26, (int)size.Y - 26), Color.White); } sprite.Draw(this.frame["cover"], position, Color.White); }
protected override void Initialize() { base.Initialize(); this.sprite = new SpriteBatchEx(this.GraphicsDevice); }
/// <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.Gray); spriteBatch.Begin(); GameManager.GM.sb = spriteBatch; // TODO: Add your drawing code here //draw menu if (GUIManager.GuiManager.state == (int)GUIManager.GameState.menu) { Menu.M.Draw(Menu.M.MainMenu); } //draw objects else if (GUIManager.GuiManager.state == (int)GUIManager.GameState.play) { //draw every object foreach (Object o in GameManager.GM.objects) { spriteBatch.Draw(texture: o.tex, position: o.pos, destinationRectangle: null, sourceRectangle: null, origin: new Vector2(o.tex.Width / 2, o.tex.Height / 2), rotation: o.rot.Z, scale: null, color: null, layerDepth: 0); } //draw tiles and there reset is debug stuff foreach (KeyValuePair <Guid, PhysicsObject> o in Physics.Phy.physicsObjects) { //draw aabb if ((o.Value.GetType().IsAssignableFrom(typeof(Rect)) || o.Value.GetType().IsSubclassOf(typeof(Rect))) && debug) { Rect ro = (Rect)o.Value; ro.GetPoints(); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y), new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y), new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y + ro.aabb.Height), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y + ro.aabb.Height), new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y + ro.aabb.Height), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y + ro.aabb.Height), new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y), Color.White); Vector2[] tpoints = new Vector2[ro.points.Length]; for (int i = 0; i < ro.points.Length; i++) { tpoints[i] = ro.GetPointAfterRotation(new Vector2(ro.points[i].X, ro.points[i].Y)); } for (int i = 0; i < ro.points.Length; i++) { if (i == ro.points.Length - 1) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(tpoints[0].X, tpoints[0].Y), new Vector2(tpoints[i].X, tpoints[i].Y), Color.Black); } else { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(tpoints[i + 1].X, tpoints[i + 1].Y), new Vector2(tpoints[i].X, tpoints[i].Y), Color.Black); } } } else if ((o.Value.GetType().IsAssignableFrom(typeof(Circle)) || o.Value.GetType().IsSubclassOf(typeof(Circle))) && debug) { Circle c = (Circle)o.Value; Texture2D circle = SpriteBatchEx.CreateCircle((int)c.radius); spriteBatch.Draw(circle, new Vector2(c.pos.X - circle.Width / 2, c.pos.Y - circle.Height / 2), Color.Red); } } if (debug) { foreach (KeyValuePair <int, NavTile> t in GameManager.GM.currentLevel.nav) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), Color.Green); spriteBatch.DrawString(font, t.Key.ToString(), new Vector2(t.Value.pos.X, t.Value.pos.Y), Color.Green); } foreach (PhysicsSystem ps in GameManager.GM.currentLevel.LevelPhysics) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Left, ps.area.Top), new Vector2(ps.area.Right, ps.area.Top), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Right, ps.area.Top), new Vector2(ps.area.Right, ps.area.Bottom), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Right, ps.area.Bottom), new Vector2(ps.area.Left, ps.area.Bottom), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Left, ps.area.Bottom), new Vector2(ps.area.Left, ps.area.Top), Color.Blue); } } base.Draw(gameTime); //draw score spriteBatch.DrawString(font, "Score: " + GameManager.GM.score, new Vector2(700, 650), Color.Red); } spriteBatch.End(); }
//离屏绘制相关 protected override void Initialize() { sprite = new SpriteBatchEx(this.GraphicsDevice); graphics = new AnimationGraphics(this.GraphicsDevice, sprite); }
public static void DrawNineForm(RenderEnv env, NineFormResource res, Vector2 position, Vector2 size) { SpriteBatchEx sprite = env.Sprite; List <RenderBlock> blocks = new List <RenderBlock>(13); //计算框线 int[] x = new int[4] { 0, res.NW.Width, (int)size.X - res.NE.Width, (int)size.X }; int[] y = new int[4] { 0, res.NW.Height, (int)size.Y - res.SW.Height, (int)size.Y }; //绘制左上 blocks.Add(new RenderBlock(res.NW, new Rectangle(x[0], y[0], x[1] - x[0], y[1] - y[0]))); //绘制上 if (res.NW.Height == res.N.Height) { blocks.Add(new RenderBlock(res.N, new Rectangle(x[1], y[0], x[2] - x[1], y[1] - y[0]))); } else if (res.NW.Height > res.N.Height) { int h1 = res.N.Height; blocks.Add(new RenderBlock(res.N, new Rectangle(x[1], y[0], x[2] - x[1], h1))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], h1, x[2] - x[1], y[1] - h1))); } //绘制右上 blocks.Add(new RenderBlock(res.NE, new Rectangle(x[2], y[0], x[3] - x[2], y[1] - y[0]))); //绘制左 if (res.NW.Width == res.W.Width) { blocks.Add(new RenderBlock(res.W, new Rectangle(x[0], y[1], x[1] - x[0], y[2] - y[1]))); } else if (res.NW.Width > res.W.Width) { int w1 = res.W.Width; blocks.Add(new RenderBlock(res.W, new Rectangle(x[0], y[1], w1, y[2] - y[1]))); blocks.Add(new RenderBlock(res.C, new Rectangle(w1, y[1], x[1] - w1, y[2] - y[1]))); } //绘制中 blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], y[1], x[2] - x[1], y[2] - y[1]))); //绘制右 if (res.NE.Width == res.E.Width) { blocks.Add(new RenderBlock(res.E, new Rectangle(x[2], y[1], x[3] - x[2], y[2] - y[1]))); } else if (res.NE.Width > res.E.Width) { int w1 = res.E.Width; blocks.Add(new RenderBlock(res.E, new Rectangle(x[3] - w1, y[1], w1, y[2] - y[1]))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[2], y[1], x[3] - x[2] - w1, y[2] - y[1]))); } //绘制左下 blocks.Add(new RenderBlock(res.SW, new Rectangle(x[0], y[2], x[1] - x[0], y[3] - y[2]))); //绘制下 if (res.SW.Height == res.S.Height) { blocks.Add(new RenderBlock(res.S, new Rectangle(x[1], y[2], x[2] - x[1], y[3] - y[2]))); } else if (res.SW.Height > res.S.Height) { int h1 = res.S.Height; blocks.Add(new RenderBlock(res.S, new Rectangle(x[1], y[3] - h1, x[2] - x[1], h1))); blocks.Add(new RenderBlock(res.C, new Rectangle(x[1], y[2], x[2] - x[1], y[3] - y[2] - h1))); } //绘制右下 blocks.Add(new RenderBlock(res.SE, new Rectangle(x[2], y[2], x[3] - x[2], y[3] - y[2]))); //绘制全部 foreach (var block in blocks) { if (block.Texture != null && block.Rectangle.Width > 0 && block.Rectangle.Height > 0) { Rectangle rect = new Rectangle(block.Rectangle.X + (int)position.X, block.Rectangle.Y + (int)position.Y, block.Rectangle.Width, block.Rectangle.Height); sprite.Draw(block.Texture, rect, Color.White); } } }