Я уже просмотрел http://msdn.microsoft.com/en-us/library/bb196414.aspx#ID2EEF здесь объясняют, как рисовать 2D-линии в xna, но я получаю исключение (см. скрипт)
{
int points = 3;//I tried different values(1,2,3,4)
VertexPositionColor[] primitiveList = new VertexPositionColor[points];
for (int x = 0; x < points / 2; x++)
{
for (int y = 0; y < 2; y++)
{
primitiveList[(x * 2) + y] = new VertexPositionColor(
new Vector3(x * 100, y * 100, 0), Color.White);
}
}
// Initialize an array of indices of type short.
short[] lineListIndices = new short[(points * 2) - 2];
// Populate the array with references to indices in the vertex buffer
for (int i = 0; i < points - 1; i++)
{
lineListIndices[i * 2] = (short)(i);
lineListIndices[(i * 2) + 1] = (short)(i + 1);
}
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineList,
primitiveList,
0, // vertex buffer offset to add to each element of the index buffer
8, // number of vertices in pointList
lineListIndices, // the index buffer
0, // first index element to read
7 // number of primitives to draw
); <---This parameter must be a valid index within the array. Parameter name: primitiveCount
}
но я понятия не имею, как это исправить, так как я впервые делаю 2D-графику с использованием 3D-рендеринга.
Задний план:
Я делаю движок 2D-игры для xna, и я хочу создать класс для рисования простых фигур, я уже знаю, что вы можете использовать пиксельный трюк 1x1 Texture2D для рисования, но я также хочу знать этот способ, потому что иначе ЦП выполнять все вычисления, в то время как GPU может легко справиться с этим.