private static Rectangle GetSourceRect([NotNull] SpriteSheet2D spriteSheet, int index) { if (index < 0 || index >= spriteSheet.ArrayCount) { throw new ArgumentOutOfRangeException(nameof(index)); } int xIndex, yIndex; float w, h; switch (spriteSheet.Orientation) { case SpriteSheetOrientation.Horizontal: w = spriteSheet.UnitWidth; h = spriteSheet.UnitHeight; xIndex = index % spriteSheet.Stride; yIndex = index / spriteSheet.Stride; break; case SpriteSheetOrientation.Vertical: w = spriteSheet.UnitWidth; h = spriteSheet.UnitHeight; xIndex = index / spriteSheet.Stride; yIndex = index % spriteSheet.Stride; break; default: throw new ArgumentOutOfRangeException(); } var x = xIndex * w; var y = yIndex * h; return(RectHelper.RoundToRectangle(x, y, w, h)); }
protected override void Initialize() { var version = Assembly.GetEntryAssembly().GetName().Version; batch = new SpriteBatch(this); tex = Content.Load <Texture2D> ("nginz.png", TextureConfiguration.Nearest); testSheet = new SpriteSheet2D(Content.Load <Texture2D> ("classical_ruin_tiles_1.png", TextureConfiguration.Nearest), 23, 16); testMap = new TileMap(new Vector2(128, 256), 32, 32, new Vector2(32, 32), 2); testMap.AddLayer("testLayer", testSheet); /*testMap.SetTile ("testLayer", 0, 1, 0); * testMap.SetTile ("testLayer", 1, 1, 1); * testMap.SetTile ("testLayer", 2, 1, 2); * testMap.SetTile ("testLayer", 3, 1, 3);*/ stage = new Stage(this); var mascot = new MascotActor(); stage.AddActor(mascot); stage.AddAction(mascot); stage.TileMap = testMap; base.Initialize(); }
public static void Draw([NotNull] this SpriteBatch spriteBatch, SpriteSheet2D spriteSheet, int index, float x, float y) { if (index < 0 || index >= spriteSheet.ArrayCount) { return; } var srcRect = GetSourceRect(spriteSheet, index); spriteBatch.Draw(spriteSheet.Texture, new Vector2(x, y), srcRect, Color.White); }
public Bird(Game game, TubeGenerator generator) { this.game = game; this.generator = generator; var sheetTex = game.Content.Load <Texture2D> ("flappymascot_char.png", TextureConfiguration.Nearest); sheet = new SpriteSheet2D(sheetTex, 4, 1); animator = new Animator(sheet, 4); animator.DurationInMilliseconds = 500; animator.Position.X = game.Resolution.Width * 0.25f; ypos = (game.Resolution.Height / 2) + (sheet [0].Height / 2); }
} // a single white pixel public static void Load() { var cache = AtomicNET.GetSubsystem <ResourceCache>(); SpriteSheet2D sheet = cache.GetResource <SpriteSheet2D>("Sprites/AtomicBlasterSprites.xml"); Player = new CustomSprite(sheet.GetSprite("Player")); Seeker = new CustomSprite(sheet.GetSprite("Seeker")); Wanderer = new CustomSprite(sheet.GetSprite("Wanderer")); Bullet = new CustomSprite(sheet.GetSprite("Bullet")); Pointer = new CustomSprite(sheet.GetSprite("Pointer")); BlackHole = new CustomSprite(sheet.GetSprite("BlackHole")); LineParticle = new CustomSprite(sheet.GetSprite("Laser")); Glow = new CustomSprite(sheet.GetSprite("Glow")); Pixel = new CustomSprite(sheet.GetSprite("Pixel")); }
protected override void Initialize() { UITexture = Content.Load <Texture2D> ("TDUserInterface.png", TextureConfiguration.Nearest); SpriteSheet = new SpriteSheet2D(Content.Load <Texture2D> ("TDSheet.png", TextureConfiguration.Nearest), 16, 16); TileMap = new TileMap(Vector2.Zero, 26 / 2, 18 / 2, new Vector2(16, 16), 4); TileMap.AddLayer("GrassLayer", SpriteSheet); for (int y = 0; y < TileMap.Height; y++) { for (int x = 0; x < TileMap.Width; x++) { TileMap.SetTile("GrassLayer", x, y, new Tile { TileId = SpriteSheet.GetTileId(1, 1) }); } } TileMap.AddLayer("Track", SpriteSheet); var tiles = new int[][] { new int[] { }, new int[] { 20, 1, 1, 2 }, new int[] { -1, -1, -1, 32, 1, 2 }, new int[] { 0, 1, 2, -1, -1, 16, -1, 16 }, new int[] { 16, -1, 16, -1, -1, 18, -1, 16 }, new int[] { 16, -1, 32, 1, 1, 34, -1, 16 }, new int[] { 16, -1, -1, -1, -1, -1, -1, 16 }, new int[] { 32, 1, 1, 1, 1, 1, 1, 34 } }; for (int y = 0; y < tiles.Length; y++) { for (int x = 0; x < tiles[y].Length; x++) { TileMap.SetTile("Track", x, y, new Tile { TileId = tiles[y][x] }); } } Font = Content.Load <Font> ("durselinvenice2015.ttf", 15f); base.Initialize(); }
public static SpriteSheet2D LoadSpriteSheet2D([NotNull] GraphicsDevice graphics, [NotNull] Bitmap bitmap, [NotNull] ImageFormat format, float unitWidth, float unitHeight, int stride, int arrayCount, SpriteSheetOrientation orientation) { var texture = LoadTexture(graphics, bitmap, format); return(SpriteSheet2D.Wrap(texture, unitWidth, unitHeight, stride, arrayCount, orientation)); }