/// <summary> /// Creates a Collidable tile, Dynamic or Static. /// </summary> /// <param name="bodyType"></param> /// <param name="texture">Texture for the tile.</param> /// <param name="position">Position of the tile.</param> /// <param name="tileSize">Size of the file.</param> /// <param name="rotation">Rotation of the tile.</param> /// <param name="density">Density of it?</param> /// <returns>ICollidableTile</returns> public ICollidableTile CreateCollidableTile(BodyType bodyType, Texture2D texture, Vector2 position, Rectangle tileSize, float rotation, float density) { ICollidableTile collidableTile; Body physicsBody = null; if (PhysicsBodyCache.Count == 0) { //If our cache is empty make a brand spankin' new one physicsBody = BodyFactory.CreateRectangle(m_physicsWorld, ConvertUnits.ToSimUnits(tileSize.Width), ConvertUnits.ToSimUnits(tileSize.Height), density); } else { //If we have some phyasics bodies in our cache just grab the first one, they are all pretty much the same. physicsBody = PhysicsBodyCache[0]; //and remove it so we don't try to use it again PhysicsBodyCache.Remove(physicsBody); } collidableTile = new Tiles.StaticCollidableTile(m_spriteBatch, texture, position, physicsBody, tileSize.Height, tileSize.Width, rotation, m_physicsWorld); CollidableTiles.Add(collidableTile); Tiles.Add(collidableTile); return(collidableTile); }
/// <summary> /// Creates a Collidable tile, Dynamic or Static. /// </summary> /// <param name="bodyType"></param> /// <param name="texture">Texture for the tile.</param> /// <param name="position">Position of the tile.</param> /// <param name="tileSize">Size of the file.</param> /// <param name="rotation">Rotation of the tile.</param> /// <param name="density">Density of it?</param> /// <returns>ICollidableTile</returns> public ICollidableTile CreateCollidableTile(BodyType bodyType, Texture2D texture, Vector2 position, Rectangle tileSize, float rotation, float density) { ICollidableTile collidableTile; Body physicsBody = null; if (PhysicsBodyCache.Count == 0) { //If our cache is empty make a brand spankin' new one physicsBody = BodyFactory.CreateRectangle(m_physicsWorld, ConvertUnits.ToSimUnits(tileSize.Width), ConvertUnits.ToSimUnits(tileSize.Height), density); } else { //If we have some phyasics bodies in our cache just grab the first one, they are all pretty much the same. physicsBody = PhysicsBodyCache[0]; //and remove it so we don't try to use it again PhysicsBodyCache.Remove(physicsBody); } collidableTile = new Tiles.StaticCollidableTile(m_spriteBatch, texture, position, physicsBody, tileSize.Height, tileSize.Width, rotation, m_physicsWorld); CollidableTiles.Add(collidableTile); Tiles.Add(collidableTile); return collidableTile; }