Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Fixed Tileset tiles render and added tile remove methods
Browse files Browse the repository at this point in the history
  • Loading branch information
craftersmine committed Mar 31, 2019
1 parent c238e7f commit 9d38240
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion craftersmine.EtherEngine.Core/Objects/Tile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace craftersmine.EtherEngine.Core
using craftersmine.EtherEngine.Rendering;

namespace craftersmine.EtherEngine.Core
{
/// <summary>
/// Represents a world tile
Expand All @@ -25,5 +27,10 @@ public Tile()
{

}

public override void OnRender(GLGDI renderer)
{
base.OnRender(renderer);
}
}
}
26 changes: 26 additions & 0 deletions craftersmine.EtherEngine.Core/Objects/Tileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using craftersmine.EtherEngine.Content;
using craftersmine.EtherEngine.Rendering;
using craftersmine.EtherEngine.Utilities;

namespace craftersmine.EtherEngine.Core
Expand Down Expand Up @@ -49,8 +50,11 @@ public override void OnUpdate()
{
for (int i = 0; i < _tiles.Count; i++)
{
//if (!SceneManager.CurrentScene.GameObjects.Contains(_tiles[i]))
// SceneManager.CurrentScene.AddGameObject(_tiles[i]);
_tiles[i].OnUpdate();
TileOnUpdateAction?.Invoke(_tiles[i]);
_tiles[i].Visible = Visible;
}
}

Expand Down Expand Up @@ -86,14 +90,36 @@ public void AddTile(Tile tile, int x, int y)
{
tile.TilesetX = x;
tile.TilesetY = y;
tile.X = tile.TilesetX * TileWidth;
tile.Y = tile.TilesetY * TileHeight;
tile.Width = TileWidth;
tile.Height = TileHeight;
_tiles.Add(tile);
SceneManager.CurrentScene.AddGameObject(tile);
tile.Visible = true;
}
catch (Exception ex)
{
Debugging.Log(LogEntryType.Warning, "Unable to add tile " + tile.TileId + " @" + x + "," + y);
Debugging.LogException(LogEntryType.Warning, ex);
}
}

public void RemoveTile(Tile tile)
{
if (_tiles.Contains(tile))
{
_tiles.Remove(tile);
SceneManager.CurrentScene.RemoveGameObject(tile);
}
}

public void RemoveTile(int x, int y)
{
Tile tile = CheckTile(x, y);
if (tile != null)
RemoveTile(tile);
}
}

/// <summary>
Expand Down

0 comments on commit 9d38240

Please sign in to comment.