Skip to content

Commit b50e8a1

Browse files
author
psilo
committed
updated readme.md
1 parent ea855e3 commit b50e8a1

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

README.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,32 @@ Then you have to tell the grid how many cells it has by setting the number of ce
5858
Then you may add your sprites or other objects to the grid by calling `Add(object, Point/Vector2/Rectangle/Rect)` or `Move(object, Point/Vector2/Rectangle/Rect)`. Move removes the item first if it was present on the grid.
5959

6060
### Parameters
61-
The first parameter is your item. The grid is generic and there are no constraints for that.
62-
The second parameter is always one of the following:
63-
| Parameter | Description | Info |
64-
|:----------|:------------|:-----|
65-
|Point|This is an int-point.|By specifying this you tell the grid you mean the cell at exactly this position.|
66-
|Vector2|This is a float-vector.|By specifying this you tell the grid that you mean the cell that contains these game-coordinates.|
67-
|Rectangle|This is a basic int-rectangle. It is not rotated and therefore axis-alinged. So it's an Axis-Aligned-Bounding-Box or AABB.|By specifying this you give the grid a rectangle in the cell-coordinate-system (0-numberOfCellsX, 0-numberOfCellsY).|
68-
|Rect|This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.|By specifying this you give the grid a rectangle in the game-coordinate-system.|
69-
61+
The first parameter is your item. The grid is generic and there are no constraints for that.
62+
The second parameter is always one of the following:
63+
#### Point
64+
This is an int-point.
65+
By specifying this you tell the grid you mean the cell at exactly this position.
66+
#### Vector2
67+
This is a float-vector.
68+
By specifying this you tell the grid that you mean the cell that contains these game-coordinates.
69+
#### Rectangle
70+
This is a basic int-rectangle.
71+
It is not rotated and therefore axis-alinged. So it's an Axis-Aligned-Bounding-Box or AABB.
72+
By specifying this you give the grid a rectangle in the cell-coordinate-system (0-numberOfCellsX, 0-numberOfCellsY).
73+
#### Rect
74+
This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.
75+
By specifying this you give the grid a rectangle in the game-coordinate-system.
76+
7077
All rectangles this grid works with are axis-aligned.
7178

7279
You're free to remove them at any time by using one of the remove-methods `Remove(Point/Vector2/Rectangle/Rect)`.
7380

7481
The method `Get(Point/Vector2/Rectangle/Rect)` returns an array of your items with all of them that the grid has encountered in the area you've specified when calling `Get`. If it doesn't find any it returns an empty array.
7582

83+
If you add your sprites by their position, then this is what the grid will basically do:
7684
![Position Test][testposition]
7785

86+
If you add your sprites by their AABBs, then this is what the grid will basically do:
7887
![Rectangle Test][testrectangle]
7988

8089
#### Example
@@ -83,7 +92,9 @@ Set up the collision-grid:
8392
```csharp
8493
public CollisionGrid<Sprite> Grid;
8594

86-
public DrawableGrid(Game game, SpriteBatch spriteBatch, float width, float height, int numberOfCellsX, int numberOfCellsY) : base(game)
95+
public DrawableGrid(Game game, SpriteBatch spriteBatch,
96+
float width, float height, int numberOfCellsX,
97+
int numberOfCellsY) : base(game)
8798
{
8899
Grid = new CollisionGrid<Sprite>(width, height, numberOfCellsX, numberOfCellsY);
89100
}
@@ -99,7 +110,23 @@ public override void Update(GameTime gameTime)
99110
}
100111
}
101112
```
102-
The move-method adds an item on the given position (cell that encapsulates the given game-coordinate)
113+
The move-method adds an item on the given position (cell that encapsulates the given game-coordinate).
114+
This is the code to achieve the output in the first GIF.
115+
116+
To achieve the output in the second one, just change the Move-line to the following one:
117+
```csharp
118+
Grid.Move(s, s.getAABB());
119+
```
120+
Whereas of course your sprite has to return the axis-aligned-bounding-box as a Rect.
121+
122+
Please don't forget to clean up afterwards. There are a few data-structures the grid has to dispose of:
123+
```csharp
124+
protected override void UnloadContent()
125+
{
126+
base.UnloadContent();
127+
Grid.Dispose();
128+
}
129+
```
103130

104131
[homepage]: http://www.unterrainer.info
105132
[coding]: http://www.unterrainer.info/Home/Coding

0 commit comments

Comments
 (0)