我遇到某种问题。我是新来的XNA,并希望绘制多边形形状,看起来像这样(在最后,我想这点是随机的):在XNA中创建2D多边形
所以我读了一些文章,这是什么我结束了:
private VertexPositionColor[] vertices;
public TextureClass()
{
setupVertices();
}
public override void Render(SpriteBatch spriteBatch)
{
Texture2D texture = createTexture(spriteBatch);
spriteBatch.Draw(texture, new Rectangle((int)vertices[0].Position.X, (int)vertices[0].Position.Y, 30, 30), Color.Brown);
}
private Texture2D createTexture(SpriteBatch spriteBatch)
{
Texture2D texture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
texture.SetData<Color>(new Color[] { Color.Brown });
return texture;
}
当我打电话Render
它开始画一些正方形,如果它在一个循环的位置。我只是猜测我做错了所有事情。如果有人指出我正确的方向,我会很喜欢它。只需创建一个多边形并绘制它。它似乎很简单...
第一次设置顶点后,您是否更改顶点? – Cameron
不,我只是叫Render一次 –
从哪里调用Render? –