0
我试图用下面的方法绘制一个七段显示器,我看不出为什么,即使当我运行调试器时,但是因为somereason它不显示数字。这里有什么问题?你可以忽略大数组,这只是为了展示我如何存储这些值。七段显示器XNA
private void DrawScore(SpriteBatch spriteBatch, int score, int playerNumber)
{
int[,,] numbers =
{
// Zero
// Output:
// [ ][.][ ] [.] = white square [ ] = black square
// [.][ ][.]
// [ ][.][ ]
// [.][ ][.]
// [ ][.][ ]
{
{0, 1, 0},
{1, 0, 1},
{0, 0, 0},
{1, 0, 1},
{0, 1, 0}
},
{
{0, 0, 0},
{0, 0, 1},
{0, 0, 0},
{0, 0, 1},
{0, 0, 0}
},
{
{0, 1, 0},
{0, 0, 1},
{0, 1, 0},
{1, 0, 0},
{0, 1, 0}
},
{
{0, 1, 0},
{0, 0, 1},
{0, 1, 0},
{0, 0, 1},
{0, 1, 0}
},
{
{0, 0, 0},
{1, 0, 1},
{0, 1, 0},
{0, 0, 1},
{0, 0, 0}
},
{
{0, 1, 0},
{1, 0, 0},
{0, 1, 0},
{0, 0, 1},
{0, 1, 0}
},
{
{0, 1, 0},
{1, 0, 0},
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}
},
{
{0, 1, 0},
{0, 0, 1},
{0, 0, 0},
{0, 0, 1},
{0, 0, 0}
},
{
{0, 1, 0},
{1, 0, 1},
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}
},
{
{0, 1, 0},
{1, 0, 1},
{0, 1, 0},
{0, 0, 1},
{0, 0, 0}
}
};
for (int i = 0; i < numbers.GetLength(1); i++)
{
for (int j = 0; j < numbers.GetLength(2); j++)
{
Debug.WriteLine("Score: {0}", score);
Debug.WriteLine("\ti, j: {0}", numbers[score, i, j]);
if (playerNumber == 1)
{
spriteBatch.Draw(numbers[score, i, j] == 0 ? _scoreSegmentTexBlack : _scoreSegmentTexWhite,
new Vector2(
(Graphics.PreferredBackBufferWidth/2) - _scoreSegmentTex.Width*(3 + i),
_scoreSegmentTex.Height*j + 1),
Color.White);
}
if (playerNumber == 2)
{
spriteBatch.Draw(numbers[score, i, j] == 0 ? _scoreSegmentTexBlack : _scoreSegmentTexWhite,
new Vector2(
(Graphics.PreferredBackBufferWidth/2) + _scoreSegmentTex.Width*(1 + i),
_scoreSegmentTex.Height*j + 1),
Color.White);
}
}
}
}
我假定循环(I,J)通大阵列的两个级别,是什么原因造成的慢度?我什么都看不到。为什么你的“数字”数组中的“大不透明的浓汤”,以及没有明确/有意义的结构,如“数字”或“段”? –
2d数组的每一部分都是从0开始的不同数字,我的评论不好。 –
将数字存储为整个纹理而非构建它们可能更简单快捷。除此之外,我真的不知道你的数组是如何构造的。为什么每个内部数组有三个条目,中间数组有五个数组,每个数字产生15个条目。对我来说没有多大意义。 –