Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Platformer2D/Core/Game/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ private Tile LoadTile(char tileType, int x, int y)
case 'P':
return LoadStartTile(x, y);

// Background block
case ',':
Tile tile = LoadVarietyTile("BlockB", 2, TileCollision.Passable);
tile.TintColor = new Color(120, 130, 150);
return tile;

// Unknown tile type character
default:
throw new NotSupportedException(String.Format(Resources.ErrorUnsupportedTileType, tileType, x, y));
Expand Down Expand Up @@ -830,8 +836,9 @@ private void DrawTiles(SpriteBatch spriteBatch)
int right = (int)(left + screenManager.BaseScreenSize.X / Tile.Width);
right = Math.Min(right, Width - 1);

// Reuse a single Vector2 object for tile positions to reduce memory allocations.
// Reuse a single Vector2 and Color object for tile positions and tint color to reduce memory allocations.
var position = new Vector2();
var tintColor = Color.White;

// Loop through each tile position within the visible range.
for (int y = 0; y < Height; ++y)
Expand All @@ -845,7 +852,9 @@ private void DrawTiles(SpriteBatch spriteBatch)
position.X = x * Tile.Size.X;
position.Y = y * Tile.Size.Y;

spriteBatch.Draw(texture, position, Color.White);
tintColor = tiles[x, y].TintColor;

spriteBatch.Draw(texture, position, tintColor);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Platformer2D/Core/Game/Tile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ struct Tile
/// </summary>
public Texture2D Texture;

/// <summary>
/// Specifies the color tint to apply to the Texture when drawing.
/// </summary>
public Color TintColor = Color.White;

/// <summary>
/// The type of collision behavior this tile exhibits.
/// </summary>
Expand Down
Loading