Time for action – the TileMap class – part 2

  1. Add methods dealing with locating map cells to the TileMap class:
    #region Information about Map Cells
    static public int GetCellByPixelX(int pixelX)
    {
        return pixelX / TileWidth;
    }
    
    static public int GetCellByPixelY(int pixelY)
    {
        return pixelY / TileHeight;
    }
    
    static public Vector2 GetCellByPixel(Vector2 pixelLocation)
    {
        return new Vector2(
            GetCellByPixelX((int)pixelLocation.X),
            GetCellByPixelY((int)pixelLocation.Y));
    }
     static public Vector2 GetCellCenter(int cellX, int cellY) { return new Vector2( (cellX * TileWidth) + (TileWidth / 2), (cellY * TileHeight) + (TileHeight / 2)); } static public Vector2 GetCellCenter(Vector2 cell) { return GetCellCenter( (int)cell.X, (int)cell.Y); } static public Rectangle ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.