private void LoadOre() { var texture = _contentManager.Load <Texture2D>("Ore"); var textureMap = _contentManager.Load <Dictionary <string, Rectangle> >("OreMap"); var atlas = new TextureAtlas("OreAtlas", texture, textureMap); _textureMap.Add(Texture.IronOre1, atlas.GetRegion(0)); _textureMap.Add(Texture.IronOre2, atlas.GetRegion(1)); _textureMap.Add(Texture.IronOre3, atlas.GetRegion(2)); }
private void LoadConveyorBelt() { var texture = _contentManager.Load <Texture2D>("ConveyorBelt"); var textureMap = _contentManager.Load <Dictionary <string, Rectangle> >("ConveyorBeltMap"); var atlas = new TextureAtlas("ConveyorBeltAtlas", texture, textureMap); _textureMap.Add(Texture.ConveyorBeltNE, atlas.GetRegion(0)); _textureMap.Add(Texture.ConveyorBeltSE, atlas.GetRegion(1)); _textureMap.Add(Texture.ConveyorBeltSW, atlas.GetRegion(2)); _textureMap.Add(Texture.ConveyorBeltNW, atlas.GetRegion(3)); }
private void LoadMiner() { var texture = _contentManager.Load <Texture2D>("Miner"); var textureMap = _contentManager.Load <Dictionary <string, Rectangle> >("MinerMap"); var atlas = new TextureAtlas("MinerAtlas", texture, textureMap); _textureMap.Add(Texture.MinerNE, atlas.GetRegion(0)); _textureMap.Add(Texture.MinerSE, atlas.GetRegion(1)); _textureMap.Add(Texture.MinerSW, atlas.GetRegion(2)); _textureMap.Add(Texture.MinerNW, atlas.GetRegion(3)); }
public void TextureAtlas_GetRegionsByName_Test() { var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200); var atlas = new TextureAtlas(null, texture); var region0 = atlas.CreateRegion("region0", 10, 20, 30, 40); var region1 = atlas.CreateRegion("region1", 50, 60, 35, 45); Assert.AreSame(region0, atlas["region0"]); Assert.AreSame(region1, atlas["region1"]); Assert.AreSame(region0, atlas.GetRegion("region0")); Assert.AreSame(region1, atlas.GetRegion("region1")); }
public static void Draw(SpriteBatch batch, Viewport viewport, Camera camera) { batch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, camera.ViewMatrix); Overlay.DrawPreviews(batch, camera); batch.End(); batch.Begin( SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, Matrix.CreateScale(Scale)); Overlay.Draw(batch); if (CurrentInterface != null) { batch.FillRectangle(Vector2.Zero, new Size2(viewport.Width, viewport.Height), new Color(Color.Black, 0.5F)); CurrentInterface.Draw(batch); } batch.End(); if (currentCursor >= 0) { batch.Begin(SpriteSortMode.Immediate, null, SamplerState.PointClamp); batch.Draw( CursorsTexture.Texture, new Rectangle(Mouse.GetState().Position, new Point(32, 32)), CursorsTexture.GetRegion((int)currentCursor % 4, (int)currentCursor / 4), Color.Multiply(Color.White, cursorAlpha)); batch.End(); } }
public ProjectileFactory(IEntityManager entityManager, TextureAtlas atlas) { _entityManager = entityManager; _atlas = atlas; _projectileTextures = new Dictionary <string, TextureRegion2D>(); _flashTexture = _atlas.GetRegion("shotRed"); }
/// <summary> /// /// </summary> /// <param name="weapon"></param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="movementSpeed"></param> public void SpawnProjectile(WeaponComponent weapon, Vector2 position, float rotation, float movementSpeed) { // First get texture for the projectile, add to dictionary if it isn't there. if (!_projectileTextures.TryGetValue(weapon.ProjectileName, out var texture)) { texture = _atlas.GetRegion(weapon.ProjectileName); _projectileTextures[weapon.ProjectileName] = texture ?? throw new ArgumentException($"Invalid projectile name defined in WeaponComponent: {weapon.ProjectileName}"); } // Spawn our entity var projectile = _entityManager.AddEntity(new Projectile(texture, position, movementSpeed) { Rotation = rotation, DamageSource = weapon.DamageSource }); if (projectile == null) { Debug.WriteLine("Unable to add projectile."); return; } // Accelerate it projectile.Accelerate(movementSpeed); // Spawn the flash _entityManager.AddEntity(new ProjectileFlashEffect(_flashTexture, position, rotation, 200)); }
public void TextureAtlas_GetRegion_InvalidIndexThrowsException_Test() { var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200); var atlas = new TextureAtlas(null, texture); atlas.CreateRegion("region0", 10, 20, 30, 40); Assert.Throws <IndexOutOfRangeException>(() => atlas.GetRegion(-1)); }
public void TextureAtlas_GetRegion_InvalidNameThrowsException_Test() { var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200); var atlas = new TextureAtlas(null, texture); atlas.CreateRegion("region0", 10, 20, 30, 40); Assert.Throws <KeyNotFoundException>(() => atlas.GetRegion("region1")); }
public void TextureAtlas_GetRegion_InvalidIndexThrowsException_Test() { var texture = new Texture2D(TestHelper.CreateGraphicsDevice(), 100, 200); var atlas = new TextureAtlas(texture); atlas.CreateRegion("region0", 10, 20, 30, 40); atlas.GetRegion(-1); }
protected override void LoadContent() { _viewportAdapter = new ScalingViewportAdapter(_graphics.GraphicsDevice, 1600, 900); _camera = new OrthographicCamera(_viewportAdapter); _spriteBatch = new SpriteBatch(_graphics.GraphicsDevice); if (File.Exists(@"Content\allSprites_default.xml")) { _atlas = TextureAtlasData.CreateFromFile(Content, @"Content\allSprites_default.xml"); _projectileFactory = new ProjectileFactory(_entityManager, _atlas); } var map = Content.Load <TiledMap>("map01"); _mapRenderer = new TiledMapRenderer(_graphics.GraphicsDevice); LoadMap(map); _player = _entityManager.AddEntity( new Player(_atlas.GetRegion("tankBody_red"), _atlas.GetRegion("tankRed_barrel1"), _projectileFactory) ); _movementController = new MovementController(_player, _camera); }
/** * Return the TextureDisplay. * @example * <listing> * var texturedisplay:Object = factory.getTextureDisplay('dragon'); * </listing> * @param The name of this Texture. * @param The name of the TextureAtlas. * @param The registration pivotX position. * @param The registration pivotY position. * @return An Object. */ public Object GetTextureDisplay(string textureName, string textureAtlasName = null, float pivotX = float.NaN, float pivotY = float.NaN) { TextureAtlas textureAtlas = null; if (textureAtlasName != null) { textureAtlas = _textureAtlasDic[textureAtlasName]; } if (textureAtlas == null && textureAtlasName == null) { foreach (KeyValuePair <string, TextureAtlas> atlas in _textureAtlasDic as Dictionary <string, TextureAtlas> ) { textureAtlas = _textureAtlasDic[atlas.Key]; if (textureAtlas.GetRegion(textureName) != null) { break; } textureAtlas = null; } } if (textureAtlas != null) { if (float.IsNaN(pivotX) || float.IsNaN(pivotY)) { SkeletonData data = _dataDic[textureAtlasName]; if (data != null) { Point pivot = data.GetSubTexturePivot(textureName); if (pivot != null) { pivotX = pivot.X; pivotY = pivot.Y; } } } return(generateDisplay(textureAtlas, textureName, pivotX, pivotY)); } return(null); }
/// <summary> /// Retrieves the bounding rectangle of a tile texture from the tilemap /// </summary> /// <returns>The tile ID's bounding rectangle.</returns> /// <param name="id">The ID to get.</param> public Rectangle GetTile(int id) { return(_atlas.GetRegion(id).Bounds); }
/// <summary> /// Gets the texture atlas region for a particular state. /// </summary> /// <param name="state"></param> /// <returns></returns> private TextureRegion2D GetTextureAtlasRegion(TrapState state) { return(atlas.GetRegion(state.ToString())); }
public static TextureRegion2D GetPlayerTexture() { return(playerAtlas.GetRegion(0)); }
/// <summary> /// Gets the texture region for the given direction. /// </summary> /// <param name="direction"></param> /// <returns></returns> private TextureRegion2D GetAtlasRegion(Direction direction) { return(atlas.GetRegion(direction.ToString())); }
static void ProcessTiles() { tileDictionary = new Dictionary <string, TextureRegion2D>(tileAtlas.RegionCount); tileDictionary["Grass"] = tileAtlas.GetRegion(0); }