[color="#1C2837"]
So I'm doing some rotation of tiles and they're not rendering to the correct location:
[color="#1C2837"]
The first tile isn't rotated and renders correctly. The other 3 are rotated to each direction other than north. Here's the code:
public override void Draw(GameTime gameTime)
{
ScreenManager.GraphicsDevice.Clear(ClearOptions.Target, Color.Black, 0, 0);
SpriteBatch sb = ScreenManager.SpriteBatch;
sb.Begin();
_defaultViewport = ScreenManager.GraphicsDevice.Viewport;
ScreenManager.GraphicsDevice.Viewport = _dungeonRenderArea;
int x2 = GetTilesShown("width");
int y2 = GetTilesShown("height");
float rotation;
Rectangle rect;
for (int x = _startX; x < x2; x++)
{
for (int y = _startY; y < y2; y++)
{
//TODO: need to fix rotation
if (_rooms[x, y] != null && _rooms[x, y].Type != RoomType.None)
{
rotation = GetRotation(_rooms[x, y].Rotation);
rect = new Rectangle((int)((x - _startX) * (TileSize * _zoomFactor)), (int)((y - _startY) * (TileSize * _zoomFactor)), (int)(TileSize * _zoomFactor), (int)(TileSize * _zoomFactor));
sb.Draw(_roomTiles[(int)_rooms[x, y].Type],
rect,
null,
Color.White,
rotation,
_rooms[x, y].Rotation != Direction.North ? _vecOrigin : Vector2.Zero,
SpriteEffects.None, 1.0f);
sb.DrawString(_debugFont, rect.ToString(), new Vector2(rect.X, rect.Y), Color.White);
}
}
}
ScreenManager.GraphicsDevice.Viewport = _defaultViewport;
sb.End();
}
private float GetRotation(Direction dir)
{
float ret = 0.0f;
switch (dir)
{
case Direction.North:
{
ret = 0.0f;
break;
}
case Direction.East:
{
ret = MathHelper.PiOver2;
break;
}
case Direction.South:
{
ret = MathHelper.Pi;
break;
}
case Direction.West:
{
ret = MathHelper.PiOver2 * 3;
break;
}
}
return ret;
}
_vecOrigin is set to the middle of the sprite. The text is rendering in the correct locations for the tiles, but I can't figure out why the tiles aren't.
Any ideas?