private static Rectangle GetSourceRect([NotNull] SpriteSheet1D spriteSheet, int index) { if (index < 0 || index >= spriteSheet.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } float x, y, w, h; switch (spriteSheet.Orientation) { case SpriteSheetOrientation.Horizontal: w = spriteSheet.UnitWidth; h = spriteSheet.UnitHeight; x = index * w; y = 0; break; case SpriteSheetOrientation.Vertical: w = spriteSheet.UnitWidth; h = spriteSheet.UnitHeight; x = 0; y = index * h; break; default: throw new ArgumentOutOfRangeException(); } return(RectHelper.RoundToRectangle(x, y, w, h)); }
public static void Draw([NotNull] this SpriteBatch spriteBatch, SpriteSheet1D spriteSheet, int index, float x, float y) { if (index < 0 || index >= spriteSheet.Count) { return; } var srcRect = GetSourceRect(spriteSheet, index); spriteBatch.Draw(spriteSheet.Texture, new Vector2(x, y), srcRect, Color.White); }
public static void Draw([NotNull] this SpriteBatch spriteBatch, SpriteSheet1D spriteSheet, int index, Rectangle destRect, Rectangle blankEdge) { if (index < 0 || index >= spriteSheet.Count) { return; } var srcRect = GetSourceRect(spriteSheet, index, blankEdge); spriteBatch.Draw(spriteSheet.Texture, destRect, srcRect, Color.White); }
public static void Draw([NotNull] this SpriteBatch spriteBatch, SpriteSheet1D spriteSheet, int index, Rectangle destRect, float opacity = 1.0f) { if (index < 0 || index >= spriteSheet.Count) { return; } if (opacity <= 0) { return; } var srcRect = GetSourceRect(spriteSheet, index); spriteBatch.Draw(spriteSheet.Texture, destRect, srcRect, Color.White * opacity); }
protected override void OnLoadContents() { base.OnLoadContents(); var notesLayerConfig = ConfigurationStore.Get <NotesLayerConfig>(); var theaterDays = Game.ToBaseGame(); var debugOverlay = theaterDays.FindSingleElement <DebugOverlay>(); var gamingArea = theaterDays.FindSingleElement <MltdStage>(); if (gamingArea == null) { throw new InvalidOperationException(); } if (notesLayerConfig.Data.Images.Notes == null || notesLayerConfig.Data.Images.Notes.Length == 0) { if (debugOverlay != null) { debugOverlay.AddLine("WARNING: default notes image strip is not specified."); } } else { _noteImages = new SpriteSheet1D[notesLayerConfig.Data.Images.Notes.Length]; for (var i = 0; i < notesLayerConfig.Data.Images.Notes.Length; ++i) { var notesImageEntry = notesLayerConfig.Data.Images.Notes[i]; if (notesImageEntry == null) { continue; } if (notesImageEntry.File == null || !File.Exists(notesImageEntry.File)) { if (i == 0) { if (debugOverlay != null) { debugOverlay.AddLine($"WARNING: default notes image strip <{notesImageEntry.File ?? string.Empty}> is not found."); } } else { if (debugOverlay != null) { debugOverlay.AddLine($"WARNING: notes image strip <{notesImageEntry.File ?? string.Empty}> is not found, falling back to default."); } } continue; } var imageStrip = ContentHelper.LoadSpriteSheet1D(theaterDays.GraphicsDevice, notesImageEntry.File, notesImageEntry.Count, (SpriteSheetOrientation)notesImageEntry.Orientation); _noteImages[i] = imageStrip; } } var tapPointsConfig = ConfigurationStore.Get <TapPointsConfig>(); _tapPointImage = ContentHelper.LoadTexture(theaterDays.GraphicsDevice, tapPointsConfig.Data.Images.TapPoint.FileName); }
public static SpriteSheet1D LoadSpriteSheet1D([NotNull] GraphicsDevice graphics, [NotNull] Bitmap bitmap, [NotNull] ImageFormat format, int count, SpriteSheetOrientation orientation) { var texture = LoadTexture(graphics, bitmap, format); return(SpriteSheet1D.Wrap(texture, count, orientation)); }
public static SpriteSheet1D LoadSpriteSheet1D([NotNull] GraphicsDevice graphics, [NotNull] string filePath, int count, SpriteSheetOrientation orientation) { var texture = LoadTexture(graphics, filePath); return(SpriteSheet1D.Wrap(texture, count, orientation)); }
private static Rectangle GetSourceRect([NotNull] SpriteSheet1D spriteSheet, int index, Rectangle blankEdge) { var rect = GetSourceRect(spriteSheet, index); return(new Rectangle(rect.Left + blankEdge.Left, rect.Top + blankEdge.Top, rect.Width - (blankEdge.Left + blankEdge.Right), rect.Height - (blankEdge.Top + blankEdge.Bottom))); }