//------------------------------------------------------------------------------------------------------------------------ // spawnBackgroundTiles() //------------------------------------------------------------------------------------------------------------------------ public void SpawnOverlapTiles(Map levelData) { // Check if there are layers if (levelData.Layers == null || levelData.Layers.Length == 0) { return; } // Setting the mainlayer to the first layer Layer mainLayer = levelData.Layers[2]; short[,] tileNumbers = mainLayer.GetTileArray(); for (int row = 0; row < mainLayer.Height; row++) { for (int col = 0; col < mainLayer.Width; col++) { int tileNumber = tileNumbers[col, row]; if (tileNumber > 0) { bgTile = new BackgroundTile(BgSpriteSheet, BgCols, BgRows); bgTile.SetFrame(tileNumber - 4); bgTile.x = col * bgTile.width + bgTile.width / 2; bgTile.y = row * bgTile.height + bgTile.height / 2; AddChild(bgTile); } } } AddActivityBoxes(); }
/// <summary> /// Spawns tiles to their positions /// </summary> /// <param name="leveldata"> This needs a leveldata map to read out of to get the data of the tiles </param> private void SpawnTiles(Map leveldata) { foreach (Layer _layer in leveldata.Layers) { if (leveldata.Layers == null || leveldata.Layers.Length == 0) { continue; } short[,] _tileNumbers = _layer.GetTileArray(); for (int row = 0; row < _layer.Height; row++) { for (int col = 0; col < _layer.Width; col++) { bool _isBackgroundTile = _layer.GetBoolProperty("Background"); int _tileNumber = _tileNumbers[col, row]; TileSet _tiles = leveldata.GetTileSet(_tileNumber); string _filenameTiles = _tiles.Image.FileName; _filenameTiles = _filenameTiles.Remove(0, 3); if (_tileNumber > 0 && _isBackgroundTile == false) { CollisionTile _tile = new CollisionTile(_filenameTiles, _tiles.Columns, _tiles.Rows); _tile.SetFrame(_tileNumber - _tiles.FirstGId); _tile.x = col * _tile.width; _tile.y = row * _tile.height; AddChild(_tile); } else if (_tileNumber > 0 && _isBackgroundTile == true) { BackgroundTile _backgroundTile = new BackgroundTile(_filenameTiles, _tiles.Columns, _tiles.Rows); _backgroundTile.SetFrame(_tileNumber - _tiles.FirstGId); _backgroundTile.x = col * _backgroundTile.width; _backgroundTile.y = row * _backgroundTile.height; AddChild(_backgroundTile); } } } } }