Skip to content

Instantly share code, notes, and snippets.

@phrohdoh
Last active Aug 29, 2015
Embed
What would you like to do?
// World.cs
public Rectangle GetSourceRectangle(Texture2D tileset, int tileIndex, int tileSize)
{
var borderSize = 1;
var paddedTileSize = tileSize + borderSize;
var tilesPerRow = tileset.Width / paddedTileSize;
var x = paddedTileSize * (tileIndex % tilesPerRow);
var y = paddedTileSize * (tileIndex / tilesPerRow);
return new Rectangle(x, y, tileSize, tileSize);
}
void CreateTiles()
{
var tilesheet = content.Load<Texture2D>("tilesetTest");
for (var x = 0; x < tiles2D.GetLength(0); x++)
{
for (var y = 0; y < tiles2D.GetLength(1); y++)
{
var typeNum = random.Next(0, 200); // 200 seems to be some odd seed value???
tiles2D[x,y] = new Tile(this, tilesheet, typeNum);
}
}
}
// Tile.cs ctor
sourceRect = world.GetSourceRectangle(tileSheet, type, 48);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment