/// <summary> /// Draws the foreground. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="cameraposition">The camera's position.</param> /// <param name="cameramatrix">The camera's transformation matrix. </param> public virtual void DrawForeground(SpriteBatch spritebatch, Rectangle drawarea, Vector2 cameraposition, Matrix cameramatrix) { spritebatch.Begin(SpriteSortMode.Immediate, ForegroundData.BlendState, ForegroundData.SamplerState, ForegroundData.DepthStencilState, ForegroundData.RasterizerState, ForegroundData.Effect, cameramatrix); DrawTileLayer(spritebatch, drawarea, ForegroundLayer); spritebatch.End(); spritebatch.Begin(SpriteSortMode.Immediate, ForedropData.BlendState, ForedropData.SamplerState, ForedropData.DepthStencilState, ForedropData.RasterizerState, ForedropData.Effect, cameramatrix); var drops = new List<XnaBackdrop>(Foredrops.Count); foreach (var foredrop in Foredrops) { drops.Add((XnaBackdrop)foredrop.Value); } drops.Sort(); foreach (var drop in drops) { drop.Draw(spritebatch, drawarea, cameraposition); } spritebatch.End(); }
/// <summary> /// Draws the tile layer. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="layer">The layer to draw.</param> protected virtual void DrawTileLayer(SpriteBatch spritebatch, Rectangle drawarea, int[] layer) { var xstart = (int)(drawarea.X/TileSize.X); var ystart = (int) (drawarea.Y/TileSize.Y); var xend = xstart + (int)(drawarea.Width / TileSize.X) + 2; var yend = ystart + (int)(drawarea.Height / TileSize.Y) + 2; for (var y = ystart; y < yend; y++) { for (var x = xstart; x < xend; x++) { var tile = GetTile(new Vector(x, y), layer); if (tile != null) { //Draw Before foreach (var effect in tile.FloorEffects) { XnaEffect<Tile> xnaeffect = effect as XnaEffect<Tile>; if (xnaeffect != null) { xnaeffect.DrawBefore(spritebatch); } } foreach (var effect in tile.CheckEffects) { XnaEffect<Tile> xnaeffect = effect as XnaEffect<Tile>; if (xnaeffect != null) { xnaeffect.DrawBefore(spritebatch); } } //Draw Animation var anim = (XnaAnimation)tile.Animation; anim.Draw(spritebatch, new Vector2(x, y) * TileSize.ToXnaVector(), Color.White, 0f, Vector2.One, SpriteEffects.None, 0); //Draw After foreach (var effect in tile.FloorEffects) { XnaEffect<Tile> xnaeffect = effect as XnaEffect<Tile>; if (xnaeffect != null) { xnaeffect.DrawAfter(spritebatch); } } foreach (var effect in tile.CheckEffects) { XnaEffect<Tile> xnaeffect = effect as XnaEffect<Tile>; if (xnaeffect != null) { xnaeffect.DrawAfter(spritebatch); } } } } } }
/// <summary> /// Runs the general draw cycle for a map. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="cameraposition">The camera's position.</param> /// <param name="cameramatrix">The camera's transformation matrix. </param> public virtual void DrawCycle(SpriteBatch spritebatch, Rectangle drawarea, Vector2 cameraposition, Matrix cameramatrix) { DrawBackground(spritebatch, drawarea, cameraposition, cameramatrix); var entities = Entities as XnaEntityManager; if (entities != null) { entities.Draw(spritebatch, drawarea, cameramatrix); } DrawForeground(spritebatch, drawarea, cameraposition, cameramatrix); }
/// <summary> /// Draws the debug information. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="cameramatrix">The camera's transformation matrix.</param> /// <param name="texture">The texture use to draw. It should be a 1x1 white pixel texture.</param> public virtual void DrawDebugInfo(SpriteBatch spritebatch, Rectangle drawarea, Matrix cameramatrix, Texture2D texture) { var entities = Entities as XnaEntityManager; if (entities != null) { entities.DrawHitboxes(spritebatch, drawarea, cameramatrix, texture); } }
/// <summary> /// Draws the backdrop /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="cameraposition">The camera's position.</param> public virtual void Draw(SpriteBatch spritebatch, Rectangle drawarea, Vector2 cameraposition) { var drawposition = Position.ToXnaVector() + (cameraposition*Parallax.ToXnaVector()); if (LoopX) { if (LoopY) { DrawLoopBoth(spritebatch, drawarea, drawposition); } else { DrawLoopX(spritebatch, drawarea, drawposition); } } else { if (LoopY) { DrawLoopY(spritebatch, drawarea, drawposition); } else { DrawBackdrop(spritebatch, drawarea, drawposition); } } }
/// <summary> /// Draws the collision maps. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="cameramatrix">The camera's transformation matrix. </param> /// <param name="texture">The texture use to draw. It should be a 1x1 white pixel texture.</param> public virtual void DrawCollisionMaps(SpriteBatch spritebatch, Rectangle drawarea, Matrix cameramatrix, Texture2D texture) { var xstart = (int)(drawarea.X / TileSize.X); var ystart = (int)(drawarea.Y / TileSize.Y); var xend = xstart + (int)(drawarea.Width / TileSize.X) + 2; var yend = ystart + (int)(drawarea.Height / TileSize.Y) + 2; Rectangle empty = new Rectangle(); spritebatch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp, null, null, null, cameramatrix); for (var y = ystart; y < yend; y++) { for (var x = xstart; x < xend; x++) { var hitbox = GetHitbox(new Vector(x, y)); if (!hitbox.Equals(empty)) { spritebatch.Draw(texture, new Vector2(hitbox.X, hitbox.Y), texture.Bounds, Color.Aqua * .7f, 0f, Vector2.Zero, new Vector2(hitbox.Width, hitbox.Height), SpriteEffects.None, 0f); } } } spritebatch.End(); }
/// <summary> /// Draws the backdrop looping on the Y axis. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="drawposition">The position to draw at.</param> protected virtual void DrawLoopY(SpriteBatch spritebatch, Rectangle drawarea, Vector2 drawposition) { //First move it outside of the draw area while (drawposition.Y >= drawarea.Y) { drawposition.Y -= Texture.Height; } //Draw, then move the position till it's offscreen, then stop. while (drawposition.Y <= drawarea.Bottom) { DrawBackdrop(spritebatch, drawarea, drawposition); drawposition.Y += Texture.Height; } }
/// <summary> /// Draws the backdrop looping on the X axis. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="drawposition">The position to draw at.</param> protected virtual void DrawLoopX(SpriteBatch spritebatch, Rectangle drawarea, Vector2 drawposition) { //First move it outside of the draw area while (drawposition.X >= drawarea.X) { drawposition.X -= Texture.Width; } //Draw, then move the position till it's offscreen, then stop. while (drawposition.X <= drawarea.Right) { DrawBackdrop(spritebatch, drawarea, drawposition); drawposition.X += Texture.Width; } }
/// <summary> /// Actually draws the backdrop. /// </summary> /// <param name="spritebatch">The spritebatch to use for drawing.</param> /// <param name="drawarea">The area of the screen.</param> /// <param name="drawposition">The position to draw at.</param> protected virtual void DrawBackdrop(SpriteBatch spritebatch, Rectangle drawarea, Vector2 drawposition) { spritebatch.Draw(Texture, drawposition, Texture.Bounds, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); }
/// <summary> /// Initializes a new instance of the <see cref="XnaFrame" /> class. /// </summary> /// <param name="textureid">The ID used for texture loading.</param> /// <param name="drawarea">The area on the texture that should be drawn.</param> /// <param name="origin">The origin of the frame. Used for rotation and to offset the sprite.</param> /// <param name="timetillnext">The time until the frame changes.</param> /// <param name="spriteeffect">The sprite effect used to flip the texture.</param> public XnaFrame(string textureid, SOLRect drawarea, Vector origin, float timetillnext, SpriteEffects spriteeffect) : this(textureid, drawarea, origin, timetillnext) { SpriteEffect = spriteeffect; }
/// <summary> /// Initializes a new instance of the <see cref="XnaFrame" /> class. /// </summary> /// <param name="textureid">The ID used for texture loading.</param> /// <param name="drawarea">The area on the texture that should be drawn.</param> /// <param name="origin">The origin of the frame. Used for rotation and to offset the sprite.</param> /// <param name="timetillnext">The time until the frame changes.</param> public XnaFrame(string textureid, SOLRect drawarea, Vector origin, float timetillnext) : base(textureid, drawarea, origin, timetillnext) { SpriteEffect = SpriteEffects.None; }